aloof-appointment-30987
11/23/2022, 5:58 PMlibraries
directory. I'd like to be able to reference these relatively so that apps and libraries are using the latest source code rather than being referenced via a version-pinned requirement reference. In poetry, I can use path references in pyproject.toml.
[tool.poetry.dependencies]
quoteoftheday = {path = "../quoteoftheday"}
I'd like to configure path
BUILD files to reflect this. I find my Google searches pointing me to python_library
in the v1 documentation quite often. Can someone point me toward a solid resource to understand
1. How to properly configure a library distribution
2. How to reference that as a dependency from another project in the same monorepowide-midnight-78598
11/23/2022, 6:00 PMpython_sources(
name="libhelloworld",
sources=["**/*.py"],
dependencies=[
"examples/python/core:libcore",
],
)
aloof-appointment-30987
11/23/2022, 6:01 PMpolite-garden-50641
11/23/2022, 6:05 PM./pants tailor
and pants dependency inference should be able to do the rest for you.wide-midnight-78598
11/23/2022, 6:07 PMpython_sources(
name="libcore",
sources=["**/*.py"],
)
aloof-appointment-30987
11/23/2022, 6:11 PMwide-midnight-78598
11/23/2022, 6:15 PMpants.toml
- also note that I might do things a little differently to the community, as I don't usually use tailor
happy-kitchen-89482
11/23/2022, 8:43 PMwide-midnight-78598
11/23/2022, 8:50 PMaloof-appointment-30987
11/23/2022, 10:35 PMmarker_filenames = ["BUILD.pants"]
It was not clear that this essentially sets up a global search path that all dependees use to resolve import statements. Is that correct? I found I can now remove dependencies=
from the python_sources
config and inference works. I can then import relative to the sub directory(s) included by the library BUILD.pants as that marks the project root as a source root. This is wicked cool!
I have a couple of questions:
β’ Let's say someone really likes to have their source files in a _project_name/src/project_name_ (or maybe we're migrating an existing repo to pants). How do we configure the BUILD file or otherwise instruct pants to omit the src directory? The goal being to be able to import starting with the contents of src.
β’ What is a good documentation / resource to dig deep into some of these concepts? Assume I am relatively new to Python pathing and dependency resolution in general (assumed correctly π)
Thanks so much, BTW!βββ apps
β βββ python
β βββ example_app
β βββ monorepo_util
βββ libraries
β βββ python
β βββ another_library
β βββ content_module
β βββ quoteoftheday
βββ pants
βββ pants.toml
I'd like to support imports relative to each library project source root. from content_module import content
IOW, the imports should not have to change if one decides to publish the libs to a package repo and source them using pip.
Given the _content_module_ project sub directory tree:
βββ BUILD
βββ README.md
βββ src
β βββ BUILD.pants
β βββ content_module
β βββ __init__.py
β βββ content.py
βββ tests
βββ BUILD
βββ __init__.py
βββ test_content_module.py
where ./BUILD
contains:
python_sources(
dependencies="./src:content-module"
)
and ./src/BUILD.pants
contains:
python_sources(
name="content-module",
sources=["**/*.py"],
)
A dependee (located ,,/../apps/python/example_app/app.py
relative to the above library project) is able to import as:
from content_module import content
Am I configuring these things appropriately?Build.pants
is configured in ./pants.toml
as
[source]
marker_filenames = ["BUILD.pants"]
happy-kitchen-89482
11/25/2022, 2:01 PMproject1/src/foo/bar.py
and you want your code to from foo import bar
then project1/src/
is a source root (i.e., must be on the sys.path of the python interpreter doing the importing) and so Pants must be told of thisβ¦./BUILD
? I donβt see any sources in that dirsetup.py
or pyproject.toml
are useful as marker files.wide-midnight-78598
11/25/2022, 2:09 PMdonβt think Iβve seen BUILD files used as marker filesExcept from this guy π π I use them as project delineators - as mentioned above, I do some things a little differently
aloof-appointment-30987
11/25/2022, 2:15 PMBUILD
creates a dist but I think you are correct in that I could move that into ./src.
Using BUILD.pants as the source root marker appealed to me because itβs explicit and gets around the src sub directory issue.happy-kitchen-89482
11/25/2022, 2:21 PM