egg_info.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. """setuptools.command.egg_info
  2. Create a distribution's .egg-info directory and contents"""
  3. from distutils.filelist import FileList as _FileList
  4. from distutils.errors import DistutilsInternalError
  5. from distutils.util import convert_path
  6. from distutils import log
  7. import distutils.errors
  8. import distutils.filelist
  9. import os
  10. import re
  11. import sys
  12. import io
  13. import warnings
  14. import time
  15. import collections
  16. from setuptools.extern import six
  17. from setuptools.extern.six.moves import map
  18. from setuptools import Command
  19. from setuptools.command.sdist import sdist
  20. from setuptools.command.sdist import walk_revctrl
  21. from setuptools.command.setopt import edit_config
  22. from setuptools.command import bdist_egg
  23. from pkg_resources import (
  24. parse_requirements, safe_name, parse_version,
  25. safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename)
  26. import setuptools.unicode_utils as unicode_utils
  27. from setuptools.glob import glob
  28. from setuptools.extern import packaging
  29. def translate_pattern(glob):
  30. """
  31. Translate a file path glob like '*.txt' in to a regular expression.
  32. This differs from fnmatch.translate which allows wildcards to match
  33. directory separators. It also knows about '**/' which matches any number of
  34. directories.
  35. """
  36. pat = ''
  37. # This will split on '/' within [character classes]. This is deliberate.
  38. chunks = glob.split(os.path.sep)
  39. sep = re.escape(os.sep)
  40. valid_char = '[^%s]' % (sep,)
  41. for c, chunk in enumerate(chunks):
  42. last_chunk = c == len(chunks) - 1
  43. # Chunks that are a literal ** are globstars. They match anything.
  44. if chunk == '**':
  45. if last_chunk:
  46. # Match anything if this is the last component
  47. pat += '.*'
  48. else:
  49. # Match '(name/)*'
  50. pat += '(?:%s+%s)*' % (valid_char, sep)
  51. continue # Break here as the whole path component has been handled
  52. # Find any special characters in the remainder
  53. i = 0
  54. chunk_len = len(chunk)
  55. while i < chunk_len:
  56. char = chunk[i]
  57. if char == '*':
  58. # Match any number of name characters
  59. pat += valid_char + '*'
  60. elif char == '?':
  61. # Match a name character
  62. pat += valid_char
  63. elif char == '[':
  64. # Character class
  65. inner_i = i + 1
  66. # Skip initial !/] chars
  67. if inner_i < chunk_len and chunk[inner_i] == '!':
  68. inner_i = inner_i + 1
  69. if inner_i < chunk_len and chunk[inner_i] == ']':
  70. inner_i = inner_i + 1
  71. # Loop till the closing ] is found
  72. while inner_i < chunk_len and chunk[inner_i] != ']':
  73. inner_i = inner_i + 1
  74. if inner_i >= chunk_len:
  75. # Got to the end of the string without finding a closing ]
  76. # Do not treat this as a matching group, but as a literal [
  77. pat += re.escape(char)
  78. else:
  79. # Grab the insides of the [brackets]
  80. inner = chunk[i + 1:inner_i]
  81. char_class = ''
  82. # Class negation
  83. if inner[0] == '!':
  84. char_class = '^'
  85. inner = inner[1:]
  86. char_class += re.escape(inner)
  87. pat += '[%s]' % (char_class,)
  88. # Skip to the end ]
  89. i = inner_i
  90. else:
  91. pat += re.escape(char)
  92. i += 1
  93. # Join each chunk with the dir separator
  94. if not last_chunk:
  95. pat += sep
  96. pat += r'\Z'
  97. return re.compile(pat, flags=re.MULTILINE|re.DOTALL)
  98. class egg_info(Command):
  99. description = "create a distribution's .egg-info directory"
  100. user_options = [
  101. ('egg-base=', 'e', "directory containing .egg-info directories"
  102. " (default: top of the source tree)"),
  103. ('tag-date', 'd', "Add date stamp (e.g. 20050528) to version number"),
  104. ('tag-build=', 'b', "Specify explicit tag to add to version number"),
  105. ('no-date', 'D', "Don't include date stamp [default]"),
  106. ]
  107. boolean_options = ['tag-date']
  108. negative_opt = {
  109. 'no-date': 'tag-date',
  110. }
  111. def initialize_options(self):
  112. self.egg_name = None
  113. self.egg_version = None
  114. self.egg_base = None
  115. self.egg_info = None
  116. self.tag_build = None
  117. self.tag_date = 0
  118. self.broken_egg_info = False
  119. self.vtags = None
  120. ####################################
  121. # allow the 'tag_svn_revision' to be detected and
  122. # set, supporting sdists built on older Setuptools.
  123. @property
  124. def tag_svn_revision(self):
  125. pass
  126. @tag_svn_revision.setter
  127. def tag_svn_revision(self, value):
  128. pass
  129. ####################################
  130. def save_version_info(self, filename):
  131. """
  132. Materialize the value of date into the
  133. build tag. Install build keys in a deterministic order
  134. to avoid arbitrary reordering on subsequent builds.
  135. """
  136. egg_info = collections.OrderedDict()
  137. # follow the order these keys would have been added
  138. # when PYTHONHASHSEED=0
  139. egg_info['tag_build'] = self.tags()
  140. egg_info['tag_date'] = 0
  141. edit_config(filename, dict(egg_info=egg_info))
  142. def finalize_options(self):
  143. self.egg_name = safe_name(self.distribution.get_name())
  144. self.vtags = self.tags()
  145. self.egg_version = self.tagged_version()
  146. parsed_version = parse_version(self.egg_version)
  147. try:
  148. is_version = isinstance(parsed_version, packaging.version.Version)
  149. spec = (
  150. "%s==%s" if is_version else "%s===%s"
  151. )
  152. list(
  153. parse_requirements(spec % (self.egg_name, self.egg_version))
  154. )
  155. except ValueError:
  156. raise distutils.errors.DistutilsOptionError(
  157. "Invalid distribution name or version syntax: %s-%s" %
  158. (self.egg_name, self.egg_version)
  159. )
  160. if self.egg_base is None:
  161. dirs = self.distribution.package_dir
  162. self.egg_base = (dirs or {}).get('', os.curdir)
  163. self.ensure_dirname('egg_base')
  164. self.egg_info = to_filename(self.egg_name) + '.egg-info'
  165. if self.egg_base != os.curdir:
  166. self.egg_info = os.path.join(self.egg_base, self.egg_info)
  167. if '-' in self.egg_name:
  168. self.check_broken_egg_info()
  169. # Set package version for the benefit of dumber commands
  170. # (e.g. sdist, bdist_wininst, etc.)
  171. #
  172. self.distribution.metadata.version = self.egg_version
  173. # If we bootstrapped around the lack of a PKG-INFO, as might be the
  174. # case in a fresh checkout, make sure that any special tags get added
  175. # to the version info
  176. #
  177. pd = self.distribution._patched_dist
  178. if pd is not None and pd.key == self.egg_name.lower():
  179. pd._version = self.egg_version
  180. pd._parsed_version = parse_version(self.egg_version)
  181. self.distribution._patched_dist = None
  182. def write_or_delete_file(self, what, filename, data, force=False):
  183. """Write `data` to `filename` or delete if empty
  184. If `data` is non-empty, this routine is the same as ``write_file()``.
  185. If `data` is empty but not ``None``, this is the same as calling
  186. ``delete_file(filename)`. If `data` is ``None``, then this is a no-op
  187. unless `filename` exists, in which case a warning is issued about the
  188. orphaned file (if `force` is false), or deleted (if `force` is true).
  189. """
  190. if data:
  191. self.write_file(what, filename, data)
  192. elif os.path.exists(filename):
  193. if data is None and not force:
  194. log.warn(
  195. "%s not set in setup(), but %s exists", what, filename
  196. )
  197. return
  198. else:
  199. self.delete_file(filename)
  200. def write_file(self, what, filename, data):
  201. """Write `data` to `filename` (if not a dry run) after announcing it
  202. `what` is used in a log message to identify what is being written
  203. to the file.
  204. """
  205. log.info("writing %s to %s", what, filename)
  206. if six.PY3:
  207. data = data.encode("utf-8")
  208. if not self.dry_run:
  209. f = open(filename, 'wb')
  210. f.write(data)
  211. f.close()
  212. def delete_file(self, filename):
  213. """Delete `filename` (if not a dry run) after announcing it"""
  214. log.info("deleting %s", filename)
  215. if not self.dry_run:
  216. os.unlink(filename)
  217. def tagged_version(self):
  218. version = self.distribution.get_version()
  219. # egg_info may be called more than once for a distribution,
  220. # in which case the version string already contains all tags.
  221. if self.vtags and version.endswith(self.vtags):
  222. return safe_version(version)
  223. return safe_version(version + self.vtags)
  224. def run(self):
  225. self.mkpath(self.egg_info)
  226. installer = self.distribution.fetch_build_egg
  227. for ep in iter_entry_points('egg_info.writers'):
  228. ep.require(installer=installer)
  229. writer = ep.resolve()
  230. writer(self, ep.name, os.path.join(self.egg_info, ep.name))
  231. # Get rid of native_libs.txt if it was put there by older bdist_egg
  232. nl = os.path.join(self.egg_info, "native_libs.txt")
  233. if os.path.exists(nl):
  234. self.delete_file(nl)
  235. self.find_sources()
  236. def tags(self):
  237. version = ''
  238. if self.tag_build:
  239. version += self.tag_build
  240. if self.tag_date:
  241. version += time.strftime("-%Y%m%d")
  242. return version
  243. def find_sources(self):
  244. """Generate SOURCES.txt manifest file"""
  245. manifest_filename = os.path.join(self.egg_info, "SOURCES.txt")
  246. mm = manifest_maker(self.distribution)
  247. mm.manifest = manifest_filename
  248. mm.run()
  249. self.filelist = mm.filelist
  250. def check_broken_egg_info(self):
  251. bei = self.egg_name + '.egg-info'
  252. if self.egg_base != os.curdir:
  253. bei = os.path.join(self.egg_base, bei)
  254. if os.path.exists(bei):
  255. log.warn(
  256. "-" * 78 + '\n'
  257. "Note: Your current .egg-info directory has a '-' in its name;"
  258. '\nthis will not work correctly with "setup.py develop".\n\n'
  259. 'Please rename %s to %s to correct this problem.\n' + '-' * 78,
  260. bei, self.egg_info
  261. )
  262. self.broken_egg_info = self.egg_info
  263. self.egg_info = bei # make it work for now
  264. class FileList(_FileList):
  265. # Implementations of the various MANIFEST.in commands
  266. def process_template_line(self, line):
  267. # Parse the line: split it up, make sure the right number of words
  268. # is there, and return the relevant words. 'action' is always
  269. # defined: it's the first word of the line. Which of the other
  270. # three are defined depends on the action; it'll be either
  271. # patterns, (dir and patterns), or (dir_pattern).
  272. (action, patterns, dir, dir_pattern) = self._parse_template_line(line)
  273. # OK, now we know that the action is valid and we have the
  274. # right number of words on the line for that action -- so we
  275. # can proceed with minimal error-checking.
  276. if action == 'include':
  277. self.debug_print("include " + ' '.join(patterns))
  278. for pattern in patterns:
  279. if not self.include(pattern):
  280. log.warn("warning: no files found matching '%s'", pattern)
  281. elif action == 'exclude':
  282. self.debug_print("exclude " + ' '.join(patterns))
  283. for pattern in patterns:
  284. if not self.exclude(pattern):
  285. log.warn(("warning: no previously-included files "
  286. "found matching '%s'"), pattern)
  287. elif action == 'global-include':
  288. self.debug_print("global-include " + ' '.join(patterns))
  289. for pattern in patterns:
  290. if not self.global_include(pattern):
  291. log.warn(("warning: no files found matching '%s' "
  292. "anywhere in distribution"), pattern)
  293. elif action == 'global-exclude':
  294. self.debug_print("global-exclude " + ' '.join(patterns))
  295. for pattern in patterns:
  296. if not self.global_exclude(pattern):
  297. log.warn(("warning: no previously-included files matching "
  298. "'%s' found anywhere in distribution"),
  299. pattern)
  300. elif action == 'recursive-include':
  301. self.debug_print("recursive-include %s %s" %
  302. (dir, ' '.join(patterns)))
  303. for pattern in patterns:
  304. if not self.recursive_include(dir, pattern):
  305. log.warn(("warning: no files found matching '%s' "
  306. "under directory '%s'"),
  307. pattern, dir)
  308. elif action == 'recursive-exclude':
  309. self.debug_print("recursive-exclude %s %s" %
  310. (dir, ' '.join(patterns)))
  311. for pattern in patterns:
  312. if not self.recursive_exclude(dir, pattern):
  313. log.warn(("warning: no previously-included files matching "
  314. "'%s' found under directory '%s'"),
  315. pattern, dir)
  316. elif action == 'graft':
  317. self.debug_print("graft " + dir_pattern)
  318. if not self.graft(dir_pattern):
  319. log.warn("warning: no directories found matching '%s'",
  320. dir_pattern)
  321. elif action == 'prune':
  322. self.debug_print("prune " + dir_pattern)
  323. if not self.prune(dir_pattern):
  324. log.warn(("no previously-included directories found "
  325. "matching '%s'"), dir_pattern)
  326. else:
  327. raise DistutilsInternalError(
  328. "this cannot happen: invalid action '%s'" % action)
  329. def _remove_files(self, predicate):
  330. """
  331. Remove all files from the file list that match the predicate.
  332. Return True if any matching files were removed
  333. """
  334. found = False
  335. for i in range(len(self.files) - 1, -1, -1):
  336. if predicate(self.files[i]):
  337. self.debug_print(" removing " + self.files[i])
  338. del self.files[i]
  339. found = True
  340. return found
  341. def include(self, pattern):
  342. """Include files that match 'pattern'."""
  343. found = [f for f in glob(pattern) if not os.path.isdir(f)]
  344. self.extend(found)
  345. return bool(found)
  346. def exclude(self, pattern):
  347. """Exclude files that match 'pattern'."""
  348. match = translate_pattern(pattern)
  349. return self._remove_files(match.match)
  350. def recursive_include(self, dir, pattern):
  351. """
  352. Include all files anywhere in 'dir/' that match the pattern.
  353. """
  354. full_pattern = os.path.join(dir, '**', pattern)
  355. found = [f for f in glob(full_pattern, recursive=True)
  356. if not os.path.isdir(f)]
  357. self.extend(found)
  358. return bool(found)
  359. def recursive_exclude(self, dir, pattern):
  360. """
  361. Exclude any file anywhere in 'dir/' that match the pattern.
  362. """
  363. match = translate_pattern(os.path.join(dir, '**', pattern))
  364. return self._remove_files(match.match)
  365. def graft(self, dir):
  366. """Include all files from 'dir/'."""
  367. found = [
  368. item
  369. for match_dir in glob(dir)
  370. for item in distutils.filelist.findall(match_dir)
  371. ]
  372. self.extend(found)
  373. return bool(found)
  374. def prune(self, dir):
  375. """Filter out files from 'dir/'."""
  376. match = translate_pattern(os.path.join(dir, '**'))
  377. return self._remove_files(match.match)
  378. def global_include(self, pattern):
  379. """
  380. Include all files anywhere in the current directory that match the
  381. pattern. This is very inefficient on large file trees.
  382. """
  383. if self.allfiles is None:
  384. self.findall()
  385. match = translate_pattern(os.path.join('**', pattern))
  386. found = [f for f in self.allfiles if match.match(f)]
  387. self.extend(found)
  388. return bool(found)
  389. def global_exclude(self, pattern):
  390. """
  391. Exclude all files anywhere that match the pattern.
  392. """
  393. match = translate_pattern(os.path.join('**', pattern))
  394. return self._remove_files(match.match)
  395. def append(self, item):
  396. if item.endswith('\r'): # Fix older sdists built on Windows
  397. item = item[:-1]
  398. path = convert_path(item)
  399. if self._safe_path(path):
  400. self.files.append(path)
  401. def extend(self, paths):
  402. self.files.extend(filter(self._safe_path, paths))
  403. def _repair(self):
  404. """
  405. Replace self.files with only safe paths
  406. Because some owners of FileList manipulate the underlying
  407. ``files`` attribute directly, this method must be called to
  408. repair those paths.
  409. """
  410. self.files = list(filter(self._safe_path, self.files))
  411. def _safe_path(self, path):
  412. enc_warn = "'%s' not %s encodable -- skipping"
  413. # To avoid accidental trans-codings errors, first to unicode
  414. u_path = unicode_utils.filesys_decode(path)
  415. if u_path is None:
  416. log.warn("'%s' in unexpected encoding -- skipping" % path)
  417. return False
  418. # Must ensure utf-8 encodability
  419. utf8_path = unicode_utils.try_encode(u_path, "utf-8")
  420. if utf8_path is None:
  421. log.warn(enc_warn, path, 'utf-8')
  422. return False
  423. try:
  424. # accept is either way checks out
  425. if os.path.exists(u_path) or os.path.exists(utf8_path):
  426. return True
  427. # this will catch any encode errors decoding u_path
  428. except UnicodeEncodeError:
  429. log.warn(enc_warn, path, sys.getfilesystemencoding())
  430. class manifest_maker(sdist):
  431. template = "MANIFEST.in"
  432. def initialize_options(self):
  433. self.use_defaults = 1
  434. self.prune = 1
  435. self.manifest_only = 1
  436. self.force_manifest = 1
  437. def finalize_options(self):
  438. pass
  439. def run(self):
  440. self.filelist = FileList()
  441. if not os.path.exists(self.manifest):
  442. self.write_manifest() # it must exist so it'll get in the list
  443. self.add_defaults()
  444. if os.path.exists(self.template):
  445. self.read_template()
  446. self.prune_file_list()
  447. self.filelist.sort()
  448. self.filelist.remove_duplicates()
  449. self.write_manifest()
  450. def _manifest_normalize(self, path):
  451. path = unicode_utils.filesys_decode(path)
  452. return path.replace(os.sep, '/')
  453. def write_manifest(self):
  454. """
  455. Write the file list in 'self.filelist' to the manifest file
  456. named by 'self.manifest'.
  457. """
  458. self.filelist._repair()
  459. # Now _repairs should encodability, but not unicode
  460. files = [self._manifest_normalize(f) for f in self.filelist.files]
  461. msg = "writing manifest file '%s'" % self.manifest
  462. self.execute(write_file, (self.manifest, files), msg)
  463. def warn(self, msg):
  464. if not self._should_suppress_warning(msg):
  465. sdist.warn(self, msg)
  466. @staticmethod
  467. def _should_suppress_warning(msg):
  468. """
  469. suppress missing-file warnings from sdist
  470. """
  471. return re.match(r"standard file .*not found", msg)
  472. def add_defaults(self):
  473. sdist.add_defaults(self)
  474. self.filelist.append(self.template)
  475. self.filelist.append(self.manifest)
  476. rcfiles = list(walk_revctrl())
  477. if rcfiles:
  478. self.filelist.extend(rcfiles)
  479. elif os.path.exists(self.manifest):
  480. self.read_manifest()
  481. ei_cmd = self.get_finalized_command('egg_info')
  482. self.filelist.graft(ei_cmd.egg_info)
  483. def prune_file_list(self):
  484. build = self.get_finalized_command('build')
  485. base_dir = self.distribution.get_fullname()
  486. self.filelist.prune(build.build_base)
  487. self.filelist.prune(base_dir)
  488. sep = re.escape(os.sep)
  489. self.filelist.exclude_pattern(r'(^|' + sep + r')(RCS|CVS|\.svn)' + sep,
  490. is_regex=1)
  491. def write_file(filename, contents):
  492. """Create a file with the specified name and write 'contents' (a
  493. sequence of strings without line terminators) to it.
  494. """
  495. contents = "\n".join(contents)
  496. # assuming the contents has been vetted for utf-8 encoding
  497. contents = contents.encode("utf-8")
  498. with open(filename, "wb") as f: # always write POSIX-style manifest
  499. f.write(contents)
  500. def write_pkg_info(cmd, basename, filename):
  501. log.info("writing %s", filename)
  502. if not cmd.dry_run:
  503. metadata = cmd.distribution.metadata
  504. metadata.version, oldver = cmd.egg_version, metadata.version
  505. metadata.name, oldname = cmd.egg_name, metadata.name
  506. try:
  507. # write unescaped data to PKG-INFO, so older pkg_resources
  508. # can still parse it
  509. metadata.write_pkg_info(cmd.egg_info)
  510. finally:
  511. metadata.name, metadata.version = oldname, oldver
  512. safe = getattr(cmd.distribution, 'zip_safe', None)
  513. bdist_egg.write_safety_flag(cmd.egg_info, safe)
  514. def warn_depends_obsolete(cmd, basename, filename):
  515. if os.path.exists(filename):
  516. log.warn(
  517. "WARNING: 'depends.txt' is not used by setuptools 0.6!\n"
  518. "Use the install_requires/extras_require setup() args instead."
  519. )
  520. def _write_requirements(stream, reqs):
  521. lines = yield_lines(reqs or ())
  522. append_cr = lambda line: line + '\n'
  523. lines = map(append_cr, lines)
  524. stream.writelines(lines)
  525. def write_requirements(cmd, basename, filename):
  526. dist = cmd.distribution
  527. data = six.StringIO()
  528. _write_requirements(data, dist.install_requires)
  529. extras_require = dist.extras_require or {}
  530. for extra in sorted(extras_require):
  531. data.write('\n[{extra}]\n'.format(**vars()))
  532. _write_requirements(data, extras_require[extra])
  533. cmd.write_or_delete_file("requirements", filename, data.getvalue())
  534. def write_setup_requirements(cmd, basename, filename):
  535. data = io.StringIO()
  536. _write_requirements(data, cmd.distribution.setup_requires)
  537. cmd.write_or_delete_file("setup-requirements", filename, data.getvalue())
  538. def write_toplevel_names(cmd, basename, filename):
  539. pkgs = dict.fromkeys(
  540. [
  541. k.split('.', 1)[0]
  542. for k in cmd.distribution.iter_distribution_names()
  543. ]
  544. )
  545. cmd.write_file("top-level names", filename, '\n'.join(sorted(pkgs)) + '\n')
  546. def overwrite_arg(cmd, basename, filename):
  547. write_arg(cmd, basename, filename, True)
  548. def write_arg(cmd, basename, filename, force=False):
  549. argname = os.path.splitext(basename)[0]
  550. value = getattr(cmd.distribution, argname, None)
  551. if value is not None:
  552. value = '\n'.join(value) + '\n'
  553. cmd.write_or_delete_file(argname, filename, value, force)
  554. def write_entries(cmd, basename, filename):
  555. ep = cmd.distribution.entry_points
  556. if isinstance(ep, six.string_types) or ep is None:
  557. data = ep
  558. elif ep is not None:
  559. data = []
  560. for section, contents in sorted(ep.items()):
  561. if not isinstance(contents, six.string_types):
  562. contents = EntryPoint.parse_group(section, contents)
  563. contents = '\n'.join(sorted(map(str, contents.values())))
  564. data.append('[%s]\n%s\n\n' % (section, contents))
  565. data = ''.join(data)
  566. cmd.write_or_delete_file('entry points', filename, data, True)
  567. def get_pkg_info_revision():
  568. """
  569. Get a -r### off of PKG-INFO Version in case this is an sdist of
  570. a subversion revision.
  571. """
  572. warnings.warn("get_pkg_info_revision is deprecated.", DeprecationWarning)
  573. if os.path.exists('PKG-INFO'):
  574. with io.open('PKG-INFO') as f:
  575. for line in f:
  576. match = re.match(r"Version:.*-r(\d+)\s*$", line)
  577. if match:
  578. return int(match.group(1))
  579. return 0