I have a directory that has a (working) `python_di...
# general
f
I have a directory that has a (working)
python_distribution
(generating a setup.py) to which I want to add explicit constraints on the python version. This is in a monorepo with source roots defined as
src/*
. This config is working for the generated setup.py. However, I decided to instead use a pyproject.toml. But, when I add a pyproject.toml to the directory and set it as a resource for the distribution (like the example) pants starts complaining about the source root not being defined for the directory. How is adding the pyproject.toml file clobbering the global source root? And, how would I fix it?
h
Can you give a bit more info about your directory layout and where the
pyproject.toml
is in relation to it?
f
Roughly, it looks like this
Copy code
.
├── BUILD
├── common
│   └── src
│       └── python
│           └── <package-name>
├── gear
│   └── <app-name>
│       └── src
│           ├── docker
│           └── python
├── distributed_package
│   ├── BUILD
│   ├── pyproject.toml
│   └── src
│       └── python
│           ├── BUILD
│           ├── __init__.py
│           ├── package_code.py
│           └── py.typed
├── pants.toml
└── requirements.txt
The
distributed_package/BUILD
dependencies reference the
python_sources
defined in
distributed_package/src/python/BUILD
I’m getting NoSourceRootError: No source root found for
distributed_package
source roots from pants.toml:
Copy code
[source]
root_patterns = [
    "src/*", "test/*"
]
looking for examples from previous questions, this is the closest example I’ve found: https://github.com/Kludex/uvicorn-extensions/tree/main but that is a batch of plugins with the same structure. And in this case, the source root is defined from the root directory of the repo
Copy code
[source]
root_patterns = ['/src/python/*', '/']
Confirmed that adding variants of paths starting with
/distributed_package
did not solve the problem
h
Ah, indeed,
pyproject.toml
is not in any source root. It probably shouldn't need to be, there might be some over-aggressive checks going on. But I think a workaround is to add the repo root as a fallback source root, as it is in that other example you linked to
Pants always takes the innermost source root that matches, so it's safe to add
/
as a fallback
And that will serve as a "source root" for files that otherwise aren't in one (again, Pants probably should not insist that such files be in a source root, but looks like it does...)
gratitude grazie 1