Change in version.py

To deal with the case of previously installed version of msspec,
the order in which the version is checked has changed.
1- test if we can infer the version from the SCM
2- check if a VERSION file exists
3- take the version from the distribution
This commit is contained in:
Sylvain Tricot 2020-03-12 17:55:40 +01:00
parent 162ffa87bd
commit 3187a4cb32
1 changed files with 20 additions and 17 deletions

View File

@ -1,28 +1,31 @@
# coding: utf-8 # coding: utf-8
# vim: set et sw=4 ts=4 sts=4 nu ai cc=+0 fdm=indent mouse=a: # vim: set et sw=4 ts=4 sts=4 nu ai cc=+0 fdm=indent mouse=a:
from setuptools_scm import get_version
from pkg_resources import parse_version, DistributionNotFound, get_distribution from pkg_resources import parse_version, DistributionNotFound, get_distribution
from msspec.misc import LOGGER from msspec.misc import LOGGER
import os import os
# find the version number
# 1- Try to read it from the git info
# 2- If it fails, try to read it from the VERSION file
# 3- If it fails, try to read it from the distribution file
try: try:
# try to find the version from egg info file v = get_version(root='../../', relative_to=__file__, version_scheme="post-release")
__version__ = get_distribution(__name__.strip('.version')).version v = parse_version(v)
except DistributionNotFound: if v._version.post[-1] == 0:
# otherwise try to get it from the SCM __version__ = v.base_version
else:
__version__ = v.public
except (LookupError, ImportError):
try: try:
from setuptools_scm import get_version f = os.path.join(os.path.dirname(__file__), "../VERSION")
v = get_version(root='../../', relative_to=__file__, version_scheme="post-release") with open(f, "r") as fd:
v = parse_version(v) __version__ = fd.read().strip('\n ')
if v._version.post[-1] == 0: except:
__version__ = v.base_version
else:
__version__ = v.public
except (LookupError, ModuleNotFoundError):
# Ok, so there may be a VERSION file to look for it
try: try:
f = os.path.join(os.path.dirname(__file__), "../VERSION") __version__ = get_distribution(__name__.strip('.version')).version
with open(f, "r") as fd: except DistributionNotFound:
__version__ = fd.read().strip('\n ')
except:
LOGGER.error("Unable to get the version number!") LOGGER.error("Unable to get the version number!")