hi, I’ve a python distribution questions. I’ve a p...
# general
b
hi, I’ve a python distribution questions. I’ve a package that I want to distribute with some of its dependencies in
extras_requires
Pants correctly adds them to
extras_requires
in the generated setup.py . How do I tell Pants to not add them in
install_requires
?
Also, how do I make those dependencies available for my
test
goal?
h
To clarify, you add this package to
extras_requires
manually in your `python_distribution`'s
provides=
value?
And so you want it to not also be automatically added to
install_requires
?
b
Correct
h
And this package is built from your repo? So there are two
python_distribution
targets involved, one for the extra and the main one that adds the extra in its
extra_requires
?
b
Yes it is built from my repo. The
extra_requires
is a mix of 3rdparty and first party packages. The first party code is in the same namespaced repo
e
Ah, yeah. We don't handle that at all. This will need some new feature work.
@big-xylophone-43403 your help spec'ing this out in an issue would be great. I'd guess though that ideally you could supply a mapping from extra name to list of targets and then Pants would do the rest and calculate extras requirements and trim install_requires.
👍 2
Also, how do I make those dependencies available for my test goal?
So, instead of testing the distribution's files and extras files directly, you want tests to go through the hoop of building the distribution into a wheel for example, then installing that wheel in the test sandbox?
As discussed over here https://pantsbuild.slack.com/archives/C046T6T9U/p1624495153473700?thread_ts=1624495153.473700&cid=C046T6T9U you can ask that a test target have the packaged distribution made available in the test sandbox, but the rest is up to you. So your test would need to install the distribution as part of it's setup as things stand.
Since this has come up twice in quick succession there's either a non-Pants workflow we need to provide docs on the (easier) Pants way to do this (don't build an intermediate package) or else there's an important case Pants is missing where you really do want the intermediate step for some reason we've not encountered yet through our own dogfooding.
If @proud-dentist-22844 s plugin over in that thread is what you're looking for, you might chime in on that thread.
b
No. I don’t need the package to built for the test goal. I assumed that Pants already supports this use case and was wondering if the extras will still be available during tests.
I’ll create the issue that describes this use case
h
If your tests depend on the extra code then it should "just work", although if they don't have
import
statements that reference the code then you may need to manually add a dependency in the BUILD file. But this should bypass the distribution entirely and just be a direct 1stparty library dependency.
That is if you have a
python_tests
target that (directly or indirectly) `import`s something from a
python_library
target in the same repo then it should work already, regardless of how that
python_library
target is published as a distribution.
Is it possible that there is no
import
statement that allows pants to infer the dependency? if so then you just need to add it manually in the appropriate BUILD file.
But regarding the
extras_requires
, when you add it manually I guess you hard-code the version of the requirement?
As John mentioned, we can add some support for knowing the difference between
install_requires
and
extras_requires
if you could help us spec it out.
b
So my tests are working fine 🙂 My question was if Pants already supports removing extras from
install_requires
, does it have any affect on my tests.
But regarding the 
extras_requires
, when you add it manually I guess you hard-code the version of the requirement?
Yes they are hardcoded in the
python_distribution
provides
h
Ah no, it doesn't support removing extras from
install_requires
, we'd need to figure out a solution, but it wouldn't affect tests either way.
b
I created this issue that describes our use case
👍 1
h
Thanks!