gentle-flower-25372
02/23/2024, 3:36 PM$ pants dependencies --transitive utility/one/bin/main.py
08:33:13.80 [INFO] Initializing scheduler...
08:33:16.22 [INFO] Scheduler initialized.
08:33:16.27 [WARN] The target utility/one/bin/main.py imports `click`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['utility/one:reqs#click', 'utility/some/long/subdir/two:reqs#click'].
Please explicitly include the dependency you want in the `dependencies` field of utility/one/bin/main.py, or ignore the ones you do not want by prefixing with `!` or `!!` so that one or no targets are left.
Alternatively, you can remove the ambiguity by deleting/changing some of the targets so that only 1 target owns this module. Refer to <https://www.pantsbuild.org/v2.19/docs/troubleshooting#import-errors-and-missing-dependencies>.
08:33:16.27 [WARN] Pants cannot infer owners for the following imports in the target utility/one/bin/main.py:
* click (line: 1)
If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/v2.19/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
This question is tied to a greater fear with adoption for my use case. I have about 100 pyproject.toml with their own poetry.lock
files currently without any build tools. I'm attempting to adopt pants, but I fear that because of the complexity of inter dependencies (1st party) and then overlapping/conflicting 3rd party dependencies it will be challenging to get everything tied to the "right" resolve (lockfile) where I can build everything without specifying all 3rd party dependencies across the monorepo explicitly in BUILD
files.better-van-82973
02/23/2024, 3:49 PMpyproject.toml
directly so I don’t think you necessarily need to use poetry.lock
or requirements.txt
as the source for the dependencies: https://www.pantsbuild.org/2.18/reference/targets/poetry_requirements
When I migrated my own monorepo to Pants, we had about ~15 subprojects managed using Poetry which we unified into a single resolve; that was a pain at first but definitely worth the effort. For you, you may want to think about which subprojects need to share code with each other (if at all) and use that to drive the strategy for how to split resolves/lockfiles.gentle-flower-25372
02/23/2024, 3:53 PMpoetry_requirements()
and now I'm testing out what it would look like if we exported requirements.txt from poetry in the interim with python_requirements
explicitly.
If I have a predictable pattern for python_requirements (or poetry_requirements) am I able to write some meta programming to set it up? I saw __defaults__
and wasn't sure if I can use that. For example,
Initially I want all of the BUILD files living in the same directory as pyproject.toml to have this:
poetry_requirements(
name="poetry",
resolve="<dynamically-driven-value>",
)
In my case the <dynamically-driven-value>
is really just the name of the directory that contains the BUILD file.gentle-flower-25372
02/23/2024, 3:55 PMpython_sources
and python_tests
gentle-flower-25372
02/23/2024, 3:56 PMbetter-van-82973
02/23/2024, 3:59 PMgentle-flower-25372
02/23/2024, 4:00 PMdiff --git a/utility/one/BUILD b/utility/one/BUILD
index b8519ce..994a1a8 100644
--- a/utility/one/BUILD
+++ b/utility/one/BUILD
@@ -1,3 +1,7 @@
+__defaults__({
+ (python_sources, python_tests, python_requirements, pex_binary): dict(resolve="one")
+})
+
python_requirements(
name="reqs",
)
curved-television-6568
02/25/2024, 8:13 AM<dynamically-driven-value>
is really just the name of the directory that contains the BUILD file.
you can use build_file_dir()
for this, it's a PurePath
object:
resolve=build_file_dir().name,