addresses issue #257: get version number from package metadata in __i… #261
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…nit__.py
Let me know if there are any modifications I should make!
Solution:
As one of the solutions from https://packaging.python.org/en/latest/guides/single-sourcing-package-version/.
Fixed Behavior:
previously (using a virtual env that the cloned repo is installed into):
pipenv run python -c "import astroML; print(astroML.__version__)" -> 1.0.2
now:
pipenv run python -c "import astroML; print(astroML.__version__)" -> 1.0.3.dev0
Which now (mostly) matches the behavior from
pipenv run python setup.py --version -> 1.0.3.dev
(missing the zero)Alternative Modifications / Alternative Solutions:
Add a try/except for errors when astroML isn't installed yet or if version number is undefined (what setuptools does):
https://github.com/pypa/setuptools/blob/main/setuptools/version.py#L1
Alt Solution 1: importlib_metadata
Apparently pkg_resources is being deprecated in favor of importlib_metadata, but importlib_metadata is only a built-in for python >=3.8, otherwise you need to add the backport as an install requires for setup.py/cfg. It seems like astroML is definitely supporting python<3.8, so I went for the solution that didn't add an extra dependency. Perhaps in the future when the support for python is only >=3.8, could use importlib_metadata?
Alt Solution 2: setuptools_scm
Switch to setuptools_scm to grab the version from the git tag. More complicated, but the version number wouldn't need to be hardcoded anywhere except the git tags(?). Wouldn't need to update the setup.cfg with a ".dev" in the version either; it should auto-generate the .dev after any commits that aren't tagged. I think this would ensure that the number generated after .dev would be the same across all methods of checking the version number.
This would mean adding setuptools_scm to setup_requires for setup.py (setup.py & setup.cfg usage are both deprecated in favor of pyproject.toml).
Nice, quick overview: https://www.moritzkoerber.com/posts/versioning-with-setuptools_scm/ & https://github.com/pypa/setuptools_scm