-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupUtilities.py
87 lines (81 loc) · 3.4 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python
"""
Utilities which are used in any setup script
Copyright 2017 California Institute of Technology
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Title : t2Mon
Author : Justas Balcas
Email : justas.balcas (at) cern.ch
@Copyright : Copyright (C) 2016 California Institute of Technology
Date : 2017/09/26
"""
import os
import sys
import configparser
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)