-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup.py
executable file
·114 lines (90 loc) · 3.17 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
#!/usr/bin/env python
"""
callee
======
{description}
"""
import ast
import os
from setuptools import find_packages, setup
import sys
# Utility functions
def read_tags(filename):
"""Reads values of "magic tags" defined in the given Python file.
:param filename: Python filename to read the tags from
:return: Dictionary of tags
"""
with open(filename) as f:
ast_tree = ast.parse(f.read(), filename)
res = {}
for node in ast.walk(ast_tree):
if type(node) is not ast.Assign:
continue
target = node.targets[0]
if type(target) is not ast.Name:
continue
if not (target.id.startswith('__') and target.id.endswith('__')):
continue
name = target.id[2:-2]
res[name] = ast.literal_eval(node.value)
return res
def read_requirements(filename='requirements.txt'):
"""Reads the list of requirements from given file.
:param filename: Filename to read the requirements from.
Uses ``'requirements.txt'`` by default.
:return: Requirements as list of strings
"""
# allow for some leeway with the argument
if not filename.startswith('requirements'):
filename = 'requirements-' + filename
if not os.path.splitext(filename)[1]:
filename += '.txt' # no extension, add default
def valid_line(line):
line = line.strip()
return line and not any(line.startswith(p) for p in ('#', '-'))
def extract_requirement(line):
egg_eq = '#egg='
if egg_eq in line:
_, requirement = line.split(egg_eq, 1)
return requirement
return line
with open(filename) as f:
lines = f.readlines()
return list(map(extract_requirement, filter(valid_line, lines)))
# setup() call
tags = read_tags(os.path.join('callee', '__init__.py'))
__doc__ = __doc__.format(**tags)
tests_require = read_requirements('test')
if sys.version_info < (2, 7):
tests_require.extend(read_requirements('test-py26'))
if sys.version_info < (3, 3):
tests_require.extend(read_requirements('test-py32'))
setup(
name="callee",
version=tags['version'],
description=tags['description'],
long_description=__doc__,
author=tags['author'],
url="https://github.com/Xion/callee",
license=tags['license'],
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"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",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Testing",
],
platforms='any',
packages=find_packages(exclude=['tests']),
tests_require=tests_require,
)