-
Notifications
You must be signed in to change notification settings - Fork 56
/
setup.py
executable file
·162 lines (123 loc) · 4.6 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
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
from setuptools.command.install_scripts import install_scripts
from setuptools.command.install import install as _install
import os, platform, sys
BAT_TEMPLATE = \
r"""@echo off
REM wrapper to use shebang first line of {FNAME}
set mypath=%~dp0
set pyscript="%mypath%{FNAME}"
set /p line1=<%pyscript%
if "%line1:~0,2%" == "#!" (goto :goodstart)
echo First line of %pyscript% does not start with "#!"
exit /b 1
:goodstart
set py_exe=%line1:~2%
call "%py_exe%" %pyscript% %*
"""
NO_PYTHON_ERROR = """
WARNING: No #!python executable found in %s, skipping .bat wrapper'"""
printer = print # noqa: T001
SCRIPTS_TO_INSTALL = 'bp', 'bibliopixel', 'bp-color', 'bp-pid'
class InstallScripts(install_scripts):
def run(self):
install_scripts.run(self)
if not os.name == 'nt':
return
for filepath in self.get_outputs():
# If we can find an executable name in the #! top line of the script
# file, make .bat wrapper for script.
with open(filepath, 'rt') as fobj:
first_line = fobj.readline().lower()
if not (first_line.startswith('#!') and 'python' in first_line):
printer(NO_PYTHON_ERROR % filepath)
continue
path, fname = os.path.split(filepath)
froot, ext = os.path.splitext(fname)
bat_file = os.path.join(path, froot + '.bat')
bat_contents = BAT_TEMPLATE.replace('{FNAME}', fname)
printer('Making %s wrapper for %s' % (bat_file, filepath))
if self.dry_run:
continue
with open(bat_file, 'wt') as fobj:
fobj.write(bat_contents)
# From here: http://pytest.org/2.2.4/goodpractises.html
class RunTests(TestCommand):
DIRECTORY = 'test'
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = [self.DIRECTORY]
self.test_suite = True
def run_tests(self):
# Import here, because outside the eggs aren't loaded.
import pytest
errno = pytest.main(self.test_args)
if errno:
raise SystemExit(errno)
class RunBenchmark(RunTests):
DIRECTORY = 'benchmark'
class RunCoverage(RunTests):
def run_tests(self):
import coverage
cov = coverage.Coverage(config_file=True)
cov.start()
super().run_tests()
cov.stop()
cov.report(file=sys.stdout)
coverage = cov.html_report(directory='htmlcov')
fail_under = cov.get_option('report:fail_under')
if coverage < fail_under:
printer('ERROR: coverage %.2f%% was less than fail_under=%s%%' % (
coverage, fail_under))
raise SystemExit(1)
def _get_version():
from os.path import abspath, dirname, join
filename = join(dirname(abspath(__file__)), 'bibliopixel', 'VERSION')
return open(filename).read().strip()
INSTALLATION_ERROR = """INSTALLATION ERROR!
BiblioPixel v3 requires Python 3.4+ but
you are using version {0.major}.{0.minor}.{0.micro}
If you absolutely require using Python 2,
please install BiblioPixel v2.x using:
> pip install "bibliopixel<3.0"
However we highly recommend using the latest BiblioPixel
(v3+) with Python 3.4+.
"""
if sys.version_info.major != 3:
printer(INSTALLATION_ERROR.format(sys.version_info))
sys.exit(1)
VERSION = _get_version()
with open('requirements.txt') as f:
REQUIRED = f.read().splitlines()
setup(
name='BiblioPixel',
version=VERSION,
description=(
'BiblioPixel is a pure python library for manipulating a wide variety '
'of LED strip based displays, both in strip and matrix form.'),
long_description=open('README.rst').read(),
author='Adam Haile',
author_email='adam@maniacallabs.com',
url='http://github.com/maniacallabs/bibliopixel/',
license='MIT',
packages=find_packages(exclude=['test']) + ['ui', 'scripts'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
tests_require=['pytest'],
cmdclass={
'benchmark': RunBenchmark,
'coverage': RunCoverage,
'test': RunTests,
'install_scripts': InstallScripts
},
include_package_data=True,
scripts=['scripts/to_install/' + s for s in SCRIPTS_TO_INSTALL],
install_requires=REQUIRED
)