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

refactor setup.py and add pyproject.toml for PEP 517/518 support. #255

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"setuptools_scm"
]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "_version.py"
34 changes: 11 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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:')
Expand All @@ -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(),
Expand All @@ -40,19 +28,19 @@ def get_data_files(path, strip='', prefix=''):
author_email='[email protected]',

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=[
Expand Down
7 changes: 6 additions & 1 deletion src/ansible-cmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] <dir> > output.html")
Expand Down
1 change: 0 additions & 1 deletion src/ansiblecmdb/data/VERSION

This file was deleted.