root / env / lib / python2.7 / site-packages / distribute-0.6.19-py2.7.egg / setuptools / command / sdist.py @ 1a305335
History | View | Annotate | Download (7.01 KB)
1 |
from distutils.command.sdist import sdist as _sdist |
---|---|
2 |
from distutils.util import convert_path |
3 |
from distutils import log |
4 |
import os, re, sys, pkg_resources |
5 |
from glob import glob |
6 |
|
7 |
entities = [ |
8 |
("<","<"), (">", ">"), (""", '"'), ("'", "'"), |
9 |
("&", "&") |
10 |
] |
11 |
|
12 |
def unescape(data): |
13 |
for old,new in entities: |
14 |
data = data.replace(old,new) |
15 |
return data
|
16 |
|
17 |
def re_finder(pattern, postproc=None): |
18 |
def find(dirname, filename): |
19 |
f = open(filename,'rU') |
20 |
data = f.read() |
21 |
f.close() |
22 |
for match in pattern.finditer(data): |
23 |
path = match.group(1)
|
24 |
if postproc:
|
25 |
path = postproc(path) |
26 |
yield joinpath(dirname,path)
|
27 |
return find
|
28 |
|
29 |
def joinpath(prefix,suffix): |
30 |
if not prefix: |
31 |
return suffix
|
32 |
return os.path.join(prefix,suffix)
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
def walk_revctrl(dirname=''): |
44 |
"""Find all files under revision control"""
|
45 |
for ep in pkg_resources.iter_entry_points('setuptools.file_finders'): |
46 |
for item in ep.load()(dirname): |
47 |
yield item
|
48 |
|
49 |
def _default_revctrl(dirname=''): |
50 |
for path, finder in finders: |
51 |
path = joinpath(dirname,path) |
52 |
if os.path.isfile(path):
|
53 |
for path in finder(dirname,path): |
54 |
if os.path.isfile(path):
|
55 |
yield path
|
56 |
elif os.path.isdir(path):
|
57 |
for item in _default_revctrl(path): |
58 |
yield item
|
59 |
|
60 |
def externals_finder(dirname, filename): |
61 |
"""Find any 'svn:externals' directories"""
|
62 |
found = False
|
63 |
f = open(filename,'rt') |
64 |
for line in iter(f.readline, ''): # can't use direct iter! |
65 |
parts = line.split() |
66 |
if len(parts)==2: |
67 |
kind,length = parts |
68 |
data = f.read(int(length))
|
69 |
if kind=='K' and data=='svn:externals': |
70 |
found = True
|
71 |
elif kind=='V' and found: |
72 |
f.close() |
73 |
break
|
74 |
else:
|
75 |
f.close() |
76 |
return
|
77 |
|
78 |
for line in data.splitlines(): |
79 |
parts = line.split() |
80 |
if parts:
|
81 |
yield joinpath(dirname, parts[0]) |
82 |
|
83 |
|
84 |
entries_pattern = re.compile(r'name="([^"]+)"(?![^>]+deleted="true")', re.I)
|
85 |
|
86 |
def entries_finder(dirname, filename): |
87 |
f = open(filename,'rU') |
88 |
data = f.read() |
89 |
f.close() |
90 |
if data.startswith('10') or data.startswith('9') or data.startswith('8'): |
91 |
for record in map(str.splitlines, data.split('\n\x0c\n')[1:]): |
92 |
# subversion 1.6/1.5/1.4
|
93 |
if not record or len(record)>=6 and record[5]=="delete": |
94 |
continue # skip deleted |
95 |
yield joinpath(dirname, record[0]) |
96 |
elif data.startswith('<?xml'): |
97 |
for match in entries_pattern.finditer(data): |
98 |
yield joinpath(dirname,unescape(match.group(1))) |
99 |
else:
|
100 |
log.warn("unrecognized .svn/entries format in %s", dirname)
|
101 |
|
102 |
|
103 |
finders = [ |
104 |
(convert_path('CVS/Entries'),
|
105 |
re_finder(re.compile(r"^\w?/([^/]+)/", re.M))),
|
106 |
(convert_path('.svn/entries'), entries_finder),
|
107 |
(convert_path('.svn/dir-props'), externals_finder),
|
108 |
(convert_path('.svn/dir-prop-base'), externals_finder), # svn 1.4 |
109 |
] |
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
class sdist(_sdist): |
127 |
"""Smart sdist that finds anything supported by revision control"""
|
128 |
|
129 |
user_options = [ |
130 |
('formats=', None, |
131 |
"formats for source distribution (comma-separated list)"),
|
132 |
('keep-temp', 'k', |
133 |
"keep the distribution tree around after creating " +
|
134 |
"archive file(s)"),
|
135 |
('dist-dir=', 'd', |
136 |
"directory to put the source distribution archive(s) in "
|
137 |
"[default: dist]"),
|
138 |
] |
139 |
|
140 |
negative_opt = {} |
141 |
|
142 |
def run(self): |
143 |
self.run_command('egg_info') |
144 |
ei_cmd = self.get_finalized_command('egg_info') |
145 |
self.filelist = ei_cmd.filelist
|
146 |
self.filelist.append(os.path.join(ei_cmd.egg_info,'SOURCES.txt')) |
147 |
self.check_readme()
|
148 |
self.check_metadata()
|
149 |
self.make_distribution()
|
150 |
|
151 |
dist_files = getattr(self.distribution,'dist_files',[]) |
152 |
for file in self.archive_files: |
153 |
data = ('sdist', '', file) |
154 |
if data not in dist_files: |
155 |
dist_files.append(data) |
156 |
|
157 |
def add_defaults(self): |
158 |
standards = [('README', 'README.txt'), |
159 |
self.distribution.script_name]
|
160 |
for fn in standards: |
161 |
if isinstance(fn, tuple): |
162 |
alts = fn |
163 |
got_it = 0
|
164 |
for fn in alts: |
165 |
if os.path.exists(fn):
|
166 |
got_it = 1
|
167 |
self.filelist.append(fn)
|
168 |
break
|
169 |
|
170 |
if not got_it: |
171 |
self.warn("standard file not found: should have one of " + |
172 |
', '.join(alts))
|
173 |
else:
|
174 |
if os.path.exists(fn):
|
175 |
self.filelist.append(fn)
|
176 |
else:
|
177 |
self.warn("standard file '%s' not found" % fn) |
178 |
|
179 |
optional = ['test/test*.py', 'setup.cfg'] |
180 |
for pattern in optional: |
181 |
files = filter(os.path.isfile, glob(pattern))
|
182 |
if files:
|
183 |
self.filelist.extend(files)
|
184 |
|
185 |
# getting python files
|
186 |
if self.distribution.has_pure_modules(): |
187 |
build_py = self.get_finalized_command('build_py') |
188 |
self.filelist.extend(build_py.get_source_files())
|
189 |
|
190 |
if self.distribution.has_ext_modules(): |
191 |
build_ext = self.get_finalized_command('build_ext') |
192 |
self.filelist.extend(build_ext.get_source_files())
|
193 |
|
194 |
if self.distribution.has_c_libraries(): |
195 |
build_clib = self.get_finalized_command('build_clib') |
196 |
self.filelist.extend(build_clib.get_source_files())
|
197 |
|
198 |
if self.distribution.has_scripts(): |
199 |
build_scripts = self.get_finalized_command('build_scripts') |
200 |
self.filelist.extend(build_scripts.get_source_files())
|
201 |
|
202 |
def read_template(self): |
203 |
try:
|
204 |
_sdist.read_template(self)
|
205 |
except:
|
206 |
# grody hack to close the template file (MANIFEST.in)
|
207 |
# this prevents easy_install's attempt at deleting the file from
|
208 |
# dying and thus masking the real error
|
209 |
sys.exc_info()[2].tb_next.tb_frame.f_locals['template'].close() |
210 |
raise
|
211 |
|
212 |
def check_readme(self): |
213 |
alts = ("README", "README.txt") |
214 |
for f in alts: |
215 |
if os.path.exists(f):
|
216 |
return
|
217 |
else:
|
218 |
self.warn(
|
219 |
"standard file not found: should have one of " +', '.join(alts) |
220 |
) |
221 |
|
222 |
|
223 |
def make_release_tree(self, base_dir, files): |
224 |
_sdist.make_release_tree(self, base_dir, files)
|
225 |
|
226 |
# Save any egg_info command line options used to create this sdist
|
227 |
dest = os.path.join(base_dir, 'setup.cfg')
|
228 |
if hasattr(os,'link') and os.path.exists(dest): |
229 |
# unlink and re-copy, since it might be hard-linked, and
|
230 |
# we don't want to change the source version
|
231 |
os.unlink(dest) |
232 |
self.copy_file('setup.cfg', dest) |
233 |
|
234 |
self.get_finalized_command('egg_info').save_version_info(dest) |
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
#
|