Skip to content
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

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

Closed
rcaneill opened this issue Mar 22, 2023 · 5 comments · Fixed by #68
Closed

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

rcaneill opened this issue Mar 22, 2023 · 5 comments · Fixed by #68

Comments

@rcaneill
Copy link
Collaborator

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

@DocOtak
Copy link
Owner

DocOtak commented Mar 22, 2023

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
Copy link
Collaborator Author

rcaneill commented Mar 24, 2023

python-poetry/poetry#144 (comment)

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
Copy link
Collaborator Author

Other solution, that does not require to add toml as mandatory dependency (but only as dev dependency):

python-poetry/poetry#144 (comment)

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
Copy link
Collaborator Author

I like quite well this 2nd option

@rcaneill
Copy link
Collaborator Author

@DocOtak Which option would you prefer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants