forked from ariovistus/pyd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_manifest.py
executable file
·113 lines (94 loc) · 3.54 KB
/
build_manifest.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os, os.path
import itertools
import sys
import re
FORBIDDEN_EXTENSIONS = [
'.pyc', '.pyo', # Python bytecode
'.marks', # jEdit bookmark files
'.map', # Created automatically by the DMD compiler; needn't distribute.
'.swp', # Vim swap files
]
FORBIDDEN_DIRECTORIES = [
lambda d: d.lower() in ('.svn', 'cvs', 'build', 'dist', '.hg', '.git', '.tup'),
lambda d: d.startswith('__'),
]
INCLUDE_ONLY_IN_SOURCE_DISTRIBUTION = [
'build_manifest.py',
'setup.py',
]
def split_complete(path):
folders = []
while True:
path, p2 = os.path.split(path)
if p2 != '':
folders.append(p2)
else:
if path!='':
folders.append(path)
break
return list(reversed(folders))
def include_path(path):
pathsubs = split_complete(path)
assert pathsubs
filebase, ext = os.path.splitext(pathsubs[-1])
if pathsubs[0] == 'infrastructure':
if pathsubs == ['infrastructure','pyd','LICENSE']:
return True
if pathsubs == ['infrastructure','d','python_dll_def.def_template']:
return True
if pathsubs == ['infrastructure','d','so_ctor.c']:
return True
if pathsubs == ['infrastructure','python','python.d']:
return False
if ext.lower() == '.d':
return True
if pathsubs[0:2] == ['infrastructure','windows'] and \
re.match("python.._digitalmars\\.lib",pathsubs[-1]):
return True
return False
if len(pathsubs) == 1 and ext.lower() == '.py':
return True
if len(pathsubs) == 1 and pathsubs[0] == "version.txt":
return True
return False
def buildManifest(outputStream, isForSourceDist):
includedPaths, excludedPaths = listFiles(isForSourceDist)
for path in includedPaths:
# print >> outputStream, 'include "%s"' % convertPathToDistutilsStandard(path)
outputStream.write(convertPathToDistutilsStandard(path))
outputStream.write("\n")
def convertPathToDistutilsStandard(path):
return path.replace(os.sep, '/')
def listFiles(isForSourceDist):
curDirAndSep = os.curdir + os.sep
includedPaths = []
excludedPaths = []
for rootPath, dirs, files in os.walk(os.curdir):
if rootPath.startswith(os.curdir + os.sep):
rootPath = rootPath[len(os.curdir + os.sep):]
elif rootPath.startswith(os.curdir):
rootPath = rootPath[len(os.curdir):]
# The os.walk interface specifies that destructively modifying dirs
# will influence which subdirs are visited, so we determine which
# subdirs are forbidden and remove them from dirs.
for subDir in dirs[:]:
for filterFunc in FORBIDDEN_DIRECTORIES:
if filterFunc(subDir):
dirs.remove(subDir)
for f in sorted(files):
fPath = os.path.join(rootPath, f)
if os.path.splitext(f)[1].lower() in FORBIDDEN_EXTENSIONS:
excludedPaths.append(fPath)
else:
includedPaths.append(fPath)
if not isForSourceDist:
for path in INCLUDE_ONLY_IN_SOURCE_DISTRIBUTION:
if path in includedPaths:
includedPaths.remove(path)
excludedPaths.append(path)
excludedPaths.extend([path for path in includedPaths if not include_path(path)])
includedPaths = [path for path in includedPaths if include_path(path)]
return includedPaths, excludedPaths
if __name__ == '__main__':
import sys
buildManifest(sys.stdout, True)