diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3486a71 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel", + "setuptools_scm" +] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "_version.py" diff --git a/setup.py b/setup.py index a8db25d..5dbc9a4 100755 --- a/setup.py +++ b/setup.py @@ -1,26 +1,13 @@ #!/usr/bin/env python import os import sys -import re -from distutils.core import setup -from setuptools import find_packages +from setuptools import setup, find_namespace_packages def get_long_description(): path = os.path.join(os.path.dirname(__file__), 'README.md') with open(path) as f: return f.read() -def get_version(): - return open('src/ansiblecmdb/data/VERSION', 'r').read().strip() - -def get_data_files(path, strip='', prefix=''): - data_files = [] - for dirpath, dirnames, filenames in os.walk(path): - files = [os.path.join(dirpath, filename) for filename in filenames] - data_files.append( [prefix + dirpath[len(strip):], files] ) - return data_files - - if sys.argv[-1] == 'publish': os.system('python setup.py sdist upload') print('You should also add a git tag for this version:') @@ -30,7 +17,8 @@ def get_data_files(path, strip='', prefix=''): setup( name='ansible-cmdb', - version=get_version(), + use_scm_version=True, + setup_requires=['setuptools_scm'], license='GPLv3', description='Generate host overview from ansible fact gathering output', long_description=get_long_description(), @@ -40,19 +28,19 @@ def get_data_files(path, strip='', prefix=''): author_email='ferry.boender@electricmonk.nl', package_dir={'': 'src'}, - packages=find_packages('src'), + packages=find_namespace_packages('src'), + package_data={ + 'ansiblecmdb.data': ['*.*'], + 'ansiblecmdb.data.static.images': ['*.*'], + 'ansiblecmdb.data.static.js': ['*.*'], + 'ansiblecmdb.data.tpl': ['*.*'] + }, include_package_data=True, - data_files=\ - get_data_files( - 'src/ansiblecmdb/data', - strip='src', - prefix='lib' - ) + - [['lib/ansiblecmdb/', ['src/ansible-cmdb.py']]], zip_safe=False, install_requires=['mako', 'pyyaml', 'ushlex', 'jsonxs'], scripts=[ 'src/ansible-cmdb', + 'src/ansible-cmdb.py' ], classifiers=[ diff --git a/src/ansible-cmdb.py b/src/ansible-cmdb.py index c5bbb62..cce95a3 100644 --- a/src/ansible-cmdb.py +++ b/src/ansible-cmdb.py @@ -20,6 +20,11 @@ import ansiblecmdb import ansiblecmdb.util as util import ansiblecmdb.render as render +try: + from importlib.metadata import version +except ImportError: + # Backport for Python < 3.8 + from importlib_metadata import version # Verify Python version @@ -145,7 +150,7 @@ def parse_user_params(user_params): data_dir = get_data_dir() tpl_dir = os.path.join(data_dir, 'tpl') static_dir = os.path.join(data_dir, 'static') - version = open(os.path.join(data_dir, 'VERSION')).read().strip() + version = version("ansible-cmdb") parser = optparse.OptionParser(version="%prog v{0}".format(version)) parser.set_usage(os.path.basename(sys.argv[0]) + " [option] > output.html") diff --git a/src/ansiblecmdb/data/VERSION b/src/ansiblecmdb/data/VERSION deleted file mode 100644 index 79d94e6..0000000 --- a/src/ansiblecmdb/data/VERSION +++ /dev/null @@ -1 +0,0 @@ -MASTER