wide-midnight-78598
03/18/2022, 1:30 AMpants.toml
for build_patterns
marker_filenames
and root_patterns
?
I think marker_filenames
and root_patterns
both set the source root, via different mechanisms, and then build_patterns
is what Pants looks for to identify something pants-able.
However, I just did a re-factor, and I'm not sure why I lost access to one of my libraries.
/core/BUILD.pants
python_sources(
name="libcore",
sources=["**/*.py"],
)
/helloworld/BUILD.pants
python_sources(
name="libhelloworld",
sources=["**/*.py"],
dependencies=[
"core:libcore",
],
)
This above, works, however, nested everything under examples/python
(without adding new BUILD files) and it falls over.
My pants.toml
is as follows:
[GLOBAL]
pants_version = "2.11.0.dev2"
build_patterns = ["BUILD.pants", "BUILD"]
[source]
marker_filenames = ["BUILD.pants"]
root_patterns = [
"examples/python",
"pants-plugins",
]
...
After re-reading https://www.pantsbuild.org/docs/existing-repositories#migrating-from-other-build-tools-set-custom-build-file-names - I think I can drop the build_patterns
entirely, and while I can add another top-level BUILD to the examples/python
directory, I'm not sure why it worked top level but then fails nested... Note: My pants.toml
had "/" as a root_pattern, when everything was top-levelexamples/python/core:libcore
- but I thought one of the build_patterns
or source_roots
would have solved that problemstrong-toothbrush-37759
03/18/2022, 8:57 AM./pants list ::
and ./pants roots
helped me a lot to understand what happens when I change my settings.wide-midnight-78598
03/18/2022, 3:39 PM./pants list ::
and ./pants roots
(but I honestly forget what those API calls are EVERY TIME I'm debugging something. It's the strangest thing.
Anyways, it's not an error problem, as much, as a qualitative API "surprise"? That's not even the correct word, but I can fully qualify everything, and it works correctly - but it definitely looks ugly in the build files.witty-crayon-22786
03/18/2022, 7:15 PM[sources]
subsystem): source roots are how filenames get trimmed at import time: see https://www.pantsbuild.org/docs/source-roots for more info../pants tailor
to create BUILD files rather than creating them manually. see https://www.pantsbuild.org/v2.10/docs/create-initial-build-files for more info.wide-midnight-78598
03/19/2022, 4:41 AMstrong-toothbrush-37759
03/19/2022, 9:19 AMfrom libcore import something
it should generally be possible since Pants should infer the dependency. But again as @witty-crayon-22786 mentioned, you should probably use ./pants tailor
to create your BUILD files rather than trying to manually create them yourself.witty-crayon-22786
03/21/2022, 7:27 PMNote: I know that I can fully qualify those core libs tono: neither of these allow for shorthand when you explicitly reference those libraries in a- but I thought one of theexamples/python/core:libcore
orbuild_patterns
would have solved that problemsource_roots
dependencies
list.
but as @strong-toothbrush-37759 said: needing to explicitly add dependencies
lists should be rare due to dependency inference. if you are needing to add a dep manually, it might be because your source roots aren’t set up properly.examples/python/core
to determine that the module name is core
and (and so should be imported as from core import something
) : and that means that you need ./pants roots
to report a source root at examples/python
wide-midnight-78598
03/22/2022, 12:05 AMwitty-crayon-22786
03/22/2022, 12:07 AM