pdm-project / pdm

A modern Python package and dependency manager supporting the latest PEP standards
https://pdm-project.org
MIT License
7.97k stars 410 forks source link

Documentation: Describe how to configure dynamic package versioning using scm/git #2089

Closed vlcinsky closed 1 year ago

vlcinsky commented 1 year ago

This issue is proposing an update of pdm documentation with regards to declaring package version.

Current status (as of pdm version 2.7):

pdm allows to specify in pyproject.toml a package version in multiple ways.

Static

[project]
version = "1.0.0"

The version is explicitly stated in the pyproject.toml.

Dynamic (from a file):

[project]
...
dynamic = ["version"]

[tool.pdm]
version = { source = "file", path = "mypackage/__version__.py" }

The version is read from a file (here mypackage/__version__.py) which is typically managed by some external tool such as bumpversion.

Dynamic (from scm/git)

[project]
...
dynamic = ["version",]
...
[tool.pdm.version]
source = "scm"

The version is derived from the latest tag in (git) source control. If current commit is tagged, the version is read from the tag as is, if the tag is present is some commit behind, version string is derived from given tag and current commit hash.

Documentation describes only the first two options

The problem is, that the "Dynamic (from scm/git)" option is not described in the documentation and it is not easy to find it.

Proposed solution

Update the PEP 621 Metadata/Package version as follows:

Alternative solution

Alternatively we may update "Build configuration/dynamic versioning" section which seems to be currently intended but is actually missing.

Points to review

I have tested the dynamic versioning with scm/git for pdm.backend

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

It is very likely, that each backend may offer a bit different options for assigning version. In such a case, it would be better to use dedicated section for each backend and in that place describe (for pdm-backend) or refer to (for other backends) how is versioning and possibly other aspects of package build configured and managed.

pawamoy commented 1 year ago

Thanks, that would be a nice enhancement to the docs. Would you like to contribute a PR with the tabs you suggest?

frostming commented 1 year ago

I agree to apply the alternative solution. The "dynamic versioning" in PEP 621 metadata page is what I forgot to move out when we remove the backend-specific logics from PDM. Now it doesn't make sense to keep it there, since as you said, the config options may vary in different backends. We have this for pdm-backend.

Welcome to submit a PR to update the docs.

vlcinsky commented 1 year ago

@frostming I will take care of PR.

The concept for "versioning" PR are

off topic: distinguish pdm specific stuff and other stuff in pyproject.toml

Personally I feel, that it is worth (generally for pdm) to clarify, that:

I will not attempt to put it into versioning section (in fact my PR will focus only on the versioning issue).