Skip to content

Commit

Permalink
🔧 add test config
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Jan 6, 2024
1 parent 469afbb commit bd25402
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 7 deletions.
11 changes: 11 additions & 0 deletions codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions codegen/templates/__init__.py.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% from "header.jinja" import header %}

"""{{ header() }}"""
4 changes: 2 additions & 2 deletions githubkit/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions githubkit/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions githubkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions githubkit/versions/latest/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
"""
8 changes: 8 additions & 0 deletions githubkit/versions/v2022_11_28/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
"""
52 changes: 51 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down

0 comments on commit bd25402

Please sign in to comment.