Replace find_version logic with exec to fix package version
Remove all the importlib trickery and use exec instead, as it was essentially what this was doing anyway. Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
97b564fb85
commit
75c07a9974
1 changed files with 14 additions and 23 deletions
37
setup.py
37
setup.py
|
@ -10,8 +10,6 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from importlib.machinery import PathFinder
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
@ -19,32 +17,25 @@ except ImportError:
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
|
|
||||||
def find_version(load_path, name) -> Optional[str]:
|
|
||||||
"""Find module version"""
|
|
||||||
|
|
||||||
module = None
|
|
||||||
spec = PathFinder.find_spec(name, load_path)
|
|
||||||
try:
|
|
||||||
module = spec.loader.load_module(name)
|
|
||||||
except (AttributeError, ImportError, SyntaxError):
|
|
||||||
return None
|
|
||||||
if module is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
for key in dir(module):
|
|
||||||
if key != '__version__':
|
|
||||||
continue
|
|
||||||
return getattr(module, key)
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
MODULE_FILE_PATH = os.path.join(
|
MODULE_FILE_PATH = os.path.join(
|
||||||
os.path.dirname(os.path.abspath(__file__)),
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
'slixmpp_omemo',
|
'slixmpp_omemo', 'version.py'
|
||||||
)
|
)
|
||||||
|
|
||||||
VERSION = find_version(MODULE_FILE_PATH, 'version')
|
def get_version() -> str:
|
||||||
|
"""Returns version by looking at slixmpp_omemo/version.py"""
|
||||||
|
|
||||||
|
version = {}
|
||||||
|
with open(MODULE_FILE_PATH) as file:
|
||||||
|
exec(file.read(), version)
|
||||||
|
|
||||||
|
if '__version__' in version:
|
||||||
|
return version['__version__']
|
||||||
|
return 'missingno'
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION = ('Slixmpp OMEMO plugin')
|
DESCRIPTION = ('Slixmpp OMEMO plugin')
|
||||||
|
VERSION = get_version()
|
||||||
with open('README.rst', encoding='utf8') as readme:
|
with open('README.rst', encoding='utf8') as readme:
|
||||||
LONG_DESCRIPTION = readme.read()
|
LONG_DESCRIPTION = readme.read()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue