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