-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
Improve referencing __version__ attribute. #913
Comments
What about custom version providers? |
Hmm. That’s a nice idea but I’d have to wire my own blob of code into into |
You'd have to publish a package with the custom provider in python, no code goes in pyproject.toml. Then you'd install: pip install commitizen cz-attr-version And then you'd do in commitizen toml: provider = "attr_version" |
Now that I think about it... maybe we could even make the existing provider On the other hand, the recommendation seems to point to dropping the usage of any version information at module leven in favor of just using Thoughts @Lee-W @noirbizarre ? |
I do like that.
That PEP is from 2011, so I’m tempted to not give it too much weight. Might be worth bringing up for discussion at the forum? |
like this one as well |
This is a complex topic I know quite well (sorry for the long post, but on this topic, this is required). You need to include in the reasoning that while PEP621 is about exposing static metadata that can be read at packaging time (which is perfect for commitizen as it only imply reading/writing a toml file), both Runtime access to both of those is not yet standardized, PEP621 is not about this and I don't think commitizen has any business to to on this. Those are the responsibility:
Note that PEP517 build backend is what makes your project buildable with build and However, both Here's my recipe to have commitizen properly works with PEP621 metadata and having both runtime access properly work (and my PR on version providers was meant to allow that):
This makes [project] # PEP621 standard project metadata
...
dynamic = ["version"] # standard way of delegating dynamic fields resolution to the PEP517 backend
[build-system] # PEP517 build backend
requires = ["pdm-backend"]
build-backend = "pdm.backend"
[tool.pdm.version] # Specific to pdm build backend
source = "scm"
write_to = "<pkg>/VERSION"
[tool.commitizen]
version_provider = "scm" and the from __future__ import annotations
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path
def read_version() -> str:
try:
return str(version("<pkg-name>")) # This is the PEP621 `project.name` not the root package
except (PackageNotFoundError, ImportError):
version_file = Path(__file__).parent / "VERSION"
return version_file.read_text() if version_file.is_file() else "0.0.0.dev"
__version__ = read_version() # should be failsafe Why not just read the version file ? But this is only one way of doing it properly, my way according to my constraints (one being having runtime traceability of deployed assets versions, event if they are not tagged, which is often the case when you have some CI and you only bump versions you consider stable after trial). Note that this recipe also works with editable installation of your project. This is very related to how you expect to use those. For many people (especially those coming from the JS world where this is the TLDR: the PEP621 provider should not read those packaging or runtime only information (meaning they exist at a time commitizen can't read) however documenting how it's possible to properly read this metadata at runtime and supports all those conventions in a standard Python package could be a great addition. Note: a static tool trying to read the |
Description
The other day I came across the package version declaration in SQLAlchemy’s
setup.cfg
here:The handling of special directive
attr:
is documented here.I thought this quite useful to ensure that a version is declared in one place only; currently
cz
relies on version_files to point at attributes that need to be bumped.This is probably a low-priority item that may or may not make sense. But I wanted to raise it for discussion anyway…
Possible Solution
No response
Additional context
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: