enough-advantage-61561
08/11/2023, 2:48 PMpants
work with a dummy project with two apps with different requirements. The apps use different version of a 3rd party package (pandas), which is a transitive dependency.
(continuing the description and question in comments)enough-advantage-61561
08/11/2023, 2:53 PM📁 pants-tests/
├─📁 apps/
│ ├─📁 app-A/
│ │ ├─📁 app_a/
│ │ │ ├─📄 __init__.py
│ │ │ ├─📄 app.py
│ │ │ └─📄 BUILD
│ │ ├─📄 pyproject.toml
│ │ └─📄 BUILD
│ └─📁 app-B/
│ ├─📁 app_b/
│ │ ├─📄 __init__.py
│ │ ├─📄 app.py
│ │ └─📄 BUILD
│ ├─📄 pyproject.toml
│ └─📄 BUILD
├─📄 .env
├─📄 .gitignore
├─📁 lib/
│ ├─📁 lib-E/
│ │ ├─📁 lib_e/
│ │ │ ├─📄 __init__.py
│ │ │ ├─📄 something.py
│ │ │ └─📄 BUILD
│ │ └─📄 pyproject.toml
│ ├─📁 lib-C/
│ │ ├─📁 lib_c/
│ │ │ ├─📄 __init__.py
│ │ │ ├─📄 something.py
│ │ │ └─📄 BUILD
│ │ ├─📄 pyproject.toml
│ │ └─📄 BUILD
│ ├─📁 lib-D/
│ │ ├─📁 lib_d/
│ │ │ ├─📄 __init__.py
│ │ │ ├─📄 something.py
│ │ │ └─📄 BUILD
│ │ └─📄 pyproject.toml
│ └─📁 lib-F/
│ ├─📁 lib_f/
│ │ ├─📄 __init__.py
│ │ ├─📄 something.py
│ │ └─📄 BUILD
│ └─📄 pyproject.toml
└─📄 pants.toml
flat-zoo-31952
08/11/2023, 3:02 PMflat-zoo-31952
08/11/2023, 3:04 PMflat-zoo-31952
08/11/2023, 3:06 PMflat-zoo-31952
08/11/2023, 3:06 PMenough-advantage-61561
08/11/2023, 3:06 PMnumba
in `lib/lib-C/lib_c/something.py`:
Reading in Setting up an IDE under "Python third-party dependencies and tools" I get the impression I should use multiple "resolves" and lockfiles.
... and now I'm pausing to read what @flat-zoo-31952 said 😄flat-zoo-31952
08/11/2023, 3:06 PMresolve=parametrize(...)
to appear in bothflat-zoo-31952
08/11/2023, 3:07 PMflat-zoo-31952
08/11/2023, 3:08 PMenough-advantage-61561
08/11/2023, 3:36 PMpants
works.enough-advantage-61561
08/11/2023, 3:37 PM[GLOBAL]
pants_version = "2.16.0"
backend_packages = ["pants.backend.python"]
[source]
root_patterns = ['/lib/*', '/apps/*']
[python]
interpreter_constraints = ['==3.10.*']
enable_resolves = true
default_resolve = "app_a_resolve"
[python.resolves]
app_a_resolve = ".lockfiles/app-A"
app_b_resolve = ".lockfiles/app-B"
enough-advantage-61561
08/11/2023, 3:37 PMenough-advantage-61561
08/11/2023, 3:38 PMpants generate-lockfiles
I'm, getting the following error:
niko@niko-ubuntu:~/tmp/pants-tests$ pants generate-lockfiles
18:35:41.02 [INFO] waiting for pantsd to start...
18:35:42.22 [INFO] pantsd started
18:35:42.30 [INFO] Initializing scheduler...
18:35:47.29 [INFO] Scheduler initialized.
18:35:48.46 [INFO] Completed: Generate lockfile for app_b_resolve
18:35:49.19 [INFO] Completed: Generate lockfile for app_a_resolve
18:35:49.19 [ERROR] 1 Exception encountered:
Engine traceback:
in `generate-lockfiles` goal
ProcessExecutionFailure: Process 'Generate lockfile for app_a_resolve' failed with exit code 1.
stdout:
stderr:
pid 187848 -> /home/niko/.cache/pants/named_caches/pex_root/venvs/edc3cdf8d6ebf14b5ebbdb422cf41b6e4a653c5b/5985ed09b49a653d6596b0e14d134c5456cf1a9f/bin/python -sE /home/niko/.cache/pants/named_caches/pex_root/venvs/edc3cdf8d6ebf14b5ebbdb422cf41b6e4a653c5b/5985ed09b49a653d6596b0e14d134c5456cf1a9f/pex --disable-pip-version-check --no-python-version-warning --exists-action a --no-input --isolated -q --cache-dir /home/niko/.cache/pants/named_caches/pex_root/pip_cache --log /tmp/pants-sandbox-oeEs8b/.tmp/pex-pip-log.aq4q8ck5/pip.log download --dest /tmp/pants-sandbox-oeEs8b/.tmp/tmpv7iswc9x/usr.bin.python3.10 lib-D lib-E lib_c --index-url <https://pypi.org/simple/> --retries 5 --timeout 15 exited with 1 and STDERR:
ERROR: Could not find a version that satisfies the requirement lib-D
ERROR: No matching distribution found for lib-D
Use `--keep-sandboxes=on_failure` to preserve the process chroot for inspection.
what could be the reason?enough-advantage-61561
08/11/2023, 3:41 PMpants
is at least finding the lib-D with `pants roots`:
niko@niko-ubuntu:~/tmp/pants-tests$ pants roots
apps/app-A
apps/app-B
lib/lib-C
lib/lib-D
lib/lib-E
lib/lib-F
why it says "No matching distribution found for lib-D" ?enough-advantage-61561
08/11/2023, 3:43 PMpyproject.toml
for lib-C ( lib/lib-C/pyproject.toml
):
[project]
name = "lib-C"
requires-python = ">=3.10"
version = "0.1.0"
dependencies = ["lib-D"]
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[tool.setuptools.packages.find]
where = ["."]
include = ["lib_c*"]
That's probably not a valid pyproject.toml
at all. I wonder how should the lib-D
be defined in the dependencies of lib-C
?flat-zoo-31952
08/11/2023, 3:50 PMflat-zoo-31952
08/11/2023, 3:50 PMenough-advantage-61561
08/11/2023, 3:52 PMlib_d.something
and lib_c.something
.enough-advantage-61561
08/11/2023, 3:54 PMlib/lib-D/BUILD
. Maybe that's the issue.flat-zoo-31952
08/11/2023, 3:54 PMlib/lib-D/BUILD
look like? Pants doesn't really care about pip packages for first -party codeflat-zoo-31952
08/11/2023, 3:54 PMpants tailor ::
to have pants populate targets for things that aren't createdflat-zoo-31952
08/11/2023, 3:56 PMenough-advantage-61561
08/11/2023, 3:57 PMlib/lib-D/BUILD
is not created automatically with pants tailor ::
. It creates lib/lib-D/lib_d/BUILD
if I remove it, for example.flat-zoo-31952
08/11/2023, 3:57 PMenough-advantage-61561
08/11/2023, 3:58 PMlib/lib-C/BUILD
which has
python_requirements(source="pyproject.toml")
so probably I should also make similar lib/lib-D/BUILD
flat-zoo-31952
08/11/2023, 3:58 PMflat-zoo-31952
08/11/2023, 3:59 PMflat-zoo-31952
08/11/2023, 3:59 PMflat-zoo-31952
08/11/2023, 4:00 PMERROR: Could not find a version that satisfies the requirement lib-D
ERROR: No matching distribution found for lib-D
flat-zoo-31952
08/11/2023, 4:00 PMenough-advantage-61561
08/11/2023, 4:01 PMpyproject.toml
per library/app as in the real monorepo (similar to this but many times larger) I have one setup.py
per library/app, which are used to define dependencies and possibly some CLI entry points. Since pants
does not support setup.py
, I thought I would convert all the setup.py to pyproject.toml.flat-zoo-31952
08/11/2023, 4:01 PMflat-zoo-31952
08/11/2023, 4:02 PMenough-advantage-61561
08/11/2023, 4:02 PMenough-advantage-61561
08/11/2023, 4:02 PMflat-zoo-31952
08/11/2023, 4:02 PMflat-zoo-31952
08/11/2023, 4:03 PMenough-advantage-61561
08/11/2023, 4:04 PMpants
would find lib-D
since I've said that the source files are located in these folders in pants.toml:
[source]
root_patterns = ['/lib/*', '/apps/*']
flat-zoo-31952
08/11/2023, 4:05 PMlib/*/*
and apps/*/*
thoughflat-zoo-31952
08/11/2023, 4:06 PMflat-zoo-31952
08/11/2023, 4:07 PMpython_requirements(source="pyproject.toml")
flat-zoo-31952
08/11/2023, 4:07 PMflat-zoo-31952
08/11/2023, 4:08 PMflat-zoo-31952
08/11/2023, 4:09 PMpython_requirements
targets as the universe of 3rd party dependencies, and then it will map each import statement to those dependenciesenough-advantage-61561
08/11/2023, 4:09 PMlib/lib-D/BUILD
with
python_requirements(source="pyproject.toml")
and got
niko@niko-ubuntu:~/tmp/pants-tests$ pants generate-lockfiles
18:58:35.20 [ERROR] 1 Exception encountered:
Engine traceback:
in `generate-lockfiles` goal
KeyError: 'No section `project.dependencies` or `project.optional-dependencies` found in lib/lib-D/pyproject.toml'
The problem being supposedly that I don't have any dependencies in the pyproject.toml. The lib/lib-D/pyproject.toml
looks like this:
[project]
name = "lib-D"
requires-python = ">=3.10"
version = "0.1.0"
dependencies = []
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[tool.setuptools.packages.find]
where = ["."]
include = ["lib_d*"]
and you can see the dependencies
is an empty list.flat-zoo-31952
08/11/2023, 4:09 PMflat-zoo-31952
08/11/2023, 4:09 PMflat-zoo-31952
08/11/2023, 4:10 PMpython_requirements
targetenough-advantage-61561
08/11/2023, 4:10 PMenough-advantage-61561
08/11/2023, 4:11 PMlib/lib-D/BUILD
I get again
niko@niko-ubuntu:~/tmp/pants-tests$ pants generate-lockfiles
19:10:38.71 [INFO] Completed: Generate lockfile for app_b_resolve
19:10:39.31 [INFO] Completed: Generate lockfile for app_a_resolve
19:10:39.32 [ERROR] 1 Exception encountered:
Engine traceback:
in `generate-lockfiles` goal
ProcessExecutionFailure: Process 'Generate lockfile for app_a_resolve' failed with exit code 1.
stdout:
stderr:
pid 191531 -> /home/niko/.cache/pants/named_caches/pex_root/venvs/edc3cdf8d6ebf14b5ebbdb422cf41b6e4a653c5b/5985ed09b49a653d6596b0e14d134c5456cf1a9f/bin/python -sE /home/niko/.cache/pants/named_caches/pex_root/venvs/edc3cdf8d6ebf14b5ebbdb422cf41b6e4a653c5b/5985ed09b49a653d6596b0e14d134c5456cf1a9f/pex --disable-pip-version-check --no-python-version-warning --exists-action a --no-input --isolated -q --cache-dir /home/niko/.cache/pants/named_caches/pex_root/pip_cache --log /tmp/pants-sandbox-YM7QeM/.tmp/pex-pip-log.5m_08x13/pip.log download --dest /tmp/pants-sandbox-YM7QeM/.tmp/tmpooq34rsw/usr.bin.python3.10 lib-D lib-E lib_c numba --index-url <https://pypi.org/simple/> --retries 5 --timeout 15 exited with 1 and STDERR:
ERROR: Could not find a version that satisfies the requirement lib-D
ERROR: No matching distribution found for lib-D
Use `--keep-sandboxes=on_failure` to preserve the process chroot for inspection.
flat-zoo-31952
08/11/2023, 4:11 PMlib-C
had lib-D
as a dependency, but Pants is using python_requirements(source="pyproject.toml")
as a source of third party depsflat-zoo-31952
08/11/2023, 4:11 PMlib-D
on PyPIflat-zoo-31952
08/11/2023, 4:12 PMenough-advantage-61561
08/11/2023, 4:13 PMpip
+ venv
workflow it has not mattered if you list 1st party or 3rd party dependencies in setup.pyflat-zoo-31952
08/11/2023, 4:13 PMenough-advantage-61561
08/11/2023, 4:14 PMrequirements.txt
.flat-zoo-31952
08/11/2023, 4:14 PMpip install lib-d
doesn't work, you have to tell pip the path the file somehow, or the lib has to be published on an index you have configurerdenough-advantage-61561
08/11/2023, 4:15 PMlib-D
at current working directory, thoughflat-zoo-31952
08/11/2023, 4:15 PMflat-zoo-31952
08/11/2023, 4:15 PMflat-zoo-31952
08/11/2023, 4:16 PMpip install lib/lib-D
would work from the root dir of your example repoflat-zoo-31952
08/11/2023, 4:16 PMcd lib
it wouldn't anymore, and pip install lib-D
wouldenough-advantage-61561
08/11/2023, 4:17 PMpython_requirements
is used to define 3rd party dependencies. Does this mean that BUILD files are used to define only 3rd party requirements?flat-zoo-31952
08/11/2023, 4:19 PMpython_requirments
will pick these up. You can have more than one python_requirements
but they need to be disjoint, i.e., you can't have the same dependency in two different python_requirements
sources in the same resolve.flat-zoo-31952
08/11/2023, 4:19 PMpython_sources
flat-zoo-31952
08/11/2023, 4:20 PMcat lib/lib-D/lib_d/BUILD
will yield something like python_sources()
as the contentenough-advantage-61561
08/11/2023, 4:22 PMlib/lib-D/lib_d/BUILD
has python_sources()
in itenough-advantage-61561
08/11/2023, 4:22 PMpants tailor ::
flat-zoo-31952
08/11/2023, 4:22 PMflat-zoo-31952
08/11/2023, 4:23 PMenough-advantage-61561
08/11/2023, 4:23 PMpython_requirements
sources in the same resolve " <-- what is a "resolve" here?flat-zoo-31952
08/11/2023, 4:24 PMpants test
workflow working with resolves turned off (and just a single pandas version). Resolves make things complicated, so i'd add that after you get the hang of the workflow, it's very differentflat-zoo-31952
08/11/2023, 4:25 PMenough-advantage-61561
08/11/2023, 4:25 PMenough-advantage-61561
08/11/2023, 4:25 PMflat-zoo-31952
08/11/2023, 4:26 PMflat-zoo-31952
08/11/2023, 4:26 PMenough-advantage-61561
08/11/2023, 4:26 PMflat-zoo-31952
08/11/2023, 4:26 PMflat-zoo-31952
08/11/2023, 4:27 PMpants tailor
or manually creating the python_requirement
target)flat-zoo-31952
08/11/2023, 4:27 PMimport pandas
pants will know to include pandasenough-advantage-61561
08/11/2023, 4:27 PMflat-zoo-31952
08/11/2023, 4:28 PMimport lib_d
it will know it needs to include lib_d
flat-zoo-31952
08/11/2023, 4:28 PMflat-zoo-31952
08/11/2023, 4:29 PMenough-advantage-61561
08/11/2023, 4:29 PM