forked from debops/debops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·166 lines (150 loc) · 5.91 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
# Copyright (C) 2014-2019 Hartmut Goebel <[email protected]>
# Copyright (C) 2014-2020 Maciej Delmanowski <[email protected]>
# Copyright (C) 2016 Robin Schneider <[email protected]>
# Copyright (C) 2014-2020 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-or-later
# Installation in development mode:
# pip3 install --user --editable .
from setuptools import setup, find_packages
import subprocess
import glob
import os
import re
def find_files(directory, strip):
"""
Using glob patterns in ``package_data`` that matches a directory can
result in setuptools trying to install that directory as a file and
the installation to fail.
This function walks over the contents of *directory* and returns a list
of only filenames found. The filenames will be stripped of the *strip*
directory part to allow for location relative to the package.
"""
result = []
for root, dirs, files in os.walk(directory):
for filename in files:
if not filename.endswith('.pyc'):
filename = os.path.join(root, filename)
result.append(os.path.relpath(filename, strip))
return result
try:
import pypandoc
README = pypandoc.convert_file('README.md', 'rst')
except (IOError, ImportError):
print('Warning: The "pandoc" support is required to convert '
'the README.md to reStructuredText format')
README = open('README.md').read()
try:
unicode
except NameError:
# Required for Python 3.x
class unicode(object):
def __new__(cls, s):
if isinstance(s, str):
return s
return s and s.decode('utf-8') or None
# Retrieve the project version from 'git describe' command and store it in the
# __version__.py and VERSION files, needed for correct installation of the
# Python package
try:
with open(os.devnull, 'w') as devnull:
GIT_RELEASE = subprocess.check_output(
['git', 'describe'], stderr=devnull
).strip().lstrip(b'v').decode('utf-8').split('-')
if len(GIT_RELEASE) > 1:
RELEASE = (GIT_RELEASE[0] + '.dev' + GIT_RELEASE[1]
+ '+' + GIT_RELEASE[2])
else:
RELEASE = GIT_RELEASE[0]
except subprocess.CalledProcessError:
try:
RELEASE = open('VERSION').read().strip()
except Exception:
try:
with open('CHANGELOG.rst', 'r') as changelog:
for count, line in enumerate(changelog):
if re.search('^`debops v', line):
RELEASE = line.split()[1].rstrip('`_').lstrip('v')
break
except Exception:
RELEASE = '0.0.0'
with open('VERSION', 'w') as version_file:
version_file.write('{}\n'.format(RELEASE))
with open('src/debops/__version__.py', 'w') as version_file:
version_file.write('__version__ = "{}"\n'
.format(RELEASE))
MANPAGES_1 = []
MANPAGES_5 = []
if os.path.exists('docs/_build/man'):
for manpage in os.listdir('docs/_build/man'):
if os.path.isfile(os.path.join('docs/_build/man', manpage)):
if manpage.endswith('.1'):
MANPAGES_1.append(os.path.join('docs/_build/man', manpage))
elif manpage.endswith('.5'):
MANPAGES_5.append(os.path.join('docs/_build/man', manpage))
else:
print('Warning: manual pages not built')
setup(
install_requires=['distro', 'future', 'jinja2', 'pyyaml',
'pyxdg', 'toml', 'python-dotenv', 'gitpython'],
extras_require={
'ansible': ['ansible', 'netaddr', 'passlib',
'python-ldap', 'dnspython', 'pyopenssl']
},
package_dir={'': 'src'},
packages=find_packages('src', exclude=('tests', 'docs')),
data_files=[
('share/man/man1', MANPAGES_1),
('share/man/man5', MANPAGES_5),
],
package_data={
'debops':
find_files('src/debops/_data',
'src/debops')
},
include_package_data=True,
zip_safe=True,
entry_points={
'console_scripts': [
'debops = debops.__main__:main'
]
},
# metadata for upload to PyPI
name='debops',
version=unicode(RELEASE),
description='Your Debian-based data center in a box',
long_description=README,
author='DebOps Developers',
author_email='[email protected]',
url='https://debops.org/',
license="GPL-3.0-or-later",
license_files=glob.glob("LICENSES/*.txt"),
keywords="ansible debian sysadmin",
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, '
'!=3.3.*, !=3.4.*, <4',
download_url='https://github.com/debops/debops'
'/archive/v' + unicode(RELEASE) + '.tar.gz',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU General Public License v3 '
'or later (GPLv3+)',
'Natural Language :: English',
'Operating System :: POSIX',
'Programming Language :: Other Scripting Engines',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: System :: Installation/Setup',
'Topic :: System :: Systems Administration',
'Topic :: Utilities'
]
)