poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Dependency aliasing

Open blaggacao opened this issue 6 years ago • 5 comments

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] I have searched the documentation and believe that my question is not covered.

Feature Request

  • Packages provide API namespaces
  • API namepsaces are mostly identified by the package name
  • A package name mostly resolves to a package source
  • Yet, there are valid exceptions to both norms:
    • A package should resolve to an alternate (local) source for dev (eg. python-poetry/semver dev branch to python-poetry/poetry dev branch)
    • A package namespace can be provided in different flavors by different packages (e.g. psycopg2 & psycopg2-binary)

Therefore, add [tool.poetry.dev-alternates] with exactly the same syntax as [tool.poetry.dependencies] yet with an optional aliases field on the dep object, to inform which production package's namespace is provided through this package during dev. If aliases is not specified, it shall be inferred by the dep name itself.

Example covering both cases:

[tool.poetry.dependencies]
python = "^3.7"
dodoo = "^2.0"
psycopg2 = "^2.8"

[tool.poetry.dev-alternates]
psycopg2-binary = {aliases = psycopg2, version = "^2.8"}
dodoo = {path = "../dodoo"}

Further considerations

toml file API

  • It could be considered to make this a sub-path of [tool.poetry.dev-dependencies], however I consider, flat rymes are part of poetry's rythm, so stick with the groove.
  • Making this a feature of [tool.poetry.dev-dependencies] itself might probably not be verbose / descriptive enough and decrease clarity and readability

Merge strategy

I should be precise in that, it shall be expected to do a true merge of the objects, so -- strictly -- psycopg2-binary = {aliases = psycopg2, version = "^2.8"} could be written as just psycopg2-binary = {aliases = psycopg2}

CLI UX

From a UX perspectve, maybe the install --develop=DEVELOP has almost a 90% overlap in semantics with the requested feature. It would be an acceptable modification to current behaviour, if:

  • install --develop=DEVELOP always uses the alternate dev dep -- if specified -- in addition to install said dep in development mode

This FR collects a few FR in the issue catalogue, please reference them as you see fit.

blaggacao avatar Dec 12 '19 16:12 blaggacao

Collects (at least):

  • #483
  • #1264

blaggacao avatar Dec 12 '19 16:12 blaggacao

+1 on this, not sure why it hasn't been implemented yet

rdozier-work avatar Jun 24 '24 18:06 rdozier-work

The psycopg2 example is indirectly solved / closed. This issue affects many other packages.

Here is another:

pip install nats-py
import nats
nc = await nats.connect("tls://demo.nats.io:4443")
[tool.poetry.dependencies]
nats-py = { version = "~2.8.0" }

https://github.com/nats-io/nats.py https://pypi.org/project/nats-py/

skewty avatar Jul 03 '24 18:07 skewty

Please see the recent discussion around package variants on the python channels, once such an option is available in the wider eco system, poetry will be able to support it.

clintonroy avatar Jul 03 '24 22:07 clintonroy

One good example here is tensorflow. See: https://www.tensorflow.org/install/pip

You can install tensorflow from pypi through at least three different packages: tensorflow, tf-nightly and tensorflow-cpu.

If you don't need gpu support, and want to save space, you should use tensorflow-cpu. However, tensorflow-cpu only supports Linux and Windows since the regular tensorflow package for MacOS is already cpu-only.

If you want to support all three common OSes and you want a cpu-only tensorflow, this gets really difficult in poetry today.

harahu avatar Nov 20 '24 15:11 harahu