Question about local requirements/projects… I have...
# general
f
Question about local requirements/projects… I have a directory in my monorepo that contains a Python package w/
pyproject.toml
. I can
pip install -e mypackage
successfully. I have added an entry to my
<http://requirements.in|requirements.in>
(e.g.,
file:mypackage
) and
pip-compile
resolves dependencies and produces a
requirements.txt
that also contains a
file:mypackage
entry. I can run
pip install -r requirements.txt
successfully. When I run pants goals such as
pants dependencies
, pants raises the following error:
ValueError: Invalid requirement 'file:mypackage' in requirements.txt at line 705: Parse error at "':mypacka'": Expected string_end
Is it possible to include a local requirement this way? The docs [here](https://www.pantsbuild.org/2.18/docs/python/overview/third-party-dependencies#local-requirements) indicate that .whl or sdist are required or is there another solution? (apologies if this has already been answered, search didn’t seem to return any relevant results)
Upon digging further, this seems to be a pip pathing issue. Feel free to disregard. I’ll update here once I get it sorted in case anyone else stumbles over this.
Ok, so after updating
<http://requirements.in|requirements.in>
to include just
./mypackage
(without
file:
),
pip-compile
generates a
requirements.txt
that contains
file:///absolute/path/to/project
that pants infers as a dependency. I am now looking for a solution to
pip-compile
compiling a relative path to an absolute path which isn’t portable… (here’s the rabbit hole: https://github.com/jazzband/pip-tools/issues/204)
b
Sorry for the trouble. Pants normally expects in-repo dependencies to be managed on the Pants side, rather than via pip (etc.). That is, rather than package A appear in a
requirements.txt
of package B, just
from A import whatever
and let Pants' dependency inference handle that. For instance, in my work repo, we have a few different "packages" that we import from, but only one top-level
pyproject.toml
that only defines the third-party (i.e. from PyPI) dependencies, no internal ones. Does that sound like it might work for you?
f
Yeah, that’s what I ended up going with. It’s a pattern we follow elsewhere in the repo, but I developed the package separately before migrating it into the monorepo and was hoping to preserve the package structure w/
src
layout etc.
b
Ah I see. I think it should be possible to preserve the layout with appropriate source roots configured: https://www.pantsbuild.org/stable/docs/using-pants/key-concepts/source-roots For instance, if the structure is something like
path/to/src/A
with imports like
from A import ...
then making sure
path/to/src
is a source root should satisfy that. (
root_patterns = ["src"]
would be one approach)
👍 1
f
Thanks, I’ll try that out