-
Notifications
You must be signed in to change notification settings - Fork 1
/
setupUtilities.py
67 lines (62 loc) · 2.6 KB
/
setupUtilities.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
""" Utilities which are used in any setup"""
import os
import sys
def get_path_to_root(appendLocation=None):
"""
Work out the path to the root from where the script is being run. Allows for
calling setup.py env from sub directories and directories outside the main dir
"""
fullPath = os.path.dirname(os.path.abspath(os.path.join(os.getcwd(), sys.argv[0])))
if appendLocation:
return "%s/%s" % (fullPath, appendLocation)
return fullPath
def list_packages(packageDirs=None,
recurse=True,
ignoreThese=None,
pyFiles=False):
"""
Take a list of directories and return a list of all packages under those directories,
Skipping 'CVS', '.svn', 'svn', '.git', '', 'dtnrmagent.egg-info' files.
"""
if not packageDirs:
packageDirs = []
if not ignoreThese:
ignoreThese = set(['CVS', '.svn', 'svn', '.git', '', 'dtnrmagent.egg-info'])
else:
ignoreThese = set(ignoreThese)
packages = []
modules = []
# Skip the following files
for aDir in packageDirs:
if recurse:
# Recurse the sub-directories
for dirpath, dummyDirnames, dummyFilenames in os.walk('%s' % aDir, topdown=True):
pathelements = dirpath.split('/')
# If any part of pathelements is in the ignore_these set skip the path
if len(set(pathelements) & ignoreThese) == 0:
relPath = os.path.relpath(dirpath, get_path_to_root())
relPath = relPath.split('/')[2:]
if not pyFiles:
packages.append('.'.join(relPath))
else:
for fileName in dummyFilenames:
if fileName.startswith('__init__.') or \
fileName.endswith('.pyc') or \
not fileName.endswith('.py'):
#print('Ignoring %s' % fileName)
continue
relName = fileName.rsplit('.', 1)
modules.append("%s.%s" % ('.'.join(relPath), relName[0]))
else:
continue
#print('Ignoring %s' % dirpath)
else:
relPath = os.path.relpath(aDir, get_path_to_root())
relPath = relPath.split('/')[2:]
packages.append('.'.join(relPath))
if pyFiles:
return modules
return packages
def get_py_modules(modulesDirs):
""" Get py modules for setup.py """
return list_packages(modulesDirs, pyFiles=True)