https://pantsbuild.org/ logo
b

breezy-agent-54573

01/09/2023, 12:08 PM
Hey everyone, I am trying to use pants to generate openapi python code from a swagger file. I have looked at this page https://www.pantsbuild.org/docs/plugins-codegen , but it seems a little bit complex just for a couple of shell commands. What I tried to do is to generate the code using experimental_shell_command and then load it using python_source. the first step works(i have confirmed it in the created sandbox) but the second step ignores the files that were generated by that command(I have added the first command as dependency for the second one). My question is, Is there a way to include those generate files as sources or maybe some way to generate python code other than that way (https://www.pantsbuild.org/docs/plugins-codegen) ? the BUILD file i used:
Copy code
experimental_shell_command(
    name="generate_external_client_sources",
    command='echo $PWD; docker run --rm -v ${PWD}/..:/local openapitools/openapi-generator-cli:v6.0.1 generate -i /local/external_brain_swagger.yaml -o /local/ -g python --package-name brain_client.external --additional-properties="generateSourceCodeOnly=True"',
    tools=["bash", "docker"],
    outputs=["external/"],
    dependencies=["Brain:generate_external_swagger"],
)

experimental_shell_command(
    name="generate_internal_client_sources",
    command='echo $PWD; docker run --rm -v ${PWD}/..:/local openapitools/openapi-generator-cli:v6.0.1 generate -i /local/internal_brain_swagger.yaml -o /local/ -g python --package-name brain_client.internal --additional-properties="generateSourceCodeOnly=True"',
    tools=["bash", "docker"],
    outputs=["internal/"],
    dependencies=["Brain:generate_internal_swagger"],
)

python_sources(
    name="brain_client",
    dependencies=[
        ":generate_external_client_sources",
        ":generate_internal_client_sources",
    ],
)
1
c

curved-television-6568

01/09/2023, 12:20 PM
The issue here is that you want Pants to treat the generated files from your shell command as Python sources, where as the output files will be just
files
. There are new targets to make this kind of translation on
main
. See https://github.com/pantsbuild/pants/pull/17877
b

breezy-agent-54573

01/09/2023, 1:17 PM
Ok Thank you for you help, I tryed using the latest release version with that feature but i was unable to make it work. that is what i have tried
Copy code
experimental_wrap_as_python_sources(name="generated_client",inputs=[':generate_internal_client_sources', ':generate_external_client_sources'])
c

curved-television-6568

01/09/2023, 1:32 PM
yeah, it’s not in a release yet.. either wait a bit or try using a bleeding edge version by providing a
PANTS_SHA
https://www.pantsbuild.org/docs/manual-installation#running-pants-from-unreleased-builds
b

breezy-agent-54573

01/09/2023, 1:34 PM
I will wait for the next release, thank you very much :)
👍 1