forked from pmacosta/peng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
175 lines (157 loc) · 5.02 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
167
168
169
170
171
172
173
174
175
# setup.py
# Copyright (c) 2013-2017 Pablo Acosta-Serafini
# See LICENSE for details
# pylint: disable=C0111,E1111,R0904,W0122,W0201,W0621
# Taken in large part from:
# http://www.jeffknupp.com/blog/2013/08/16/
# open-sourcing-a-python-project-the-right-way/
# With additional hints from:
# http://oddbird.net/set-your-code-free-preso/
# The function to get the version number from __init__.py is from:
# https://python-packaging-user-guide.readthedocs.org/
# en/latest/single_source_version/
# Standard library imports
from __future__ import print_function
import io
import glob
import os
import sys
# PyPI imports
from setuptools import setup
from setuptools.command.test import test as TestCommand
# Intra-package imports
from sbin.functions import (
SUPPORTED_VERS, get_pkg_data_files, load_requirements, python_version
)
###
# Supported interpreter check
###
PYTHON_VER = python_version('{0:0x}'.format(sys.hexversion & 0xFFFF0000)[:-4])
if PYTHON_VER not in SUPPORTED_VERS:
sys.exit(
'Supported interpreter versions: {0}'.format(', '.join(SUPPORTED_VERS))
)
###
# Functions
###
def get_short_desc(long_desc):
""" Get first sentence of first paragraph of long description """
found = False
olines = []
for line in [item.rstrip() for item in long_desc.split('\n')]:
if (found and (((not line) and (not olines))
or (line and olines))):
olines.append(line)
elif found and olines and (not line):
return (' '.join(olines).split('.')[0]).strip()
found = line == '.. [[[end]]]' if not found else found
def read(*filenames, **kwargs):
""" Read plain text file(s) """
encoding = kwargs.get('encoding', 'utf-8')
sep = kwargs.get('sep', '\n')
buf = []
for filename in filenames:
with io.open(filename, encoding=encoding) as fobj:
buf.append(fobj.read())
return sep.join(buf)
###
# Global variables
###
PKG_NAME = 'peng'
REPO = 'http://github.com/pmacosta/{pkg_name}/'.format(pkg_name=PKG_NAME)
AUTHOR = 'Pablo Acosta-Serafini'
AUTHOR_EMAIL = '[email protected]'
PKG_DIR = os.path.abspath(os.path.dirname(__file__))
LONG_DESCRIPTION = read(
os.path.join(PKG_DIR, 'README.rst'),
os.path.join(PKG_DIR, 'CHANGELOG.rst')
)
SHORT_DESC = get_short_desc(LONG_DESCRIPTION)
# Actual directory is os.join(sys.prefix, 'share', PKG_NAME)
SHARE_DIR = os.path.join('share', PKG_NAME)
INSTALL_REQUIRES = load_requirements(PKG_DIR, PYTHON_VER, 'source')
TESTING_REQUIRES = load_requirements(PKG_DIR, PYTHON_VER, 'testing')
try:
DATA_FILES = get_pkg_data_files(SHARE_DIR)
except IOError:
print('PKG_DIR: {0}'.format(PKG_DIR))
print('Contents:')
print(glob.glob(os.path.join(PKG_DIR, '*')))
print('PKG_DIR/data')
print('Contents:')
print(glob.glob(os.path.join(PKG_DIR, 'data', '*')))
raise
###
# Extract version (from coveragepy)
###
VERSION_PY = os.path.join(PKG_DIR, 'peng/version.py')
with open(VERSION_PY) as fobj:
__version__ = VERSION_INFO = ""
# Execute the code in version.py.
exec(compile(fobj.read(), VERSION_PY, 'exec'))
if VERSION_INFO[3] == 'alpha':
DEVSTAT = "3 - Alpha"
elif VERSION_INFO[3] in ['beta', 'candidate']:
DEVSTAT = "4 - Beta"
else:
assert VERSION_INFO[3] == 'final'
DEVSTAT = "5 - Production/Stable"
###
# Classes
###
class Tox(TestCommand):
user_options = [('tox-args=', 'a', 'Arguments to pass to tox')]
def initialize_options(self):
TestCommand.initialize_options(self)
self.tox_args = None
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
import shlex
import tox
args = self.tox_args
if args:
args = shlex.split(self.tox_args)
errno = tox.cmdline(args=args)
sys.exit(errno)
###
# Processing
###
# package_data is used only for binary packages, i.e.
# $ python setup.py bdist ...
# but NOT when building source packages, i.e.
# $ python setup.py sdist ...
setup(
name=PKG_NAME,
version=__version__,
url=REPO,
license='MIT',
author=AUTHOR,
tests_require=TESTING_REQUIRES,
install_requires=INSTALL_REQUIRES,
cmdclass={'tests':Tox},
author_email=AUTHOR_EMAIL,
description=SHORT_DESC,
long_description=LONG_DESCRIPTION,
packages=[PKG_NAME],
data_files=DATA_FILES,
zip_safe=False,
platforms='any',
classifiers=[
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Development Status :: '+DEVSTAT,
'Natural Language :: English',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Topic :: Software Development :: Libraries :: Python Modules'
],
)