Closed rcaneill closed 1 year ago
Oops, we should change this to using the version
function from importlib.metadata
.
from importlib.metadata import version
__version__ = version("gsw_xarray")
Probably with a fallback for funny install situations (i.e. dev)
https://github.com/python-poetry/poetry/issues/144#issuecomment-623927302
from importlib import metadata import toml try: __version__ = metadata.version(__package__) except metadata.PackageNotFoundError: __version__ = toml.load("pyproject.toml")["tool"]["poetry"]["version"] + "dev"
There seems to be an easy solution for the dev. I don't really know how to test it though...
Other solution, that does not require to add toml as mandatory dependency (but only as dev dependency):
https://github.com/python-poetry/poetry/issues/144#issuecomment-877835259
Reading this thread, it seems to me that for now it's best to keep both the pyproject.toml version and the package.version.
So my process is just to stop me accidentally forgetting to update one.
I've got a simple test that checks that those two are in alignment and fails if not.
import toml
from pathlib import Path
import my_package
def test_versions_are_in_sync():
"""Checks if the pyproject.toml and package.__init__.py __version__ are in sync."""
path = Path(__file__).resolve().parents[2] / "pyproject.toml"
pyproject = toml.loads(open(str(path)).read())
pyproject_version = pyproject["tool"]["poetry"]["version"]
package_init_version = my_package.__version__
assert package_init_version == pyproject_version
I like quite well this 2nd option
@DocOtak Which option would you prefer?
Version is still 0.2.1 I guess we just need to take care to update it next time