Hello :slightly_smiling_face: I am trying to add ...
# general
b
Hello 🙂 I am trying to add pants on top of a poetry based python repo and also use resolves. Is
poetry_requirements()
capable of getting a local dependency from pyproject.toml into the lockfile generated by
poetry generate-lockfiles
?
Copy code
# BUILD

poetry_requirements(
    name="poetry",
    resolve="my_resolve"
)
Copy code
# pyproject.toml

[tool.poetry.dependencies]
local-shared-lib = {path = "../local-shared-lib", develop=true}
What I experiences is that 3rd party dependencies are added fine but the one with the local path is completely ignored with no warning or error. I would really appreciate some pointers. Thank you.
s
The only thing that
poetry_requirements
target do is generate a bunch of
python_requirement
targets. First party code in your repo needs to be defined in
python_sources
target, it doesn't need
python_requirement
, that's why
d
what's stopping you from moving that local-shared-lib into the pants monorepo?
b
Thank you for the replies. This is the repo structure I am working with. The pants roots are set to wherever the pyproject.toml files are. The shared-libs can be imported by the apps and they can import each other. So
libs/lib_b/my_namespace/lib_b/src/main.py
has an import
from my_namespace.lib_a.src import whatever
The apps use the same format.
apps/app1/app1/src/main.py
has an import
from my_namespace.lib_a.src import whatever
For now I have placed BUILD files at the same level with pyproject.toml and defined targets for poetry_requirements, sources and tests. I am not clear yet how to define
lib_a
as a dependency for
lib_b
and
app1
considering the import format is
from my_namespace.lib_a.src import whatever
s
You don't need to explicitly define it as a dependency, it will be automatically inferred if you're using pex binary
d
Copy code
local-shared-lib = {path = "../local-shared-lib", develop=true}
My own repo had this exact same setup. I'm guessing this is why you have the x2 duplicate namespaces like
lib_a/my_namespace/lib_a
so that when you install something you can just importing it with
my_namespace.lib_a
Instead of thinking about how you can get pants to mimick what poetry is doing here I'd really consider just completely flattening your namespace completely (because what poetry is doing is pretty weird). So instead your repo structure would look like
Copy code
shared_libs/lib_a/__init__.py
shared_libs/lib_b/__init__.py
apps/app1/__init__.py
etc. But this might not be possible. In my own experience the migration/flattening the repo structure was worth it. The imports then directly reflect the structure of your repo (instead of some weird shimmed poetry path).
s
The layout is completely fine as long as you correctly set
source_roots
in your
pants.toml
Copy code
[source]
root_patterns = ["shared-libs/*/", "apps/*/"]
d
I wasn't aware! (Ignore my advice then)
b
Thank you for all the input. I will try it with
root_patterns = ["shared-libs/*/", "apps/*/"]
instead of
marker_filenames = ["pyproject.toml"]