Hi, I'm trying to use Pants to generate a python c...
# general
a
Hi, I'm trying to use Pants to generate a python client using the openapi-generator. I have everything working ok and generating the files in the sandbox. I would like those files to end up in my project tree. I thought from reading
run_shell_command
that this would happen:
Copy code
Also, the outputs does not apply, as any output files produced will end up directly in your project tree.
What am I missing here?
BUILD file:
Copy code
# curl -L <https://beta.optimeering.com/api/docs/openapi_public.json> | tee >(wc -c) >(shasum -a 256) >/dev/null
resource(
    name="openapi-schema",
    source=http_source(
        url="<https://beta.optimeering.com/api/docs/openapi_public.json>",
        sha256="6587bbdb2a7bed438aaedba2d961ef3afd41766725363e61adc8117c2ee78eab",
        len=33973
    )
)

# Specify JAR dependencies
jvm_artifact(
    name="openapi-generator",
    group="org.openapitools",
    artifact="openapi-generator-cli",
    version="7.7.0",
)

# Generate the openapi bindings from a schema produced by a different step
adhoc_tool(
    name="generator",
    runnable=":openapi-generator",
    args=[
        "generate",
        "-i",
        "generate_v2/openapi_public.json",
        "--skip-validate-spec",
        "-g",
        "python",
        "-o",
        "./sdk",
    ],
    execution_dependencies=[
        ":openapi-schema",
    ],
    output_directories=[
        "sdk/",
    ],
    workdir="/",
    root_output_directory=".",
)

run_shell_command(
    name="run-generator",
    command="echo Generated client",
    execution_dependencies=[":generator"],
)
b
Ah, run shell command does have a sandbox involved which is where any dependencies end up, but the
command
itself runs outside a sandbox. You can/should copy from the sandbox to the workspace. This is what we do for similar use cases: https://github.com/pantsbuild/pants/discussions/18235#discussioncomment-6655594
a
Thanks Huon, the use case you shared is where I’m heading with the git diff so that’s great!
👍 1