Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Python codegen for the OpenAPI backend #21316

Merged
merged 21 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Copy openapi java stuff
  • Loading branch information
grihabor committed Aug 10, 2024
commit e0dd5dd985c42d200c206c78f8bdb3f0d53c85d6
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

python_sources()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import annotations

from pants.backend.experimental.python.register import rules as python_rules
from pants.backend.experimental.python.register import target_types as python_target_types
from pants.backend.experimental.openapi.register import rules as openapi_rules
from pants.backend.experimental.openapi.register import target_types as openapi_target_types
from pants.backend.openapi.codegen.python.rules import rules as openapi_python_codegen_rules


def target_types():
return [*python_target_types(), *openapi_target_types()]


def rules():
return [*python_rules(), *openapi_rules(), *openapi_python_codegen_rules()]
8 changes: 8 additions & 0 deletions src/python/pants/backend/openapi/codegen/python/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

python_sources()

python_tests(name="tests", dependencies=[":lockfiles"])

resources(name="lockfiles", sources=["*.test.lock"])
35 changes: 35 additions & 0 deletions src/python/pants/backend/openapi/codegen/python/extra_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pants.backend.openapi.target_types import OpenApiDocumentGeneratorTarget, OpenApiDocumentTarget
from pants.engine.target import BoolField, StringField
from pants.jvm.target_types import PrefixedJvmJdkField, PrefixedJvmResolveField


class OpenApiPythonModelPackageField(StringField):
alias = "python_model_package"
help = "Root package for generated model code"


class OpenApiPythonApiPackageField(StringField):
alias = "python_api_package"
help = "Root package for generated API code"


class OpenApiPythonSkipField(BoolField):
alias = "skip_python"
default = False
help = "If true, skips generation of Python sources from this target"


def rules():
return [
OpenApiDocumentTarget.register_plugin_field(OpenApiPythonSkipField),
OpenApiDocumentTarget.register_plugin_field(OpenApiPythonModelPackageField),
OpenApiDocumentTarget.register_plugin_field(OpenApiPythonApiPackageField),
OpenApiDocumentGeneratorTarget.register_plugin_field(OpenApiPythonSkipField),
OpenApiDocumentGeneratorTarget.register_plugin_field(OpenApiPythonModelPackageField),
OpenApiDocumentGeneratorTarget.register_plugin_field(OpenApiPythonApiPackageField),
# Default Pants JVM fields
# OpenApiDocumentTarget.register_plugin_field(PrefixedJvmJdkField),
# OpenApiDocumentTarget.register_plugin_field(PrefixedJvmResolveField),
# OpenApiDocumentGeneratorTarget.register_plugin_field(PrefixedJvmJdkField),
# OpenApiDocumentGeneratorTarget.register_plugin_field(PrefixedJvmResolveField),
]
Loading