diff --git a/codegen/__init__.py b/codegen/__init__.py index dbf6014e2..2e3547efe 100644 --- a/codegen/__init__.py +++ b/codegen/__init__.py @@ -162,6 +162,12 @@ def build_latest_version( ): logger.info("Start generating latest version...") + # build pkg + logger.info("Building latest __init__.py...") + init_template = env.get_template("__init__.py.jinja") + init_path = dir / "__init__.py" + init_path.write_text(init_template.render()) + # build models logger.info("Building latest models...") latest_template = env.get_template("latest/models.py.jinja") @@ -296,6 +302,11 @@ def build(): version_path = config.output_dir / version_module version_path.mkdir(parents=True, exist_ok=True) + # generate __init__.py + init_template = env.get_template("__init__.py.jinja") + init_path = version_path / "__init__.py" + init_path.write_text(init_template.render()) + # generate models model_path = version_path / "models" model_path.mkdir(parents=True, exist_ok=True) diff --git a/codegen/templates/__init__.py.jinja b/codegen/templates/__init__.py.jinja new file mode 100644 index 000000000..db44d1010 --- /dev/null +++ b/codegen/templates/__init__.py.jinja @@ -0,0 +1,3 @@ +{% from "header.jinja" import header %} + +"""{{ header() }}""" diff --git a/githubkit/compat.py b/githubkit/compat.py index 93f4af47f..be4e0f958 100644 --- a/githubkit/compat.py +++ b/githubkit/compat.py @@ -29,7 +29,7 @@ def __get_validators__(cls) -> Generator[Callable[..., Any], None, None]: CVC = TypeVar("CVC", bound=CustomValidationClass) -if PYDANTIC_V2: +if PYDANTIC_V2: # pragma: pydantic-v2 from pydantic_core import CoreSchema, core_schema from pydantic import ( BaseModel, @@ -80,7 +80,7 @@ def custom_validation(class_: Type["CVC"]) -> Type["CVC"]: ) return class_ -else: +else: # pragma: pydantic-v1 from pydantic import Extra, BaseModel, parse_obj_as, parse_raw_as, root_validator class GitHubModel(BaseModel): diff --git a/githubkit/typing.py b/githubkit/typing.py index a2009d033..5b0e4ea06 100644 --- a/githubkit/typing.py +++ b/githubkit/typing.py @@ -45,7 +45,7 @@ ] RequestFiles: TypeAlias = Union[Dict[str, FileTypes], List[Tuple[str, FileTypes]]] -if PYDANTIC_V2: +if PYDANTIC_V2: # pragma: pydantic-v2 from pydantic import AfterValidator from pydantic_core import PydanticCustomError @@ -59,7 +59,7 @@ def _validate_unique_list(value: List[H]) -> List[H]: AfterValidator(_validate_unique_list), Field(json_schema_extra={"uniqueItems": True}), ] -else: +else: # pragma: pydantic-v1 UniqueList: TypeAlias = Annotated[List[H], Field(unique_items=True)] # type: ignore # if the property is not required, we allow it to have the value null. diff --git a/githubkit/utils.py b/githubkit/utils.py index accc7e97c..1d9603ea1 100644 --- a/githubkit/utils.py +++ b/githubkit/utils.py @@ -7,7 +7,7 @@ from .compat import PYDANTIC_V2, custom_validation, type_validate_python -if PYDANTIC_V2: +if PYDANTIC_V2: # pragma: pydantic-v2 from pydantic_core import core_schema from pydantic import GetCoreSchemaHandler @@ -94,7 +94,7 @@ def __init__(self, type_: Type[T], discriminator: str, tag: str) -> None: def _validate(self, value: Any) -> T: return type_validate_python(self.type_, value) - if PYDANTIC_V2: + if PYDANTIC_V2: # pragma: pydantic-v2 def __get_pydantic_core_schema__( self, _source_type: Any, _handler: "GetCoreSchemaHandler" diff --git a/githubkit/versions/latest/__init__.py b/githubkit/versions/latest/__init__.py new file mode 100644 index 000000000..b1710f9b9 --- /dev/null +++ b/githubkit/versions/latest/__init__.py @@ -0,0 +1,8 @@ +"""DO NOT EDIT THIS FILE! + +This file is automatically @generated by githubkit using the follow command: + +python -m codegen && isort . && black . + +See https://github.com/github/rest-api-description for more information. +""" diff --git a/githubkit/versions/v2022_11_28/__init__.py b/githubkit/versions/v2022_11_28/__init__.py new file mode 100644 index 000000000..b1710f9b9 --- /dev/null +++ b/githubkit/versions/v2022_11_28/__init__.py @@ -0,0 +1,8 @@ +"""DO NOT EDIT THIS FILE! + +This file is automatically @generated by githubkit using the follow command: + +python -m codegen && isort . && black . + +See https://github.com/github/rest-api-description for more information. +""" diff --git a/poetry.lock b/poetry.lock index 3b41e0712..1051fd7cc 100644 --- a/poetry.lock +++ b/poetry.lock @@ -260,6 +260,22 @@ tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.1 [package.extras] toml = ["tomli"] +[[package]] +name = "coverage-conditional-plugin" +version = "0.9.0" +description = "Conditional coverage based on any rules you define!" +optional = false +python-versions = ">=3.7,<4.0" +files = [ + {file = "coverage_conditional_plugin-0.9.0-py3-none-any.whl", hash = "sha256:1b37bc469019d2ab5b01f5eee453abe1846b3431e64e209720c2a9ec4afb8130"}, + {file = "coverage_conditional_plugin-0.9.0.tar.gz", hash = "sha256:6893dab0542695dbd5ea714281dae0dfec8d0e36480ba32d839e9fa7344f8215"}, +] + +[package.dependencies] +coverage = ">=7,<8" +importlib_metadata = {version = "*", markers = "python_version < \"3.10\""} +packaging = ">=20.4" + [[package]] name = "cryptography" version = "41.0.7" @@ -460,6 +476,25 @@ files = [ {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, ] +[[package]] +name = "importlib-metadata" +version = "7.0.1" +description = "Read metadata from Python packages" +optional = false +python-versions = ">=3.8" +files = [ + {file = "importlib_metadata-7.0.1-py3-none-any.whl", hash = "sha256:4805911c3a4ec7c3966410053e9ec6a1fecd629117df5adee56dfc9432a1081e"}, + {file = "importlib_metadata-7.0.1.tar.gz", hash = "sha256:f238736bb06590ae52ac1fab06a3a9ef1d8dce2b7a35b5ab329371d6c8f5d2cc"}, +] + +[package.dependencies] +zipp = ">=0.5" + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-lint"] +perf = ["ipython"] +testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)", "pytest-ruff"] + [[package]] name = "iniconfig" version = "2.0.0" @@ -1125,6 +1160,21 @@ files = [ {file = "wcwidth-0.2.12.tar.gz", hash = "sha256:f01c104efdf57971bcb756f054dd58ddec5204dd15fa31d6503ea57947d97c02"}, ] +[[package]] +name = "zipp" +version = "3.17.0" +description = "Backport of pathlib-compatible object wrapper for zip files" +optional = false +python-versions = ">=3.8" +files = [ + {file = "zipp-3.17.0-py3-none-any.whl", hash = "sha256:0e923e726174922dce09c53c59ad483ff7bbb8e572e00c7f7c46b88556409f31"}, + {file = "zipp-3.17.0.tar.gz", hash = "sha256:84e64a1c28cf7e91ed2078bb8cc8c259cb19b76942096c8d7b84947690cabaf0"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-lint"] +testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-ignore-flaky", "pytest-mypy (>=0.9.1)", "pytest-ruff"] + [extras] all = ["PyJWT", "anyio"] auth = ["PyJWT", "anyio"] @@ -1135,4 +1185,4 @@ jwt = ["PyJWT"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "fd5bf29e7be2b8544f08964227dc336af8f7fa530b21b643916b1281545c809d" +content-hash = "99912787905bb95161458d2f745dcd8ecb12f3a33519f0853f6a4ffb01720ce4" diff --git a/pyproject.toml b/pyproject.toml index b4f7aac43..d8a7715ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ anyio = "*" pytest = "^7.4.3" pytest-cov = "^4.1.0" pytest-xdist = "^3.5.0" +coverage-conditional-plugin = "^0.9.0" [tool.poetry.extras] jwt = ["PyJWT"] @@ -48,6 +49,28 @@ all = ["PyJWT", "anyio"] addopts = "--cov=githubkit --cov-append --cov-report=term-missing" filterwarnings = ["error", "ignore::DeprecationWarning"] +[tool.coverage.run] +plugins = ["coverage_conditional_plugin"] + +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "def __repr__", + "def __str__", + "@(typing\\.)?overload", + "if (typing\\.)?TYPE_CHECKING( is True)?:", + "@(abc\\.)?abstractmethod", + "raise NotImplementedError", + "warnings\\.warn", + "^\\.\\.\\.$", + "pass", + "if __name__ == .__main__.:", +] + +[tool.coverage.coverage_conditional_plugin.rules] +pydantic-v2 = "package_version('pydantic') < (2,)" +pydantic-v1 = "package_version('pydantic') >= (2,)" + [tool.black] line-length = 88 target-version = ["py38", "py39", "py310", "py311"]