Created
June 23, 2011 08:59
-
-
Save valeryz/1042185 to your computer and use it in GitHub Desktop.
Pinning dependencies versions in buildout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zc.buildout.easy_install | |
import zc.recipe.egg | |
import os | |
import os.path | |
import sys | |
import fileinput | |
import pkg_resources | |
class PinVersions: | |
""" | |
Recipe for generation of pinversions script | |
""" | |
def __init__(self, buildout, name, options): | |
self.packages = buildout['buildout']['develop'].split() | |
self.bindir = buildout['buildout']['bin-directory'] | |
self.egg = zc.recipe.egg.Scripts(buildout, name, options) | |
def install(self): | |
_, ws = self.egg.working_set(['recipes']) | |
return zc.buildout.easy_install.scripts( | |
[('pinversions', 'recipes.pinversions', 'pinversions'), | |
('dumpversions', 'recipes.pinversions', 'dumpversions')], | |
ws, sys.executable, self.bindir, | |
arguments='packages=%r' % self.packages) | |
update = install | |
def _find_version(): | |
if len(sys.argv) < 2: | |
return os.popen('git describe').read().strip() | |
else: | |
return sys.argv[1] | |
def pinversions(packages): | |
""" | |
pin versions of our packages to command line argument or | |
'git describe' if command line argument isn't given | |
""" | |
version = _find_version() | |
# change version in setup.py files | |
for p in packages: | |
setup_script = os.path.join(p, "setup.py") | |
for line in fileinput.input(setup_script, inplace=1): | |
if line.startswith("version"): | |
sys.stdout.write("version = '%s'\n" % version) | |
else: | |
sys.stdout.write(line) | |
# change version in buildout.cfg | |
for line in fileinput.input("buildout.cfg", inplace=1): | |
if line.startswith("kgp-version"): | |
sys.stdout.write("kgp-version = %s\n" % version) | |
else: | |
sys.stdout.write(line) | |
def dumpversions(packages): | |
version = _find_version() | |
devel_pkgs = [] | |
for p in packages: | |
devel_pkgs.append(os.path.realpath(p)) | |
for dist in pkg_resources.working_set: | |
if any((dist.location.startswith(d) for d in devel_pkgs)): | |
v = version | |
else: | |
v = dist.version | |
print "%s = %s" % (dist.project_name, v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment