DocOtak / gsw-xarray

Wrapper for gsw that will add CF attributes to xarray.DataArray outputs
https://gsw-xarray.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
23 stars 3 forks source link

We forgot to change version in __init__.py file #62

Closed rcaneill closed 1 year ago

rcaneill commented 1 year ago

Version is still 0.2.1 I guess we just need to take care to update it next time

DocOtak commented 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)

rcaneill commented 1 year ago

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...

rcaneill commented 1 year ago

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
rcaneill commented 1 year ago

I like quite well this 2nd option

rcaneill commented 1 year ago

@DocOtak Which option would you prefer?