Closed yongrenjie closed 6 months ago
Sorry for leaving random comments on closed issues, but if interesting for future reference you can also do this the other way around in Python 3.10+, i.e. have the version defined in pyproject.toml
and use importlib.metadata
to define __version__
in __init__.py
, e.g. see https://github.com/alan-turing-institute/AIrsenal/blob/main/airsenal/__init__.py I find it slightly more intuitive for pyproject.toml
to be the source of all metadata about the package.
ooh @jack89roberts that's really helpful! agree that the toml file is better as the source of truth!
maybe we should change the template to work that way too @phinate?
you can also do this the other way around in Python 3.10+
I think it's 3.8+ actually, but it was called a "provisional feature" (whatever that is) until 3.10
Sorry for leaving random comments on closed issues
Open for the time being now ;)
I find it slightly more intuitive for pyproject.toml to be the source of all metadata about the package.
Yes, this makes sense. I only made peace with the __init__.py
route because of knowing I can import __version__
, and that I've seen it done as a release commit in other repos. Happy to explore this way though, don't think it's much work to swap it around!
this idea was implemented via #26! many thanks for bringing this back to life :)
In the current
pyproject.toml
we have this bit:https://github.com/alan-turing-institute/python-project-template/blob/f1e40e728510fda5ca51874208912b4ffd934fba/project_template/pyproject.toml#L65-L67
Having the version number in two places is not ideal (unless there are checks to make sure that they stay in sync).
Is it possible / useful to change this to use
tool.setuptools.dynamic
as described in https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata? Then__init__.py
would be the single source of truth for versioning.It seems that we would need something like:
(though not sure about whether any of the curly braces above need to be escaped)