Skip to content

Path dependencies specialization at build time #5495

@mindstorm38

Description

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

Feature Request

The main issue I want to address is a "bug" affecting "path dependencies", this issue has already been described in #3148 if you need more context. To sum up, such dependencies need a path to another project instead of a version. When building a poetry project (e.g. for publishing), the output archives .whl and .tar.gz both contains a metadata file, named METADATA in wheels, and PKG-INFO in tarball. In this file, each poetry dependency (except python one) are translated to a Requires-Dist one. For version constraints it works as usual, but for path dependencies we can get something like this Requires-Dist: foo @ ../bar, where foo is the package's name and ../bar is its location. But in reality of production, it will never work, it's only suitable for testing (and is addressed in issue #1168).

I also know that an alternative has already been suggested using dev-dependencies with path-dependencies, and dependencies with actual versions, but for me, it remains complicated to maintain dependencies versions.

The goal is to fix this by specializing the version of path-dependencies at build time, to have a fixed Requires-Dist field in the metadata. Because multi-repos (without usage of submodules) cannot use this path-dependency feature, I'll only be talking about monorepo workspaces (which are useful for small projects), but this proposal remains compatible with multi-repos and PyPI publishing.

From current specification (from official documentation):

[tool.poetry.dependencies]
# directory
my-package = { path = "../my-package/", develop = false }
# file
my-package = { path = "../my-package/dist/my-package-0.1.0.tar.gz" }

This schema will remain valid, but will be transposed to Requires-Dist: my-package (>=0.1.0, <0.2.0) in metadata, this version can be known from the pyproject.toml file in a directory-based path, from PKG-INFO for tarball-based paths or from METADATA for wheels. By default, we use a ~ tilde constraint to allow patch-level changes, behavior for non-semver versions is not currently specified.

Devs might want to change this default constraint, for this we need to extend the path dependency schema by adding a version key. Here are some examples:

# Simple constraints:
dep = { path = "<path>", version = ">=x" }    # actual constraint: >=1
dep = { path = "<path>", version = ">=x.x" }  # actual constraint: >=1.2
dep = { path = "<path>", version = "^x.x" }   # actual constraint: ^1.2
dep = { path = "<path>", version = "^x.x, !=1.2.0" }   # we can also use classic constraints
# By default, this constraints can be used to allow only patch updates (according to sementic versionning):
dep = { path = "<path>", version = "~x.x.x" }                 # actual constraint: ~1.2.3
dep = { path = "<path>", version = ">=x.x.x, <x.{x+1}.0" }    # equivalent to the previous one, less readable, and {x+1} syntax is ugly imo
# Disable specialization:
dep = { path = "<path>", version = false }

What do you think about this idea? I can try to work on a proof-of-concept pull request if you find that useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureFeature requests/implementations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions