Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/setuptools/command/sdist.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 from glob import glob | |
2 from distutils import log | |
3 import distutils.command.sdist as orig | |
4 import os | |
5 import sys | |
6 | |
7 from setuptools.compat import PY3 | |
8 from setuptools.utils import cs_path_exists | |
9 | |
10 import pkg_resources | |
11 | |
12 READMES = 'README', 'README.rst', 'README.txt' | |
13 | |
14 _default_revctrl = list | |
15 | |
16 def walk_revctrl(dirname=''): | |
17 """Find all files under revision control""" | |
18 for ep in pkg_resources.iter_entry_points('setuptools.file_finders'): | |
19 for item in ep.load()(dirname): | |
20 yield item | |
21 | |
22 | |
23 class sdist(orig.sdist): | |
24 """Smart sdist that finds anything supported by revision control""" | |
25 | |
26 user_options = [ | |
27 ('formats=', None, | |
28 "formats for source distribution (comma-separated list)"), | |
29 ('keep-temp', 'k', | |
30 "keep the distribution tree around after creating " + | |
31 "archive file(s)"), | |
32 ('dist-dir=', 'd', | |
33 "directory to put the source distribution archive(s) in " | |
34 "[default: dist]"), | |
35 ] | |
36 | |
37 negative_opt = {} | |
38 | |
39 def run(self): | |
40 self.run_command('egg_info') | |
41 ei_cmd = self.get_finalized_command('egg_info') | |
42 self.filelist = ei_cmd.filelist | |
43 self.filelist.append(os.path.join(ei_cmd.egg_info, 'SOURCES.txt')) | |
44 self.check_readme() | |
45 | |
46 # Run sub commands | |
47 for cmd_name in self.get_sub_commands(): | |
48 self.run_command(cmd_name) | |
49 | |
50 # Call check_metadata only if no 'check' command | |
51 # (distutils <= 2.6) | |
52 import distutils.command | |
53 | |
54 if 'check' not in distutils.command.__all__: | |
55 self.check_metadata() | |
56 | |
57 self.make_distribution() | |
58 | |
59 dist_files = getattr(self.distribution, 'dist_files', []) | |
60 for file in self.archive_files: | |
61 data = ('sdist', '', file) | |
62 if data not in dist_files: | |
63 dist_files.append(data) | |
64 | |
65 def __read_template_hack(self): | |
66 # This grody hack closes the template file (MANIFEST.in) if an | |
67 # exception occurs during read_template. | |
68 # Doing so prevents an error when easy_install attempts to delete the | |
69 # file. | |
70 try: | |
71 orig.sdist.read_template(self) | |
72 except: | |
73 _, _, tb = sys.exc_info() | |
74 tb.tb_next.tb_frame.f_locals['template'].close() | |
75 raise | |
76 | |
77 # Beginning with Python 2.7.2, 3.1.4, and 3.2.1, this leaky file handle | |
78 # has been fixed, so only override the method if we're using an earlier | |
79 # Python. | |
80 has_leaky_handle = ( | |
81 sys.version_info < (2, 7, 2) | |
82 or (3, 0) <= sys.version_info < (3, 1, 4) | |
83 or (3, 2) <= sys.version_info < (3, 2, 1) | |
84 ) | |
85 if has_leaky_handle: | |
86 read_template = __read_template_hack | |
87 | |
88 def add_defaults(self): | |
89 standards = [READMES, | |
90 self.distribution.script_name] | |
91 for fn in standards: | |
92 if isinstance(fn, tuple): | |
93 alts = fn | |
94 got_it = 0 | |
95 for fn in alts: | |
96 if cs_path_exists(fn): | |
97 got_it = 1 | |
98 self.filelist.append(fn) | |
99 break | |
100 | |
101 if not got_it: | |
102 self.warn("standard file not found: should have one of " + | |
103 ', '.join(alts)) | |
104 else: | |
105 if cs_path_exists(fn): | |
106 self.filelist.append(fn) | |
107 else: | |
108 self.warn("standard file '%s' not found" % fn) | |
109 | |
110 optional = ['test/test*.py', 'setup.cfg'] | |
111 for pattern in optional: | |
112 files = list(filter(cs_path_exists, glob(pattern))) | |
113 if files: | |
114 self.filelist.extend(files) | |
115 | |
116 # getting python files | |
117 if self.distribution.has_pure_modules(): | |
118 build_py = self.get_finalized_command('build_py') | |
119 self.filelist.extend(build_py.get_source_files()) | |
120 # This functionality is incompatible with include_package_data, and | |
121 # will in fact create an infinite recursion if include_package_data | |
122 # is True. Use of include_package_data will imply that | |
123 # distutils-style automatic handling of package_data is disabled | |
124 if not self.distribution.include_package_data: | |
125 for _, src_dir, _, filenames in build_py.data_files: | |
126 self.filelist.extend([os.path.join(src_dir, filename) | |
127 for filename in filenames]) | |
128 | |
129 if self.distribution.has_ext_modules(): | |
130 build_ext = self.get_finalized_command('build_ext') | |
131 self.filelist.extend(build_ext.get_source_files()) | |
132 | |
133 if self.distribution.has_c_libraries(): | |
134 build_clib = self.get_finalized_command('build_clib') | |
135 self.filelist.extend(build_clib.get_source_files()) | |
136 | |
137 if self.distribution.has_scripts(): | |
138 build_scripts = self.get_finalized_command('build_scripts') | |
139 self.filelist.extend(build_scripts.get_source_files()) | |
140 | |
141 def check_readme(self): | |
142 for f in READMES: | |
143 if os.path.exists(f): | |
144 return | |
145 else: | |
146 self.warn( | |
147 "standard file not found: should have one of " + | |
148 ', '.join(READMES) | |
149 ) | |
150 | |
151 def make_release_tree(self, base_dir, files): | |
152 orig.sdist.make_release_tree(self, base_dir, files) | |
153 | |
154 # Save any egg_info command line options used to create this sdist | |
155 dest = os.path.join(base_dir, 'setup.cfg') | |
156 if hasattr(os, 'link') and os.path.exists(dest): | |
157 # unlink and re-copy, since it might be hard-linked, and | |
158 # we don't want to change the source version | |
159 os.unlink(dest) | |
160 self.copy_file('setup.cfg', dest) | |
161 | |
162 self.get_finalized_command('egg_info').save_version_info(dest) | |
163 | |
164 def _manifest_is_not_generated(self): | |
165 # check for special comment used in 2.7.1 and higher | |
166 if not os.path.isfile(self.manifest): | |
167 return False | |
168 | |
169 fp = open(self.manifest, 'rbU') | |
170 try: | |
171 first_line = fp.readline() | |
172 finally: | |
173 fp.close() | |
174 return (first_line != | |
175 '# file GENERATED by distutils, do NOT edit\n'.encode()) | |
176 | |
177 def read_manifest(self): | |
178 """Read the manifest file (named by 'self.manifest') and use it to | |
179 fill in 'self.filelist', the list of files to include in the source | |
180 distribution. | |
181 """ | |
182 log.info("reading manifest file '%s'", self.manifest) | |
183 manifest = open(self.manifest, 'rbU') | |
184 for line in manifest: | |
185 # The manifest must contain UTF-8. See #303. | |
186 if PY3: | |
187 try: | |
188 line = line.decode('UTF-8') | |
189 except UnicodeDecodeError: | |
190 log.warn("%r not UTF-8 decodable -- skipping" % line) | |
191 continue | |
192 # ignore comments and blank lines | |
193 line = line.strip() | |
194 if line.startswith('#') or not line: | |
195 continue | |
196 self.filelist.append(line) | |
197 manifest.close() |