famous-kilobyte-26155
06/27/2024, 4:54 PMcomanage
.”
This is a directory in which I’m generating code from an openapi spec. The directory is at the top level of the repo and looks like
comanage/
├── BUILD
├── coreapi
│ └── src
│ └── python
│ ├── coreapi_client
│ └── coreapi_client_README.md
└── coreapi.yaml
This is similar to what I’ve done successfully for other package code that I’ve written, except in those cases I would put a BUILD file in the coreapi_client
directory.
roots are set as
[source]
root_patterns = [
"src/*", "test/*"
]
and pants roots says
comanage/coreapi/src/python
registry/get_user/src/python
and the code gets included in the virtual environment I’m using in the IDE.
I’m guessing the error is actually about the comanage
directory, but I’m not understanding what it is telling me.famous-kilobyte-26155
06/27/2024, 4:55 PMfile(name="openapi_schema", source="coreapi.yaml")
run_shell_command(
name="build_client",
command="docker run --rm -v $PWD:/local openapitools/openapi-generator-cli generate " \
"-i /local/coreapi.yaml -g python -o /local/coreapi/src/python " \
"--package-name coreapi_client " \
"--additional-properties='generateSourceCodeOnly=True'",
execution_dependencies=[":openapi_schema"]
)
experimental_wrap_as_python_sources(name="coreapi_client",
inputs=[":build_client"])
python_sources(name="coreapi",
sources=["coreapi/**/*.py"],
dependencies=[":coreapi_client"])
famous-kilobyte-26155
06/27/2024, 5:58 PMcurved-television-6568
06/29/2024, 6:13 AMcoreapi
python sources target starting in the directory where the target is defined, rather than in the directory where the sources are.
That is, you are absolutely allowed to use recursive globs for the sources, however, it seems that pants still needs the target to be within a source root. (so, perhaps not a bug, but a designed limitation.) I guess this could be a practical limitation due to implementation details (to avoid situations where you could end up with a single target with sources from multiple source roots, which could confuse pants rules, potentially..)
What you could do, is move your coreapi target into the source root:
# comanage/coreapi/src/python/BUILD
python_sources(name="coreapi", sources=["**/*.py"], ..)
famous-kilobyte-26155
09/03/2024, 3:36 PM# comanage/coreapi/src/python/BUILD
python_sources(name="coreapi",
sources=["**/*.py"],
dependencies=["comanage:coreapi_client"])