stocky-helmet-2265502/14/2023, 4:18 PM
for that - and I have package A which depends on package B locally. I’m struggling to figure out how to get A to depend on the output of B - I could add B’s source files to A’s resolve but then A wouldn’t inherit B’s 3rd party dependencies. Depending on the generated whl doesn’t seem to be working (not even sure if it should). Package A is using poetry and pants is using
. Happy to provide further info but I’m not sure what the “right” way to do it is to know which errors/logs to share
enough-analyst-5443402/14/2023, 4:39 PM
The A should depend on "lib" and not "wheel".
python_sources(name="lib") python_distribution(name="wheel", dependencies=[":lib"])
stocky-helmet-2265502/15/2023, 2:38 AM
it doesn’t seem to find any 3rd party dependencies
enough-analyst-5443402/15/2023, 2:40 AM
stocky-helmet-2265502/15/2023, 2:55 AM
enough-analyst-5443402/15/2023, 3:05 AM
$ pants --python-infer-unowned-dependency-behavior=error test : 19:10:43.03 [INFO] Initializing scheduler... 19:10:43.21 [INFO] Scheduler initialized. 19:10:44.99 [ERROR] 1 Exception encountered: UnownedDependencyError: Pants cannot infer owners for the following imports in the target //test_file.py:tests: * numpy (line: 1) If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/v2.14/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
There is no current way to get Pants to read 3rdparty dependencies from
$ git grep numpy setup.py:setup(install_requires=["numpy >=1.16.2"]) test_file.py:import numpy
, you need one of: 1. https://www.pantsbuild.org/docs/reference-python_requirements 2. https://www.pantsbuild.org/docs/reference-pipenv_requirements 3. https://www.pantsbuild.org/docs/reference-poetry_requirements All 3 of those read requirements from corresponding file type (requirements.txt file, Poetry pyproject.toml, Pipenv.lock). The 1st though allows you to just write the requirement strings inline if you have no such file.
stocky-helmet-2265502/15/2023, 3:40 AM
I’m too used to folks not providing something helpful like that.I feel your pain - I’ve been on both sides of that 😉 so a couple responses - I’m aware of the 3 solutions you posted and I’ve used all 3 so far (I’m trying to pantsify a massive repo using a different pattern in each package because the repo’s a decade old). I can migrate to one of those 3 if need be - I want to normalize everything if I can. The only reason I want to keep stuff in the setup.py as above is because that’s how it is now and I want pants to run in parallel initially, before replacing long-term regarding the dynamic-metadata - huge thanks for the link! The use case here is to have multiple requirements blocks depending on a flag and it looks like I can set it up to use requirements.txt files using a flag as well - I’ll play around with that now The thing that led me down this path originally is this bit which gave me the impression that if pants can build a whl based on a pyproject.toml, it must be able to pull dependency info as well. Clearly I was wrong - I think it could be worth documenting this limitation and recommended alternatives on that page such as with this change: https://github.com/pantsbuild/pants/pull/18253
enough-analyst-5443402/15/2023, 4:14 AM
The thing that led me down this path originally is this bit which gave me the impression that if pants can build a whl based on a pyproject.toml, it must be able to pull dependency info as well. Clearly I was wrongWell, that's unclear. You example repo does not follow those directions either. I.E. you do not declare a `python_distribution`target at all. There is an example setuptools one there at the bottom of the doc section. Had you tried doing that and depending on that target in your test target?
stocky-helmet-2265502/15/2023, 4:29 AM
You example repo does not follow those directions either. I.E. you do not declare a `python_distribution`target at all.My example repo does not - my actual repo does. As I said above:
It doesn’t include the python_distribution or separation of modules, not sure if including those would be more or less helpfulIn my project I did do a
target and tried depending on both that and the
target in my tests - the original problem being that nothing led to 3rd party dependencies working and nothing in the docs telling me that it shouldn’t work
FWIW, modern setuptools supports reading from a requirements.txt file with no setup.py code; so you may want to use that method and it will keep your requirements DRY.Just to confirm, pants cannot infer from the pyproject.toml that it should look in a requirements.txt. You are suggesting the dependencies go in a requirements.txt which is then separately depended on by pants directly as well as the pyproject.toml unrelated to pants, correct?
enough-analyst-5443402/15/2023, 5:19 AM
happy-kitchen-8948202/16/2023, 11:31 PM
stocky-helmet-2265502/16/2023, 11:53 PM
depending on a
, in this case a pyproject.toml resource
happy-kitchen-8948202/16/2023, 11:55 PM
that wraps that same pyproject.toml things work, right?
stocky-helmet-2265502/16/2023, 11:58 PM
happy-kitchen-8948202/17/2023, 12:25 AM
stocky-helmet-2265502/17/2023, 12:30 AM
[build-system] requires = ["setuptools>=61.0.0", "wheel"] build-backend = "setuptools.build_meta"
happy-kitchen-8948202/17/2023, 12:53 AM
stocky-helmet-2265502/17/2023, 2:43 PM
it installs the appropriate one. If I try to use it through pants though, it appears to ignore all but the last entry and if that entry doesn’t match the environment marker it just doesn’t install the dependency
pip install -r requirements.txt
enough-analyst-5443402/17/2023, 2:52 PM
stocky-helmet-2265502/17/2023, 4:29 PM
enough-analyst-5443402/17/2023, 4:42 PM
stocky-helmet-2265502/17/2023, 4:52 PM
enough-analyst-5443402/17/2023, 4:52 PM
stocky-helmet-2265502/17/2023, 4:52 PM
enough-analyst-5443402/17/2023, 4:53 PM
stocky-helmet-2265502/17/2023, 4:53 PM
enough-analyst-5443402/17/2023, 4:53 PM
stocky-helmet-2265502/17/2023, 4:54 PM
enough-analyst-5443402/17/2023, 4:55 PM
stocky-helmet-2265502/17/2023, 4:56 PM
Ok. I suspect that misses your single setup.py constraint (edited)maybe not, though it’s getting complicated. I believe setup.py can pull in multiple requirements.txt files, meaning I can do one per resolve
enough-analyst-5443402/17/2023, 4:56 PM
stocky-helmet-2265502/17/2023, 4:57 PM
So, what do you do today - publish 2 totally different projects / artifacts?In this case only 1 is published externally directly, but it’s a different setup when used locally vs when packaged/published as part of a different local package
enough-analyst-5443402/17/2023, 4:58 PM
stocky-helmet-2265502/17/2023, 5:01 PM
enough-analyst-5443402/17/2023, 5:01 PM
stocky-helmet-2265502/17/2023, 5:02 PM
enough-analyst-5443402/17/2023, 5:02 PM
stocky-helmet-2265502/17/2023, 5:03 PM
enough-analyst-5443402/17/2023, 5:06 PM
support for example, and so it didn't suit for internal lock use since it didn't cover all Pants cases. That leaves using it as an external input, which I think could be done, but no-one has asked for it, or at least done so and followed up with the muscle to implement.
stocky-helmet-2265502/17/2023, 5:07 PM
enough-analyst-5443402/17/2023, 5:08 PM
stocky-helmet-2265502/17/2023, 5:10 PM
enough-analyst-5443402/17/2023, 5:10 PM
stocky-helmet-2265502/17/2023, 5:13 PM
which would automatically add the block to a BUILD file?
./pants install numpy==1.2.3
enough-analyst-5443402/17/2023, 5:13 PM
stocky-helmet-2265502/17/2023, 5:14 PM
enough-analyst-5443402/17/2023, 5:14 PM
stocky-helmet-2265502/17/2023, 5:15 PM
enough-analyst-5443402/17/2023, 5:15 PM
stocky-helmet-2265502/17/2023, 5:18 PM
I think nearly all ideas that “save dev time” tend to be misused anyhow. Most of them seem to make you know less at the end of the day.This said by a dev working on pants - a tool used to save dev time 😂
enough-analyst-5443402/17/2023, 5:30 PM
and get the optional dependencies implied by
Now Pants does support that requirement string, but it does not offer support for injecting the "extra1" extra into the marker evaluation environment.
optional-thing; extra = "extra1"
for a 3rd party dependency the standard Python machinery below Pants injects the "extra1" and "extra2" markers. It's just the 1st party case where Pants would have to provide that mechanism and does not today.
It’s a tightrope walk - when things are 100% rock solid and completely remove any need for doing a thing (removing pointers in higher level languages for example), they’re great and should be used - because they “can’t” be mis-used.I guess, but I fooled myself by doing this for, say,
. It always works and you don't know it's there, but you pay a big price for it. I still don't understand linking and loading completely, but I've since read a book on linkers & loaders and I'm slightly less dumb. I think tools are definitely dangerous and I am wary of them at least. Writing them is another story! That forces you to learn how things work. That I like.
stocky-helmet-2265502/17/2023, 6:30 PM
enough-analyst-5443402/17/2023, 6:32 PM
stocky-helmet-2265502/17/2023, 6:34 PM
enough-analyst-5443402/17/2023, 6:44 PM