forked from what-studio/profiling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
108 lines (89 loc) · 3.14 KB
/
Copy pathsetup.py
File metadata and controls
108 lines (89 loc) · 3.14 KB
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
# -*- coding: utf-8 -*-
"""
profiling
~~~~~~~~~
An interactive profilier.
"""
from __future__ import with_statement
import os
import sys
from textwrap import dedent
from setuptools import find_packages, setup
from setuptools.command.install import install
from setuptools.command.test import test
from setuptools.extension import Extension
try:
import __pypy__
except ImportError:
__pypy__ = False
# include __about__.py.
__dir__ = os.path.dirname(__file__)
about = {}
with open(os.path.join(__dir__, 'profiling', '__about__.py')) as f:
exec(f.read(), about)
# these files require specific python version or later. they will be replaced
# with a placeholder which raises a runtime error on installation.
PYTHON_VERSION_REQUIREMENTS = {
'profiling/remote/asyncio.py': (3, 4),
}
INCOMPATIBLE_PYTHON_VERSION_PLACEHOLDER = dedent('''
# -*- coding: utf-8 -*-
raise RuntimeError('Python {version} or later required.')
''').strip()
def requirements(filename):
"""Reads requirements from a file."""
with open(filename) as f:
return [x.strip() for x in f.readlines() if x.strip()]
# use pytest instead.
def run_tests(self):
raise SystemExit(__import__('pytest').main(['-v']))
test.run_tests = run_tests
# replace files which are incompatible with the current python version.
def replace_incompatible_files():
for filename, version_info in PYTHON_VERSION_REQUIREMENTS.items():
if sys.version_info >= version_info:
continue
version = '.'.join(str(v) for v in version_info)
code = INCOMPATIBLE_PYTHON_VERSION_PLACEHOLDER.format(version=version)
with open(filename, 'w') as f:
f.write(code)
run_install = install.run
install.run = lambda x: (replace_incompatible_files(), run_install(x))
# build profiling.speedup on cpython.
if __pypy__:
ext_modules = []
else:
ext_modules = [Extension('profiling.speedup', ['profiling/speedup.c'])]
setup(
name='profiling',
version=about['__version__'],
license=about['__license__'],
author=about['__author__'],
maintainer=about['__maintainer__'],
maintainer_email=about['__maintainer_email__'],
platforms='linux',
packages=find_packages(),
ext_modules=ext_modules,
entry_points={
'console_scripts': ['profiling = profiling.__main__:cli']
},
classifiers=[
'Development Status :: 1 - Planning',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Debuggers',
],
install_requires=requirements('requirements.txt'),
tests_require=requirements('test/requirements.txt'),
test_suite='...',
)