-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
123 lines (112 loc) · 4.13 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
import sys, os, re, shutil, unittest, doctest
from setuptools import setup, find_packages
def my_test_suite():
test_loader = unittest.TestLoader()
test_suite = test_loader.discover('tests', pattern='test_*.py')
from athlib.wma import agegrader
test_suite.addTests(doctest.DocTestSuite(agegrader))
from athlib import utils
test_suite.addTests(doctest.DocTestSuite(utils))
from athlib import codes
test_suite.addTests(doctest.DocTestSuite(codes))
r = unittest.TextTestRunner().run(test_suite)
sys.exit(len(r.errors)+len(r.failures))
def get_version():
if os.path.isdir('docs'):
NS = {}
version_re = re.compile(r'^version\s*=.*$',re.M)
with open(os.path.join('docs','source','conf.py'),'r') as f:
txt = f.read()
m = version_re.search(txt)
if not m:
raise ValueError('Cannot find version in docs/source/conf.py')
sv = m.group()
exec(m.group(),NS)
docs_version = NS['version']
else:
docs_version = 'unknown'
if os.path.isdir('athlib'):
NS = {}
version_re = re.compile(r'^__version__\s*=.*$',re.M)
with open(os.path.join('athlib','__init__.py'),'r') as f:
txt = f.read()
m = version_re.search(txt)
if not m:
raise ValueError('Cannot find version in athlib/__init__.py')
sv = m.group()
exec(m.group(), NS)
athlib_version = NS['__version__']
if docs_version!='unknown' and athlib_version!=docs_version:
i0 = m.start()
i1 = m.end()
txt = txt[:i0]+('__version__ = %r' % docs_version)+txt[i1:]
with open(os.path.join('athlib','__init__.py'),'wb') as f:
f.write(txt)
else:
docs_version = athlib_version
return docs_version
def find_json(top,drop=1,force=False):
for p,D,F in os.walk(top):
for f in F:
fn = os.path.join(p,f)
if '__pycache__' in fn:
continue
print("scanning", fn)
with open(fn,'r') as j:
json = j.read()
if force or schema_marker_re.search(json):
if drop:
fn = os.sep.join(fn.split(os.sep)[drop:])
yield fn
here = os.getcwd()
base = os.path.dirname(os.path.abspath(__file__))
schema_marker_re = re.compile(r'''(?P<q>["'])\$schema(?P=q)\s*:''',re.M)
os.chdir(base)
jschdir = os.path.join('athlib','json-schemas')
if 'test' in sys.argv:
my_test_suite()
try:
if 'sdist' in sys.argv:
if os.path.isdir(jschdir):
shutil.rmtree(jschdir)
shutil.copytree('json',jschdir)
shutil.copyfile('README.md','README.rst')
setup(
name="athlib",
version=get_version(),
packages=find_packages(),
package_data={'athlib':(list(find_json(os.path.join('athlib','json-schemas')))
+list(find_json(os.path.join('athlib','wma'),force=True)))},
#test_suite="setup.my_test_suite",
# metadata for upload to PyPI
author="Andy Robinson and others",
author_email="[email protected]",
description="Utilities for track and field athletics",
license="Apache",
keywords="athletics track field",
url="https://github.com/openath/athlib", # project home page, if any
install_requires=[
'jsonschema>=2.6.0',
'python-dateutil',
],
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Topic :: Utilities',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
python_requires='>=2.7',
)
finally:
if os.path.isdir(jschdir):
shutil.rmtree(jschdir)
try:
os.remove('README.rst')
except:
pass
os.chdir(here)