forked from gslab-econ/gslab_python
/
setup.py
87 lines (75 loc) · 3.01 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
import os
import re
import sys
import shutil
import site
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py
from setuptools.command.install import install
from glob import glob
# Determine if the user has specified which paths to report coverage for
is_include_arg = map(lambda x: bool(re.search('^--include=', x)),
sys.argv)
if True in is_include_arg:
include_arg = sys.argv[is_include_arg.index(True)]
include_arg = sys.argv[is_include_arg.index(True)]
del sys.argv[is_include_arg.index(True)]
else:
include_arg = None
# Uninstall old versions of GSLab-Tools
re_gslab = re.compile('gslab[-_].', re.IGNORECASE)
re_gencat = re.compile('gencat')
package_locations = site.getsitepackages()
for package_location in package_locations:
try:
packages = os.listdir(package_location)
except OSError:
continue
for package in packages:
if re_gslab.match(package) or re_gencat.match(package):
shutil.rmtree(os.path.join(package_location, package))
# Additional build commands
class TestRepo(build_py):
'''Build command for running tests in repo'''
def run(self):
if include_arg:
coverage_command = 'coverage report -m %s' % include_arg
else:
coverage_command = 'coverage report -m --omit=setup.py,*/__init__.py,.eggs/*'
if sys.platform != 'win32':
os.system("coverage run --branch --source ./ setup.py test1 2>&1 "
"| tee test.log")
# http://unix.stackexchange.com/questions/80707/
# how-to-output-text-to-both-screen-and-file-inside-a-shell-script
os.system("%s 2>&1 | tee -a test.log" % coverage_command)
else:
os.system("coverage run --branch --source ./ setup.py "
"> test.log")
os.system("%s >> test.log" % coverage_command)
sys.exit()
class CleanRepo(build_py):
'''Build command for clearing setup directories after installation'''
def run(self):
# i) Remove the .egg-info folder
egg_directories = glob('./*.egg-info')
map(shutil.rmtree, egg_directories)
# ii) Remove the ./build and ./dist directories
if os.path.isdir('./build'):
shutil.rmtree('./build')
if os.path.isdir('./dist'):
shutil.rmtree('./dist')
# Requirements
requirements = ['requests', 'scandir', 'mmh3']
setup(name = 'GSLab_Tools',
version = '4.1.0',
description = 'Python tools for GSLab',
url = 'https://github.com/gslab-econ/gslab_python',
author = 'Matthew Gentzkow, Jesse Shapiro',
author_email = 'gentzkow@stanford.edu, jesse_shapiro_1@brown.edu',
license = 'MIT',
packages = find_packages(),
install_requires = requirements,
zip_safe = False,
cmdclass = {'test': TestRepo, 'clean': CleanRepo},
setup_requires = ['pytest-runner', 'coverage'],
tests_require = ['pytest', 'coverage'])