This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
163 lines (137 loc) · 4.76 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
# -*- coding: utf-8 -*-
#
# (C) Copyright IBM, Paul D. Nation, 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""Marz
Measurement and reset simplification
"""
import os
import sys
import subprocess
import setuptools
MAJOR = 0
MINOR = 1
MICRO = 0
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
REQUIREMENTS = []
with open("requirements.txt") as f:
for line in f:
req = line.split('#')[0]
if req:
REQUIREMENTS.append(req)
PACKAGES = setuptools.find_namespace_packages()
PACKAGE_DATA = {
}
DOCLINES = __doc__.split('\n')
DESCRIPTION = DOCLINES[0]
LONG_DESCRIPTION = "\n".join(DOCLINES[2:])
def git_short_hash():
try:
git_str = "+" + os.popen('git log -1 --format="%h"').read().strip()
except: # pylint: disable=bare-except
git_str = ""
else:
if git_str == '+': #fixes setuptools PEP issues with versioning
git_str = ''
return git_str
FULLVERSION = VERSION
if not ISRELEASED:
FULLVERSION += '.dev'+str(MICRO)+git_short_hash()
def write_version_py(filename='marz/version.py'):
cnt = """\
# THIS FILE IS GENERATED FROM MARZ SETUP.PY
# pylint: disable=invalid-name, missing-module-docstring
short_version = '%(version)s'
version = '%(fullversion)s'
release = %(isrelease)s
"""
a = open(filename, 'w')
try:
a.write(cnt % {'version': VERSION, 'fullversion':
FULLVERSION, 'isrelease': str(ISRELEASED)})
finally:
a.close()
local_path = os.path.dirname(os.path.abspath(sys.argv[0]))
os.chdir(local_path)
sys.path.insert(0, local_path)
sys.path.insert(0, os.path.join(local_path, 'marz')) # to retrive _version
# always rewrite _version
if os.path.exists('marz/version.py'):
os.remove('marz/version.py')
write_version_py()
# Add command for running pylint from setup.py
class PylintCommand(setuptools.Command):
"""Run Pylint on all marz Python source files."""
description = 'Run Pylint on marz Python source files'
user_options = [
# The format is (long option, short option, description).
('pylint-rcfile=', None, 'path to Pylint config file')]
def initialize_options(self):
"""Set default values for options."""
# Each user option must be listed here with their default value.
self.pylint_rcfile = '' # pylint: disable=attribute-defined-outside-init
def finalize_options(self):
"""Post-process options."""
if self.pylint_rcfile:
assert os.path.exists(self.pylint_rcfile), (
'Pylint config file %s does not exist.' % self.pylint_rcfile)
def run(self):
"""Run command."""
command = ['pylint']
if self.pylint_rcfile:
command.append('--rcfile=%s' % self.pylint_rcfile)
command.append(os.getcwd()+"/marz")
subprocess.run(command, stderr=subprocess.STDOUT, check=False)
# Add command for running PEP8 tests from setup.py
class StyleCommand(setuptools.Command):
"""Run pep8 from setup."""
description = 'Run style from setup'
user_options = [
# The format is (long option, short option, description).
('abc', None, 'abc')]
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
"""Run command."""
command = 'pycodestyle --max-line-length=100 marz'
subprocess.run(command, shell=True, check=False, stderr=subprocess.STDOUT)
setuptools.setup(
name='marz',
version=VERSION,
packages=PACKAGES,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
url="",
author="Paul Nation",
author_email="[email protected]",
license="Apache 2.0",
classifiers=[
"Environment :: Web Environment",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering",
],
cmdclass={'lint': PylintCommand, 'style': StyleCommand},
install_requires=REQUIREMENTS,
package_data=PACKAGE_DATA,
include_package_data=True,
zip_safe=False
)