egg_info.py 25 KB

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