-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support installing Poetry dependency groups #1080
base: main
Are you sure you want to change the base?
Conversation
@Niicck e.g.
Edit: Only version v3.x+ of importlib-metadata has the py.typed, if you get issues w/ mypy on 3.7 |
@samypr100 Big thanks for that check. Tests and mypy are now passing for 3.7 |
Edit: There is now an MR for this: As a slight tangent, when I was playing around with If anyone was intrepid, fixing that upstream would make using this |
@cjolowicz Would you be able to review this MR? |
Hello friends. I'm going to be offline for the next couple of months. If there are change requests in future reviews, someone else is welcome to address them and add to this PR. In the meantime, if people want to install poetry groups using nox, I have a workaround Here's the code for that helper function with a couple examples:
|
if groups: | ||
args.extend(f"--only={group}" for group in groups) | ||
elif self.config.is_compatible_with_group_deps(): | ||
args.append("--with=dev") | ||
else: | ||
args.append("--dev") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the check on self.config.is_compatible_with_group_deps()
only for --with
? Isn't --only
also only available for poetry>=1.2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we want to do is export the "main" group along with the "dev" group. poetry export --with=dev
implicitly exports the "main" group as well.
If we ran poetry export --only=dev
then we'd only be exporting the "dev" group without "main," which is not what we want.
poetry export --with=dev
is the equivalent of poetry export --dev
. We want the expected default behavior to be the same regardless of what version of poetry the user is using.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading this again, it looks like I misunderstood your comment. Ok. You're asking why the first if groups:
clause doesn't also check for self.config.is_compatible_with_group_deps()
since that if groups:
clause uses the --only
flag which is only available for poetry v>=1.2.
The reason is because earlier in the code we have a check within _PoetrySession.export_requirements
that makes sure that if you're using "groups" that you're using the right version of poetry. And there's a unit test to ensure that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks!
Any hope to merge this soon @cjolowicz ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Came looking to make this PR and found it was already here 🎉
@cjolowicz Curious, is |
The minimum should be avoiding warnings (#873) and anticipate future breakage(s). |
@johnthagen I've been swamped with other work, but I expect to circle back to this project in the coming few weeks. I'll do my best to come up with a sustainable model for maintaining this package going forward. That might involve passing it on to others or reducing the bus factor. |
@Niicck FYI, there are some merge conflicts in this branch now, likely from |
@Niicck I was curious if you still had any interest in getting this branch back ready for a merge. Would ❤️ this feature. |
If @cjolowicz is interested in approving this PR/feature, then yes I'd be happy to bring the branch back into merge shape. If not, then I won't put any more development time into something that we're not intending to merge. |
Closes #663
Closes #977
Closes #873
This PR adds a
install_groups
method to nox_poetry Session proxy. It has the same interface assession.install
except that you pass in the dependency groups that you want to install. This feature requires poetry >=1.2.0, but the rest of the code is compatible with <1.2.0, there are no breaking changes.Example usage:
session.install_groups("lint", "test")
Implementation Notes
install_groups
uses poetry export's--only
flag to just get the requirements for the groups you specify. They are then installed viapip install -r
.install_groups
as a new method on the Session class was the cleanest way to implement this feature. My first approach followed this suggestion of addingpoetry_groups
as a kwarg ofinstall
. But this created confusing interactions between installing individual dependencies and installing entire group dependencies. The initial support PR had the right approach, so I sprang off from there._PoetrySession.export_requirements
is now more explicit. If we're generating a constraints file to only install individual packages, thenexport_requirements
will generate aconstraints.txt
. If we're creating a requirements file that is intended to install the entirety of select poetry dependency groups, thenexport_requirements
will generate a requirements file with the formatgroup1,group2-requirements.txt
. The requirements.txt file is prefixed with the groups so that if our user inputted install_groups change, we'll regenerate the requirements.txt file, even if the poetry.lock hash hasn't changed.