egg_info.py 25 KB

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