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
Prev Previous commit
Next Next commit
Implement package_mapper
  • Loading branch information
grihabor committed Aug 17, 2024
commit f5a3caa5415f87ca327b1d091316667d0f4678c5
6 changes: 2 additions & 4 deletions src/python/pants/backend/openapi/codegen/java/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
OpenApiSourceField,
)
from pants.backend.openapi.util_rules import generator_process, pom_parser
from pants.backend.openapi.util_rules.generator_process import (
OpenAPIGeneratorProcess,
)
from pants.backend.openapi.util_rules.generator_process import OpenAPIGeneratorProcess
from pants.backend.openapi.util_rules.pom_parser import AnalysePomRequest, PomReport
from pants.engine.fs import (
EMPTY_SNAPSHOT,
Expand Down Expand Up @@ -105,7 +103,7 @@ async def compile_openapi_into_java(
merged_digests = await Get(Digest, MergeDigests([request.input_digest, output_digest]))

process = OpenAPIGeneratorProcess(
generator_name='java',
generator_name="java",
argv=[
*(
("--additional-properties", f"apiPackage={request.api_package}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from pants.backend.openapi.target_types import OpenApiDocumentGeneratorTarget, OpenApiDocumentTarget
from pants.backend.python.target_types import PrefixedPythonResolveField
from pants.engine.target import BoolField, DictStringToStringField, StringField
Expand Down
42 changes: 18 additions & 24 deletions src/python/pants/backend/openapi/codegen/python/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,37 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import annotations
from typing import Tuple

from packaging.utils import canonicalize_name as canonicalize_project_name
import itertools
import logging
from collections import defaultdict
from collections.abc import Iterable
from pants.backend.codegen.utils import (
MissingPythonCodegenRuntimeLibrary,
)
from pants.engine.internals.native_engine import Address
from pants.util.requirements import parse_requirements_file
from dataclasses import dataclass
import itertools
from typing import Tuple

from pants.backend.python.target_types import (
PrefixedPythonResolveField,
PythonRequirementResolveField,
PythonRequirementsField,
PythonSourceField,
)
from packaging.utils import canonicalize_name as canonicalize_project_name

from pants.backend.codegen.utils import MissingPythonCodegenRuntimeLibrary
from pants.backend.openapi.codegen.python.extra_fields import (
OpenApiPythonAdditionalPropertiesField,
OpenApiPythonGeneratorNameField,
OpenApiPythonSkipField,
)
from pants.backend.openapi.sample.resources import PETSTORE_SAMPLE_SPEC
from pants.backend.openapi.subsystems.openapi_generator import OpenAPIGenerator
from pants.backend.openapi.target_types import (
OpenApiDocumentDependenciesField,
OpenApiDocumentField,
OpenApiSourceField,
)
from pants.backend.openapi.util_rules.generator_process import (
OpenAPIGeneratorProcess,
from pants.backend.openapi.util_rules.generator_process import OpenAPIGeneratorProcess
from pants.backend.python.dependency_inference.module_mapper import AllPythonTargets
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import (
PrefixedPythonResolveField,
PythonRequirementResolveField,
PythonRequirementsField,
PythonSourceField,
)
from pants.engine.fs import (
EMPTY_SNAPSHOT,
Expand All @@ -49,6 +48,7 @@
RemovePrefix,
Snapshot,
)
from pants.engine.internals.native_engine import Address
from pants.engine.process import ProcessResult
from pants.engine.rules import Get, MultiGet, collect_rules, rule
from pants.engine.target import (
Expand All @@ -64,16 +64,10 @@
)
from pants.engine.unions import UnionRule
from pants.source.source_root import SourceRoot, SourceRootRequest
from pants.util.logging import LogLevel
import logging

from pants.util.frozendict import FrozenDict
from pants.backend.openapi.sample.resources import PETSTORE_SAMPLE_SPEC
from pants.backend.python.dependency_inference.module_mapper import (
AllPythonTargets,
)
from pants.backend.python.subsystems.setup import PythonSetup
from pants.util.logging import LogLevel
from pants.util.pip_requirement import PipRequirement
from pants.util.requirements import parse_requirements_file
from pants.util.strutil import softwrap

logger = logging.getLogger(__name__)
Expand Down
Loading