-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 dependencies groups #1644
Support dependencies groups #1644
Comments
I didn't show any use-case for Neither for multiple groups on dependencies. This one must be clarified/specified more thoroughly I guess: default-dep = "*"
group-dep = { version = "*", groups = ["hello", "world"] } Then what happens when I do: poetry install --with hello
# since we do not include the "world" group, do we include group-dep or not?
poetry install --without hello
# since we exclude the "hello" group, but keep the other ones including "world", do we exclude group-dep or not? From the group page mentioned above (for
So if we follow the same logic: poetry install --without hello
# will still install group-dep since it's in the non-excluded "world" group
poetry install --with hello
# should be the inverse? so it would not include group-dep since "world" is non-included? |
@pawamoy I'll try to answer your questions as I understand them.
The first is excluding documentation dependencies from my test environment in continuous integration. I have a library, project-template-python, that fails on AppVeyor during installation of dependencies because some of them report This adds a performance benefit, too, as @rmorshea put it:
The second use case, which led me down a rabbit hole until I landed here, is... related to a conversation you and I had almost a year ago! (Wow, I honestly didn't notice either me or you in that thread until I started writing this comment.) Here's my example:
group-dep = { version = "*", groups = ["hello", "world"] }
optional-dep = { version = "*", groups = ["hello", "world"], optional = true } here is the behavior I would expect: poetry install # group-dep in, optional-dep out
poetry install --with hello # both in
poetry install --with world # both in
poetry install --with hello,world # both in
poetry install --without hello # group-dep in, optional-dep out
poetry install --without world # group-dep in, optional-dep out
poetry install --without hello --with world # both in
poetry install --without world --with hello # both in
poetry install --without hello,world # both out Let me just remark that the Ruby semantics are very poorly documented, but let me try to take their rule and tweak it to match these semantics as simply and concisely as possible:
I hope this is intuitive. |
This issue is pretty important to me. |
How would this feature relate to the "extras" feature? Would this be able to replace extras, or is there something that extras provides that these groups could not? It seems like groups would be somewhat of a superset? The way you specify what extras/groups are installed is different, but once you select the same set of extras/groups to install, would there be other differences? It seems that extras are not currently really working or documented well (#1145, #1076), so maybe this could be replacement for extras with clearer and more complete semantics? Note that where I say "extras" above, I refer to the "clusters of dependencies"-interpretation of that, not the "extras to apply to dependencies"-interpretation. See #1076 (comment) for some discussion of the difference. I believe the "extras to apply to dependencies"-interpretation is clearer and would not need to be replaced. |
I would not replace the extras system but add the group system on top. Reason: (Blow I added a shorted version of So the thing is that I use the extras system to split my development dependencies into categories. Then I can install So I think a good idea would be to keep the And I would only allow group assignments for optional dependencies. I see no use for the feature for mandatory dependencies. Currently: ...
[tool.poetry.dependencies]
python = "^3.6.1"
importlib-metadata = {version = "^1.6", python = "<3.8"}
mandatory-dep = {version = "^1.5.3", extras = ["some-extra"]}
enhancing-dep = {version = "^5.1.1", optional = true}
# Testing
pytest = {version = "^5.4.2", optional = true}
# Docs
sphinx = {version = "^3", optional = true}
# Code check
pre-commit = {version = "^2.4", optional = true}
mypy = {version = "0.770", optional = true}
pylint = {version = "^2.4", optional = true}
[tool.poetry.dev-dependencies]
devtools = {version = "^0.5", extras = ["pygments"]}
[tool.poetry.extras]
better-pkg-usability = ["enhancing-dep"]
testing = ["pytest"]
docs = ["sphinx"]
pre-commit = ["pre-commit", "mypy", "pylint"]
... How I would like it: ...
[tool.poetry.dependencies]
python = "^3.6.1"
importlib-metadata = {version = "^1.6", python = "<3.8"}
mandatory-dep = {version = "^1.5.3", extras = ["some-extra"]}
enhancing-dep = {version = "^5.1.1", optional = true}
# Testing
pytest = {version = "^5.4.2", optional = true, group = ["testing"]}
# Docs
sphinx = {version = "^3", optional = true, group = ["docs"]}
# Code check
pre-commit = {version = "^2.4", optional = true, group = ["pre-commit"]}
mypy = {version = "0.770", optional = true, group = ["pre-commit"]}
pylint = {version = "^2.4", optional = true, group = ["pre-commit"]}
[tool.poetry.dev-dependencies]
devtools = {version = "^0.5", extras = ["pygments"]}
[tool.poetry.extras]
better-pkg-usability = ["enhancing-dep"]
... With this a user could install the extras to enhance usability like always:
Both are extras but only viewed from another perspective. The "clusters of dependencies"-extra for your project is an "extras to apply to dependencies"-extra for someone else using your package. Also in setuptools the first is specified in PS: The extras for dependencies like this |
Oh yes, this is exactly what I've been missing in poetry. Groups as well as individual deps that I need to install on their own or together with the production code. I use poetry to setup multiple tox environments with isolated builds in tox.ini, and I currently need to wait for ~100 deps to be installed for each (!!!) tox env. The total installation time alone is many times longer than what it takes to run all tests. This feature would cut a large chunk out of the total wait time, and would probably be more valuable to me than speeding up the general installation time, which is something I understand is being worked on at the moment. |
I really liked this idea so I implemented it as a temporary work around until it lands in poetry actual. The idea, is you flag the groups with a comment: And then the following code takes those comments and writes them into |
Re-reading this discussion, I am still wondering what the essential difference between these new "groups" and the existing "extras" are? It seems that both are just specifying sets (I'm intentionally not saying "groups" here, to emphasize I'm talking about the generic concept of sets rather than the proposed "groups" feature) of dependencies, the difference seems to be only in the way these sets are addressed an their default. @Cielquan wrote:
What I read there is that "extras" are things that you can add to your dependencies (default omitted) and "groups" are things that you can omit from your (dev) dependencies (default included). The implementation @SimonBiggs follows a similar flow, where "groups" are things in the default dependency list that are annotated, resulting in an entry in the "extras" section as well. So I wonder if maybe the "extras" feature should just be somewhat E.g. taking the example from @Cielquan, that could become as below. Note
However, this does end up with the information spread out, so now I've
Compared to the original example by @Cielquan, this:
The idea here is that everything in the dependencies section is installed always, except for the Essentially, this would mean that "extras" and "groups" are just the same thing. More specifically:
One thing that still needs some thought is how This seems to offer a generic group feature, that cleanly maps onto the existing "extras" mechanism (as exposed to other packaging tooling such as pip), without duplicating information. One could even go one step further and say that
There might be some value in still storing dev dependencies in a separate section of the pyproject.toml file as now (easier to distinguish them), though just having a single list with explicit As a last extra step, you could consider allowing negated groups, e.g.:
This would be a package that is normally installed, unless
This would be installed only when Maybe this negation is one step too far and you should just add a "production" |
So, within a given production dependency definition currently an "extra" parameter is allowed. When that is defined within the dependency parameters it refers to a pypi extra for that dependency, not for your package, eg. alldeps within scikit-learn refers to an extra of scikit-learn, not your package. Let's say, your package is called "mypackage", and we want our package to have an optional dependency of scikit-learn within a group called ml (short for machine learning). And we want to make sure that when scikit-learn installs it installs with all of its own dependencies. I would expect this would look like: [tool.poetry.dependencies]
scikit-learn = {version = "*", extras = ["alldeps"], groups = ["ml"]} That way, running Importantly, when groups is defined, I believe this implies an implicit |
Yeah, I realize that that is what the
I do not think this is true. If you do this, then this "groups" concept becomes again the same as the existing "extras" concept, except with a different name. If you do this, you lose the ability to have dependencies that have a group set and are installed by default, but can be omitted using It might be true that |
@matthijskooijman I really like what you described above. I think it's very sensible.
I like it! |
Do you mean "dependencies in the dev group" here? Or maybe I do not understand what you say exactly?
Do you mean that something would actually write them to the |
Yup, I was not intending there to be any difference in the way I was wanting to use them. The aim would be to minimise inherent duplication of the package names and make a cleaner config API. I personally was not proposing any feature changes, instead just what I see as an improved API. I found manually managing the following lists was tedious and error prone, this is in contrast to adding group flags which I found to be simple and hard to make a mistake: |
What I mean is that currently, to define extras, you have to put the dependencies in the
The latter, it would happen in memory, while building the wheel, etc., the |
After some time and based on the discussion above from a week ago I changed my idea: Currently we have the dev section with dev dependencies and the normal dependency section which includes the package's dependencies and optional dependencies which can be included via the extras section. IMO the extras section should be used to add additional dependencies which enable some additional functionality for the package and NOT the development. But currently the extras are misused (by me e.g.) to also group dev dependencies. I use this to not always install e.g. the linter tools when I run unit tests (with tox) like I mentioned earlier. So the primary thing I would like to achieve with the "group" feature is to add an extra like feature to the dev dependencies also. With this you have the normal dependency section including the must have dependencies for the package to run and the optional ones which can be included via the extras like it is now. No change needed here. This basic change/step can be enhanced in multiple ways:
DISCLAIMER: The ideas above are not all mine but also taken from earlier comments. I just combined them to something I would like to see. |
I'm glad to see this is on the
I'd be interested in that. too, and same with Each of these targets influenced would considerably help dev workflows I've been involved in. For example, here is a PR submitted for |
the ability to add environments/targets as proposed would be massively helpful in ML projects imo! we usually strip out quite a few of the requirements when serving models that would have been otherwise required during training. i reckon the traditional way for separating requirements |
Thank you for getting this done @sdispater ! Any plans to release another pre-release with the feature? My team has a pretty convoluted setup (not using Poetry) that could be simplified greatly with this feature, I'd love to migrate to Poetry. |
Great to see this feature is now available, thanks. Also great that this neatly generalizes the dev-dependencies in a compatible way :-) I've read through the documentation, and am left with a few questions:
|
Regarding point 1, the current wording tells me that plain
(emphasis not mine) seems conflicting to me with the following statement:
|
+1 for @matthijskooijman 's point 2. Would be very nice to be able to Currently it seems you have to re-define (bad) the |
Would it be possible to add this functionallity to Something like:
|
@eltbus The export plugin already supports that: https://github.com/python-poetry/poetry-export-plugin#available-options. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Feature Request
As @mozartilize stated in this comment, groups from Ruby's gemfile could be a great addition and a solution to our complex workflows and different environments (local, production, ci, docs, etc.).
Instead of supporting more
tool.poetry.*-dependencies
sections, we could add support for agroups
property on dependencies. It would be more flexible than rigid sections.I also understand there is the
extras
functionality, but using extras changes the behavior ofpoetry install
, as one needs to now specify the extras to install all the dependencies. Also, extras are opt-in only, and often times we need opt-out.Also:
default
group would be attributed to dependencies without groups (requests
in the above example)/bandit
forbandit
, etc.Then we would have the following options for the
poetry install
command:--groups
: explicitely specify which groups to install (these and only these groups, no implicit default group)--with-groups
or--with
: default group plus the specified groups--without-groups
or--without
: all groups minus the specified groupsUsage would be:
#1007 could then probably be closed in favor of this issue.
The text was updated successfully, but these errors were encountered: