From 84625fa0ae06fbf33ef2620624c1f6ad797b6cab Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Sun, 20 Apr 2025 09:03:21 +0000 Subject: [PATCH] :bulb: add more info to rest api methods --- codegen/pyproject.toml | 10 ---------- codegen/templates/rest/_docstring.py.jinja | 15 +++++++++++++++ codegen/templates/rest/client.py.jinja | 9 +++------ pyproject.toml | 1 + scripts/run-codegen.sh | 2 +- 5 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 codegen/templates/rest/_docstring.py.jinja diff --git a/codegen/pyproject.toml b/codegen/pyproject.toml index d46fbb345..d6195e2b7 100644 --- a/codegen/pyproject.toml +++ b/codegen/pyproject.toml @@ -5,13 +5,3 @@ target-version = "py310" [tool.ruff.lint] ignore = ["TID"] - -[tool.pyright] -typeCheckingMode = "standard" -reportPrivateImportUsage = false -reportShadowedImports = false -disableBytesTypePromotions = true - -pythonVersion = "3.10" -pythonPlatform = "All" -defineConstant = { PYDANTIC_V2 = true } diff --git a/codegen/templates/rest/_docstring.py.jinja b/codegen/templates/rest/_docstring.py.jinja new file mode 100644 index 000000000..d9fa3ae2a --- /dev/null +++ b/codegen/templates/rest/_docstring.py.jinja @@ -0,0 +1,15 @@ +{% macro build_docstring(endpoint) %} +"""{% if endpoint.deprecated %}DEPRECATED {% endif %}{% if endpoint.operation_id %}{{ endpoint.operation_id }} +{% endif %} + +{{ endpoint.method | upper }} {{ endpoint.path }} +{% if endpoint.description %} + +{{ endpoint.description }} +{% endif %} +{% if endpoint.external_docs %} + +See also: {{ endpoint.external_docs }} +{% endif %} +""" +{% endmacro %} diff --git a/codegen/templates/rest/client.py.jinja b/codegen/templates/rest/client.py.jinja index fb7896721..5d5749588 100644 --- a/codegen/templates/rest/client.py.jinja +++ b/codegen/templates/rest/client.py.jinja @@ -5,6 +5,7 @@ {% from "rest/_param.py.jinja" import endpoint_params, endpoint_raw_params, endpoint_model_params %} {% from "rest/_response.py.jinja" import build_response_type %} {% from "rest/_request.py.jinja" import build_request, build_request_params %} +{% from "rest/_docstring.py.jinja" import build_docstring %} from __future__ import annotations @@ -98,10 +99,8 @@ class {{ pascal_case(tag) }}Client: self, {{ endpoint_params(endpoint) | indent(8) }} ) -> {{ build_response_type(endpoint.success_response) }}: - {% if endpoint.external_docs %} - """See also: {{ endpoint.external_docs }}""" + {{ build_docstring(endpoint) | indent(8) }} - {% endif %} {{ build_request(endpoint) | indent(8) }} return self._github.request( {{ build_request_params(endpoint) | indent(12) }} @@ -131,10 +130,8 @@ class {{ pascal_case(tag) }}Client: self, {{ endpoint_params(endpoint) | indent(8) }} ) -> {{ build_response_type(endpoint.success_response) }}: - {% if endpoint.external_docs %} - """See also: {{ endpoint.external_docs }}""" + {{ build_docstring(endpoint) | indent(8) }} - {% endif %} {{ build_request(endpoint) | indent(8) }} return await self._github.arequest( {{ build_request_params(endpoint) | indent(12) }} diff --git a/pyproject.toml b/pyproject.toml index 1a93d73af..c8801468a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -140,6 +140,7 @@ defineConstant = { PYDANTIC_V2 = true } executionEnvironments = [ # disable overload check for generated version codes { root = "githubkit/versions/", reportOverlappingOverload = false }, + { root = "codegen", pythonVersion = "3.10" }, ] exclude = ["codegen/**"] diff --git a/scripts/run-codegen.sh b/scripts/run-codegen.sh index fad4289e6..578c142db 100755 --- a/scripts/run-codegen.sh +++ b/scripts/run-codegen.sh @@ -5,4 +5,4 @@ set -e # cd to the root of the project cd "$(dirname "$0")/.." -python -m codegen && ruff check --select I --fix --exit-zero . && ruff check --fix --exit-zero . && ruff format . +python -m codegen && ruff check --select I --fix --exit-zero . && ruff check --fix --exit-zero . && ruff format . && ruff check --fix .