forked from ContinuumIO/pykit
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup_helpers.py
62 lines (49 loc) · 1.96 KB
/
setup_helpers.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
# -*- coding: utf-8 -*-
"""
Common funcitonality for setup.py scripts.
"""
from __future__ import print_function, division, absolute_import
import os
import sys
from fnmatch import fnmatchcase
from distutils.util import convert_path
#===------------------------------------------------------------------===
# Setup constants and arguments
#===------------------------------------------------------------------===
setup_args = {
'long_description': open('README.md').read(),
}
root = os.path.dirname(os.path.abspath(__file__))
#===------------------------------------------------------------------===
# Package finding
#===------------------------------------------------------------------===
def find_packages(where='.', exclude=()):
out = []
stack=[(convert_path(where), '')]
while stack:
where, prefix = stack.pop(0)
for name in os.listdir(where):
fn = os.path.join(where,name)
if ('.' not in name and os.path.isdir(fn) and
os.path.isfile(os.path.join(fn, '__init__.py'))
):
out.append(prefix+name)
stack.append((fn, prefix+name+'.'))
if sys.version_info[0] == 3:
exclude = exclude + ('*py2only*', )
for pat in list(exclude) + ['ez_setup', 'distribute_setup']:
out = [item for item in out if not fnmatchcase(item, pat)]
return out
#===------------------------------------------------------------------===
# 2to3
#===------------------------------------------------------------------===
def run_2to3(cmdclass):
import lib2to3.refactor
from distutils.command.build_py import build_py_2to3 as build_py
print("Installing 2to3 fixers")
# need to convert sources to Py3 on installation
# fixes = 'dict imports imports2 unicode ' \
# 'xrange itertools itertools_imports long types'.split()
# fixes = ['lib2to3.fixes.fix_' + fix for fix in fixes]
# build_py.fixer_names = fixes
cmdclass["build_py"] = build_py