You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

656 lines
25 KiB

  1. #! /usr/bin/python
  2. """versioneer.py
  3. (like a rocketeer, but for versions)
  4. * https://github.com/warner/python-versioneer
  5. * Brian Warner
  6. * License: Public Domain
  7. * Version: 0.7+
  8. This file helps distutils-based projects manage their version number by just
  9. creating version-control tags.
  10. For developers who work from a VCS-generated tree (e.g. 'git clone' etc),
  11. each 'setup.py version', 'setup.py build', 'setup.py sdist' will compute a
  12. version number by asking your version-control tool about the current
  13. checkout. The version number will be written into a generated _version.py
  14. file of your choosing, where it can be included by your __init__.py
  15. For users who work from a VCS-generated tarball (e.g. 'git archive'), it will
  16. compute a version number by looking at the name of the directory created when
  17. te tarball is unpacked. This conventionally includes both the name of the
  18. project and a version number.
  19. For users who work from a tarball built by 'setup.py sdist', it will get a
  20. version number from a previously-generated _version.py file.
  21. As a result, loading code directly from the source tree will not result in a
  22. real version. If you want real versions from VCS trees (where you frequently
  23. update from the upstream repository, or do new development), you will need to
  24. do a 'setup.py version' after each update, and load code from the build/
  25. directory.
  26. You need to provide this code with a few configuration values:
  27. versionfile_source:
  28. A project-relative pathname into which the generated version strings
  29. should be written. This is usually a _version.py next to your project's
  30. main __init__.py file. If your project uses src/myproject/__init__.py,
  31. this should be 'src/myproject/_version.py'. This file should be checked
  32. in to your VCS as usual: the copy created below by 'setup.py
  33. update_files' will include code that parses expanded VCS keywords in
  34. generated tarballs. The 'build' and 'sdist' commands will replace it with
  35. a copy that has just the calculated version string.
  36. versionfile_build:
  37. Like versionfile_source, but relative to the build directory instead of
  38. the source directory. These will differ when your setup.py uses
  39. 'package_dir='. If you have package_dir={'myproject': 'src/myproject'},
  40. then you will probably have versionfile_build='myproject/_version.py' and
  41. versionfile_source='src/myproject/_version.py'.
  42. tag_prefix: a string, like 'PROJECTNAME-', which appears at the start of all
  43. VCS tags. If your tags look like 'myproject-1.2.0', then you
  44. should use tag_prefix='myproject-'. If you use unprefixed tags
  45. like '1.2.0', this should be an empty string.
  46. parentdir_prefix: a string, frequently the same as tag_prefix, which
  47. appears at the start of all unpacked tarball filenames. If
  48. your tarball unpacks into 'myproject-1.2.0', this should
  49. be 'myproject-'.
  50. To use it:
  51. 1: include this file in the top level of your project
  52. 2: make the following changes to the top of your setup.py:
  53. import versioneer
  54. versioneer.versionfile_source = 'src/myproject/_version.py'
  55. versioneer.versionfile_build = 'myproject/_version.py'
  56. versioneer.tag_prefix = '' # tags are like 1.2.0
  57. versioneer.parentdir_prefix = 'myproject-' # dirname like 'myproject-1.2.0'
  58. 3: add the following arguments to the setup() call in your setup.py:
  59. version=versioneer.get_version(),
  60. cmdclass=versioneer.get_cmdclass(),
  61. 4: run 'setup.py update_files', which will create _version.py, and will
  62. append the following to your __init__.py:
  63. from _version import __version__
  64. 5: modify your MANIFEST.in to include versioneer.py
  65. 6: add both versioneer.py and the generated _version.py to your VCS
  66. """
  67. import os, sys, re
  68. from distutils.core import Command
  69. from distutils.command.sdist import sdist as _sdist
  70. from distutils.command.build_py import build_py as _build_py
  71. versionfile_source = None
  72. versionfile_build = None
  73. tag_prefix = None
  74. parentdir_prefix = None
  75. VCS = "git"
  76. IN_LONG_VERSION_PY = False
  77. LONG_VERSION_PY = '''
  78. IN_LONG_VERSION_PY = True
  79. # This file helps to compute a version number in source trees obtained from
  80. # git-archive tarball (such as those provided by githubs download-from-tag
  81. # feature). Distribution tarballs (build by setup.py sdist) and build
  82. # directories (produced by setup.py build) will contain a much shorter file
  83. # that just contains the computed version number.
  84. # This file is released into the public domain. Generated by
  85. # versioneer-0.7+ (https://github.com/warner/python-versioneer)
  86. # these strings will be replaced by git during git-archive
  87. git_refnames = "%(DOLLAR)sFormat:%%d%(DOLLAR)s"
  88. git_full = "%(DOLLAR)sFormat:%%H%(DOLLAR)s"
  89. import subprocess
  90. import sys
  91. def run_command(args, cwd=None, verbose=False):
  92. try:
  93. # remember shell=False, so use git.cmd on windows, not just git
  94. p = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=cwd)
  95. except EnvironmentError:
  96. e = sys.exc_info()[1]
  97. if verbose:
  98. print("unable to run %%s" %% args[0])
  99. print(e)
  100. return None
  101. stdout = p.communicate()[0].strip()
  102. if sys.version >= '3':
  103. stdout = stdout.decode()
  104. if p.returncode != 0:
  105. if verbose:
  106. print("unable to run %%s (error)" %% args[0])
  107. return None
  108. return stdout
  109. import sys
  110. import re
  111. import os.path
  112. def get_expanded_variables(versionfile_source):
  113. # the code embedded in _version.py can just fetch the value of these
  114. # variables. When used from setup.py, we don't want to import
  115. # _version.py, so we do it with a regexp instead. This function is not
  116. # used from _version.py.
  117. variables = {}
  118. try:
  119. for line in open(versionfile_source,"r").readlines():
  120. if line.strip().startswith("git_refnames ="):
  121. mo = re.search(r'=\s*"(.*)"', line)
  122. if mo:
  123. variables["refnames"] = mo.group(1)
  124. if line.strip().startswith("git_full ="):
  125. mo = re.search(r'=\s*"(.*)"', line)
  126. if mo:
  127. variables["full"] = mo.group(1)
  128. except EnvironmentError:
  129. pass
  130. return variables
  131. def versions_from_expanded_variables(variables, tag_prefix, verbose=False):
  132. refnames = variables["refnames"].strip()
  133. if refnames.startswith("$Format"):
  134. if verbose:
  135. print("variables are unexpanded, not using")
  136. return {} # unexpanded, so not in an unpacked git-archive tarball
  137. refs = set([r.strip() for r in refnames.strip("()").split(",")])
  138. for ref in list(refs):
  139. if not re.search(r'\d', ref):
  140. if verbose:
  141. print("discarding '%%s', no digits" %% ref)
  142. refs.discard(ref)
  143. # Assume all version tags have a digit. git's %%d expansion
  144. # behaves like git log --decorate=short and strips out the
  145. # refs/heads/ and refs/tags/ prefixes that would let us
  146. # distinguish between branches and tags. By ignoring refnames
  147. # without digits, we filter out many common branch names like
  148. # "release" and "stabilization", as well as "HEAD" and "master".
  149. if verbose:
  150. print("remaining refs: %%s" %% ",".join(sorted(refs)))
  151. for ref in sorted(refs):
  152. # sorting will prefer e.g. "2.0" over "2.0rc1"
  153. if ref.startswith(tag_prefix):
  154. r = ref[len(tag_prefix):]
  155. if verbose:
  156. print("picking %%s" %% r)
  157. return { "version": r,
  158. "full": variables["full"].strip() }
  159. # no suitable tags, so we use the full revision id
  160. if verbose:
  161. print("no suitable tags, using full revision id")
  162. return { "version": variables["full"].strip(),
  163. "full": variables["full"].strip() }
  164. def versions_from_vcs(tag_prefix, versionfile_source, verbose=False):
  165. # this runs 'git' from the root of the source tree. That either means
  166. # someone ran a setup.py command (and this code is in versioneer.py, so
  167. # IN_LONG_VERSION_PY=False, thus the containing directory is the root of
  168. # the source tree), or someone ran a project-specific entry point (and
  169. # this code is in _version.py, so IN_LONG_VERSION_PY=True, thus the
  170. # containing directory is somewhere deeper in the source tree). This only
  171. # gets called if the git-archive 'subst' variables were *not* expanded,
  172. # and _version.py hasn't already been rewritten with a short version
  173. # string, meaning we're inside a checked out source tree.
  174. try:
  175. here = os.path.abspath(__file__)
  176. except NameError:
  177. # some py2exe/bbfreeze/non-CPython implementations don't do __file__
  178. return {} # not always correct
  179. # versionfile_source is the relative path from the top of the source tree
  180. # (where the .git directory might live) to this file. Invert this to find
  181. # the root from __file__.
  182. root = here
  183. if IN_LONG_VERSION_PY:
  184. for i in range(len(versionfile_source.split("/"))):
  185. root = os.path.dirname(root)
  186. else:
  187. root = os.path.dirname(here)
  188. if not os.path.exists(os.path.join(root, ".git")):
  189. if verbose:
  190. print("no .git in %%s" %% root)
  191. return {}
  192. GIT = "git"
  193. if sys.platform == "win32":
  194. GIT = "git.cmd"
  195. stdout = run_command([GIT, "describe", "--tags", "--dirty", "--always"],
  196. cwd=root)
  197. if stdout is None:
  198. return {}
  199. if not stdout.startswith(tag_prefix):
  200. if verbose:
  201. print("tag '%%s' doesn't start with prefix '%%s'" %% (stdout, tag_prefix))
  202. return {}
  203. tag = stdout[len(tag_prefix):]
  204. stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=root)
  205. if stdout is None:
  206. return {}
  207. full = stdout.strip()
  208. if tag.endswith("-dirty"):
  209. full += "-dirty"
  210. return {"version": tag, "full": full}
  211. def versions_from_parentdir(parentdir_prefix, versionfile_source, verbose=False):
  212. if IN_LONG_VERSION_PY:
  213. # We're running from _version.py. If it's from a source tree
  214. # (execute-in-place), we can work upwards to find the root of the
  215. # tree, and then check the parent directory for a version string. If
  216. # it's in an installed application, there's no hope.
  217. try:
  218. here = os.path.abspath(__file__)
  219. except NameError:
  220. # py2exe/bbfreeze/non-CPython don't have __file__
  221. return {} # without __file__, we have no hope
  222. # versionfile_source is the relative path from the top of the source
  223. # tree to _version.py. Invert this to find the root from __file__.
  224. root = here
  225. for i in range(len(versionfile_source.split("/"))):
  226. root = os.path.dirname(root)
  227. else:
  228. # we're running from versioneer.py, which means we're running from
  229. # the setup.py in a source tree. sys.argv[0] is setup.py in the root.
  230. here = os.path.abspath(sys.argv[0])
  231. root = os.path.dirname(here)
  232. # Source tarballs conventionally unpack into a directory that includes
  233. # both the project name and a version string.
  234. dirname = os.path.basename(root)
  235. if not dirname.startswith(parentdir_prefix):
  236. if verbose:
  237. print("guessing rootdir is '%%s', but '%%s' doesn't start with prefix '%%s'" %%
  238. (root, dirname, parentdir_prefix))
  239. return None
  240. return {"version": dirname[len(parentdir_prefix):], "full": ""}
  241. tag_prefix = "%(TAG_PREFIX)s"
  242. parentdir_prefix = "%(PARENTDIR_PREFIX)s"
  243. versionfile_source = "%(VERSIONFILE_SOURCE)s"
  244. def get_versions(default={"version": "unknown", "full": ""}, verbose=False):
  245. variables = { "refnames": git_refnames, "full": git_full }
  246. ver = versions_from_expanded_variables(variables, tag_prefix, verbose)
  247. if not ver:
  248. ver = versions_from_vcs(tag_prefix, versionfile_source, verbose)
  249. if not ver:
  250. ver = versions_from_parentdir(parentdir_prefix, versionfile_source,
  251. verbose)
  252. if not ver:
  253. ver = default
  254. return ver
  255. '''
  256. import subprocess
  257. import sys
  258. def run_command(args, cwd=None, verbose=False):
  259. try:
  260. # remember shell=False, so use git.cmd on windows, not just git
  261. p = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=cwd)
  262. except EnvironmentError:
  263. e = sys.exc_info()[1]
  264. if verbose:
  265. print("unable to run %s" % args[0])
  266. print(e)
  267. return None
  268. stdout = p.communicate()[0].strip()
  269. if sys.version >= '3':
  270. stdout = stdout.decode()
  271. if p.returncode != 0:
  272. if verbose:
  273. print("unable to run %s (error)" % args[0])
  274. return None
  275. return stdout
  276. import sys
  277. import re
  278. import os.path
  279. def get_expanded_variables(versionfile_source):
  280. # the code embedded in _version.py can just fetch the value of these
  281. # variables. When used from setup.py, we don't want to import
  282. # _version.py, so we do it with a regexp instead. This function is not
  283. # used from _version.py.
  284. variables = {}
  285. try:
  286. for line in open(versionfile_source,"r").readlines():
  287. if line.strip().startswith("git_refnames ="):
  288. mo = re.search(r'=\s*"(.*)"', line)
  289. if mo:
  290. variables["refnames"] = mo.group(1)
  291. if line.strip().startswith("git_full ="):
  292. mo = re.search(r'=\s*"(.*)"', line)
  293. if mo:
  294. variables["full"] = mo.group(1)
  295. except EnvironmentError:
  296. pass
  297. return variables
  298. def versions_from_expanded_variables(variables, tag_prefix, verbose=False):
  299. refnames = variables["refnames"].strip()
  300. if refnames.startswith("$Format"):
  301. if verbose:
  302. print("variables are unexpanded, not using")
  303. return {} # unexpanded, so not in an unpacked git-archive tarball
  304. refs = set([r.strip() for r in refnames.strip("()").split(",")])
  305. for ref in list(refs):
  306. if not re.search(r'\d', ref):
  307. if verbose:
  308. print("discarding '%s', no digits" % ref)
  309. refs.discard(ref)
  310. # Assume all version tags have a digit. git's %d expansion
  311. # behaves like git log --decorate=short and strips out the
  312. # refs/heads/ and refs/tags/ prefixes that would let us
  313. # distinguish between branches and tags. By ignoring refnames
  314. # without digits, we filter out many common branch names like
  315. # "release" and "stabilization", as well as "HEAD" and "master".
  316. if verbose:
  317. print("remaining refs: %s" % ",".join(sorted(refs)))
  318. for ref in sorted(refs):
  319. # sorting will prefer e.g. "2.0" over "2.0rc1"
  320. if ref.startswith(tag_prefix):
  321. r = ref[len(tag_prefix):]
  322. if verbose:
  323. print("picking %s" % r)
  324. return { "version": r,
  325. "full": variables["full"].strip() }
  326. # no suitable tags, so we use the full revision id
  327. if verbose:
  328. print("no suitable tags, using full revision id")
  329. return { "version": variables["full"].strip(),
  330. "full": variables["full"].strip() }
  331. def versions_from_vcs(tag_prefix, versionfile_source, verbose=False):
  332. # this runs 'git' from the root of the source tree. That either means
  333. # someone ran a setup.py command (and this code is in versioneer.py, so
  334. # IN_LONG_VERSION_PY=False, thus the containing directory is the root of
  335. # the source tree), or someone ran a project-specific entry point (and
  336. # this code is in _version.py, so IN_LONG_VERSION_PY=True, thus the
  337. # containing directory is somewhere deeper in the source tree). This only
  338. # gets called if the git-archive 'subst' variables were *not* expanded,
  339. # and _version.py hasn't already been rewritten with a short version
  340. # string, meaning we're inside a checked out source tree.
  341. try:
  342. here = os.path.abspath(__file__)
  343. except NameError:
  344. # some py2exe/bbfreeze/non-CPython implementations don't do __file__
  345. return {} # not always correct
  346. # versionfile_source is the relative path from the top of the source tree
  347. # (where the .git directory might live) to this file. Invert this to find
  348. # the root from __file__.
  349. root = here
  350. if IN_LONG_VERSION_PY:
  351. for i in range(len(versionfile_source.split("/"))):
  352. root = os.path.dirname(root)
  353. else:
  354. root = os.path.dirname(here)
  355. if not os.path.exists(os.path.join(root, ".git")):
  356. if verbose:
  357. print("no .git in %s" % root)
  358. return {}
  359. GIT = "git"
  360. if sys.platform == "win32":
  361. GIT = "git.cmd"
  362. stdout = run_command([GIT, "describe", "--tags", "--dirty", "--always"],
  363. cwd=root)
  364. if stdout is None:
  365. return {}
  366. if not stdout.startswith(tag_prefix):
  367. if verbose:
  368. print("tag '%s' doesn't start with prefix '%s'" % (stdout, tag_prefix))
  369. return {}
  370. tag = stdout[len(tag_prefix):]
  371. stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=root)
  372. if stdout is None:
  373. return {}
  374. full = stdout.strip()
  375. if tag.endswith("-dirty"):
  376. full += "-dirty"
  377. return {"version": tag, "full": full}
  378. def versions_from_parentdir(parentdir_prefix, versionfile_source, verbose=False):
  379. if IN_LONG_VERSION_PY:
  380. # We're running from _version.py. If it's from a source tree
  381. # (execute-in-place), we can work upwards to find the root of the
  382. # tree, and then check the parent directory for a version string. If
  383. # it's in an installed application, there's no hope.
  384. try:
  385. here = os.path.abspath(__file__)
  386. except NameError:
  387. # py2exe/bbfreeze/non-CPython don't have __file__
  388. return {} # without __file__, we have no hope
  389. # versionfile_source is the relative path from the top of the source
  390. # tree to _version.py. Invert this to find the root from __file__.
  391. root = here
  392. for i in range(len(versionfile_source.split("/"))):
  393. root = os.path.dirname(root)
  394. else:
  395. # we're running from versioneer.py, which means we're running from
  396. # the setup.py in a source tree. sys.argv[0] is setup.py in the root.
  397. here = os.path.abspath(sys.argv[0])
  398. root = os.path.dirname(here)
  399. # Source tarballs conventionally unpack into a directory that includes
  400. # both the project name and a version string.
  401. dirname = os.path.basename(root)
  402. if not dirname.startswith(parentdir_prefix):
  403. if verbose:
  404. print("guessing rootdir is '%s', but '%s' doesn't start with prefix '%s'" %
  405. (root, dirname, parentdir_prefix))
  406. return None
  407. return {"version": dirname[len(parentdir_prefix):], "full": ""}
  408. import sys
  409. def do_vcs_install(versionfile_source, ipy):
  410. GIT = "git"
  411. if sys.platform == "win32":
  412. GIT = "git.cmd"
  413. run_command([GIT, "add", "versioneer.py"])
  414. run_command([GIT, "add", versionfile_source])
  415. run_command([GIT, "add", ipy])
  416. present = False
  417. try:
  418. f = open(".gitattributes", "r")
  419. for line in f.readlines():
  420. if line.strip().startswith(versionfile_source):
  421. if "export-subst" in line.strip().split()[1:]:
  422. present = True
  423. f.close()
  424. except EnvironmentError:
  425. pass
  426. if not present:
  427. f = open(".gitattributes", "a+")
  428. f.write("%s export-subst\n" % versionfile_source)
  429. f.close()
  430. run_command([GIT, "add", ".gitattributes"])
  431. SHORT_VERSION_PY = """
  432. # This file was generated by 'versioneer.py' (0.7+) from
  433. # revision-control system data, or from the parent directory name of an
  434. # unpacked source archive. Distribution tarballs contain a pre-generated copy
  435. # of this file.
  436. version_version = '%(version)s'
  437. version_full = '%(full)s'
  438. def get_versions(default={}, verbose=False):
  439. return {'version': version_version, 'full': version_full}
  440. """
  441. DEFAULT = {"version": "unknown", "full": "unknown"}
  442. def versions_from_file(filename):
  443. versions = {}
  444. try:
  445. f = open(filename)
  446. except EnvironmentError:
  447. return versions
  448. for line in f.readlines():
  449. mo = re.match("version_version = '([^']+)'", line)
  450. if mo:
  451. versions["version"] = mo.group(1)
  452. mo = re.match("version_full = '([^']+)'", line)
  453. if mo:
  454. versions["full"] = mo.group(1)
  455. return versions
  456. def write_to_version_file(filename, versions):
  457. f = open(filename, "w")
  458. f.write(SHORT_VERSION_PY % versions)
  459. f.close()
  460. print("set %s to '%s'" % (filename, versions["version"]))
  461. def get_best_versions(versionfile, tag_prefix, parentdir_prefix,
  462. default=DEFAULT, verbose=False):
  463. # returns dict with two keys: 'version' and 'full'
  464. #
  465. # extract version from first of _version.py, 'git describe', parentdir.
  466. # This is meant to work for developers using a source checkout, for users
  467. # of a tarball created by 'setup.py sdist', and for users of a
  468. # tarball/zipball created by 'git archive' or github's download-from-tag
  469. # feature.
  470. variables = get_expanded_variables(versionfile_source)
  471. if variables:
  472. ver = versions_from_expanded_variables(variables, tag_prefix)
  473. if ver:
  474. if verbose: print("got version from expanded variable %s" % ver)
  475. return ver
  476. ver = versions_from_file(versionfile)
  477. if ver:
  478. if verbose: print("got version from file %s %s" % (versionfile, ver))
  479. return ver
  480. ver = versions_from_vcs(tag_prefix, versionfile_source, verbose)
  481. if ver:
  482. if verbose: print("got version from git %s" % ver)
  483. return ver
  484. ver = versions_from_parentdir(parentdir_prefix, versionfile_source, verbose)
  485. if ver:
  486. if verbose: print("got version from parentdir %s" % ver)
  487. return ver
  488. if verbose: print("got version from default %s" % ver)
  489. return default
  490. def get_versions(default=DEFAULT, verbose=False):
  491. assert versionfile_source is not None, "please set versioneer.versionfile_source"
  492. assert tag_prefix is not None, "please set versioneer.tag_prefix"
  493. assert parentdir_prefix is not None, "please set versioneer.parentdir_prefix"
  494. return get_best_versions(versionfile_source, tag_prefix, parentdir_prefix,
  495. default=default, verbose=verbose)
  496. def get_version(verbose=False):
  497. return get_versions(verbose=verbose)["version"]
  498. class cmd_version(Command):
  499. description = "report generated version string"
  500. user_options = []
  501. boolean_options = []
  502. def initialize_options(self):
  503. pass
  504. def finalize_options(self):
  505. pass
  506. def run(self):
  507. ver = get_version(verbose=True)
  508. print("Version is currently: %s" % ver)
  509. class cmd_build_py(_build_py):
  510. def run(self):
  511. versions = get_versions(verbose=True)
  512. _build_py.run(self)
  513. # now locate _version.py in the new build/ directory and replace it
  514. # with an updated value
  515. target_versionfile = os.path.join(self.build_lib, versionfile_build)
  516. print("UPDATING %s" % target_versionfile)
  517. os.unlink(target_versionfile)
  518. f = open(target_versionfile, "w")
  519. f.write(SHORT_VERSION_PY % versions)
  520. f.close()
  521. class cmd_sdist(_sdist):
  522. def run(self):
  523. versions = get_versions(verbose=True)
  524. self._versioneer_generated_versions = versions
  525. # unless we update this, the command will keep using the old version
  526. self.distribution.metadata.version = versions["version"]
  527. return _sdist.run(self)
  528. def make_release_tree(self, base_dir, files):
  529. _sdist.make_release_tree(self, base_dir, files)
  530. # now locate _version.py in the new base_dir directory (remembering
  531. # that it may be a hardlink) and replace it with an updated value
  532. target_versionfile = os.path.join(base_dir, versionfile_source)
  533. print("UPDATING %s" % target_versionfile)
  534. os.unlink(target_versionfile)
  535. f = open(target_versionfile, "w")
  536. f.write(SHORT_VERSION_PY % self._versioneer_generated_versions)
  537. f.close()
  538. INIT_PY_SNIPPET = """
  539. from ._version import get_versions
  540. __version__ = get_versions()['version']
  541. del get_versions
  542. """
  543. class cmd_update_files(Command):
  544. description = "modify __init__.py and create _version.py"
  545. user_options = []
  546. boolean_options = []
  547. def initialize_options(self):
  548. pass
  549. def finalize_options(self):
  550. pass
  551. def run(self):
  552. ipy = os.path.join(os.path.dirname(versionfile_source), "__init__.py")
  553. print(" creating %s" % versionfile_source)
  554. f = open(versionfile_source, "w")
  555. f.write(LONG_VERSION_PY % {"DOLLAR": "$",
  556. "TAG_PREFIX": tag_prefix,
  557. "PARENTDIR_PREFIX": parentdir_prefix,
  558. "VERSIONFILE_SOURCE": versionfile_source,
  559. })
  560. f.close()
  561. try:
  562. old = open(ipy, "r").read()
  563. except EnvironmentError:
  564. old = ""
  565. if INIT_PY_SNIPPET not in old:
  566. print(" appending to %s" % ipy)
  567. f = open(ipy, "a")
  568. f.write(INIT_PY_SNIPPET)
  569. f.close()
  570. else:
  571. print(" %s unmodified" % ipy)
  572. do_vcs_install(versionfile_source, ipy)
  573. def get_cmdclass():
  574. return {'version': cmd_version,
  575. 'update_files': cmd_update_files,
  576. 'build_py': cmd_build_py,
  577. 'sdist': cmd_sdist,
  578. }