cdgriffith / Box

Python dictionaries with advanced dot notation access
https://github.com/cdgriffith/Box/wiki
MIT License
2.64k stars 107 forks source link

Fix Poetry extras metadata #243

Closed JacobHayes closed 1 year ago

JacobHayes commented 1 year ago

The tool.poetry.extras fields takes package names, not full names+versions (the version constraints are pulled from the main dependency spec). Apparently, poetry would silently drop invalid (or maybe just unmatched) extra names, so ruamel and tomli, which had version constraints in the extras name, were not correctly marked as extra.

Here's some of the generated METADATA file before:

Requires-Dist: PyYAML (>=6.0) ; extra == "pyyaml"
Requires-Dist: msgpack (>=1.0.0) ; extra == "all" or extra == "msgpack"
Requires-Dist: ruamel.yaml (>=0.17)
Requires-Dist: toml (>=0.10.2) ; extra == "toml"
Requires-Dist: tomli (>=1.2.3) ; python_version < "3.11"
Requires-Dist: tomli-w (>=1.0.0) ; extra == "all" or extra == "tomli"

and after:

Requires-Dist: PyYAML (>=6.0) ; extra == "pyyaml"
Requires-Dist: msgpack (>=1.0.0) ; extra == "all" or extra == "msgpack"
Requires-Dist: ruamel.yaml (>=0.17) ; extra == "all" or extra == "yaml" or extra == "ruamel-yaml"
Requires-Dist: toml (>=0.10.2) ; extra == "toml"
Requires-Dist: tomli (>=1.2.3) ; (python_version < "3.11") and (extra == "all" or extra == "tomli")
Requires-Dist: tomli-w (>=1.0.0) ; extra == "all" or extra == "tomli"

Or the diff in the extras section in the poetry.lock:

 [extras]
-all = ["tomli-w", "msgpack"]
+all = ["ruamel.yaml", "tomli", "tomli-w", "msgpack"]
 msgpack = ["msgpack"]
 pyyaml = ["PyYAML"]
-ruamel-yaml = []
+ruamel-yaml = ["ruamel.yaml"]
 toml = ["toml"]
-tomli = ["tomli-w"]
-yaml = []
+tomli = ["tomli", "tomli-w"]
+yaml = ["ruamel.yaml"]
cdgriffith commented 1 year ago

Thanks for poitning out the version conflicts in the extra!

However the groups do need the optional flag:

With the optional flags

> poetry install 
Updating dependencies
Resolving dependencies...

Writing lock file

No dependencies to install or update

Installing the current project: python-box (7.0.0rc3)

Without

> poetry install

Package operations: 40 installs, 6 updates, 0 removals
...
JacobHayes commented 1 year ago

Ah, that makes sense. Those deps (dev and test group) I think are only installed when inside the project using poetry install (which includes the dev deps by default), but not when another package installs python-box

Dependency groups, other than the implicit main group, must only contain dependencies you need in your development process. Installing them is only possible by using Poetry.

I removed that commit and the poetry.lock I accidentally committed (though you might consider tracking that if you want to 😄).

cdgriffith commented 1 year ago

Yup the dev and test are really so I can use them in the github action workflows, and that way just add poetry install --with dev or --with test for which use case.