Commit 4f679e8d authored by Julien Muchembled's avatar Julien Muchembled

Merge zc.recipe.egg branch

Conflicts:
	zc.recipe.egg_/setup.py
	zc.recipe.egg_/src/zc/recipe/egg/egg.py
parents 792deebc 7af0dfd0
1.3.2.post4
-----------
- Fix a regression in 1.3.2.post3 that breaks setup-eggs option.
1.3.2.post3
-----------
- Support environment in zc.recipe.egg:develop.
1.3.2.post2
-----------
- Version string is now N.N.N.devN to follow http://legacy.python.org/dev/peps/pep-0440/ .
- Support on the fly patches in zc.recipe.egg by ``EGGNAME-patches``,
``EGGNAME-patch-options``, ``EGGNAME-patch-binary`` (or
``patch-binary``) and ``EGGNAME-patch-revision`` options.
- Support on the fly patches in zc.recipe.egg:custom by ``patches``,
``patch-options``, ``patch-binary`` and ``patch-revision`` options.
(options ``EGGNAME-*`` are also supported as well).
1.3.2nxd001
-----------
- Add setup-eggs option in zc.recipe.egg:custom.
......@@ -32,11 +32,69 @@ class Base:
python = options.get('python', buildout['buildout']['python'])
options['executable'] = buildout[python]['executable']
environment_section = options.get('environment')
if environment_section:
self.environment = buildout[environment_section]
else:
self.environment = {}
environment_data = self.environment.items()
environment_data.sort()
options['_environment-data'] = repr(environment_data)
self.build_ext = build_ext(buildout, options)
def install(self):
self._set_environment()
try:
return self._install()
finally:
self._restore_environment()
def update(self):
return self.install()
def _set_environment(self):
self._saved_environment = {}
for key, value in self.environment.items():
if key in os.environ:
self._saved_environment[key] = os.environ[key]
# Interpolate value with variables from environment. Maybe there
# should be a general way of doing this in buildout with something
# like ${environ:foo}:
os.environ[key] = value % os.environ
def _restore_environment(self):
for key in self.environment:
if key in self._saved_environment:
os.environ[key] = self._saved_environment[key]
else:
try:
del os.environ[key]
except KeyError:
pass
def _get_patch_dict(self, options, distribution):
patch_dict = {}
global_patch_binary = options.get('patch-binary', 'patch')
def get_option(egg, key, default):
return options.get('%s-%s' % (egg, key),
options.get(key, default))
egg = re.sub('[<>=].*', '', distribution)
patches = filter(lambda x:x,
map(lambda x:x.strip(),
get_option(egg, 'patches', '').splitlines()))
if not patches:
return patch_dict
patch_options = get_option(egg, 'patch-options', '-p0').split()
patch_binary = get_option(egg, 'patch-binary', global_patch_binary)
patch_revision = int(get_option(egg, 'patch-revision', len(patches)))
patch_dict[egg] = {
'patches':patches,
'patch_options':patch_options,
'patch_binary':patch_binary,
'patch_revision':patch_revision,
}
return patch_dict
class Custom(Base):
......@@ -57,25 +115,16 @@ class Custom(Base):
options['index'] = index
self.index = index
environment_section = options.get('environment')
if environment_section:
self.environment = buildout[environment_section]
else:
self.environment = {}
environment_data = self.environment.items()
environment_data.sort()
options['_environment-data'] = repr(environment_data)
options['_e'] = buildout['buildout']['eggs-directory']
assert options.get('unzip') in ('true', 'false', None)
if buildout['buildout'].get('offline') == 'true':
self.install = lambda: ()
self._install = lambda: ()
self.newest = buildout['buildout'].get('newest') == 'true'
def install(self):
def _install(self):
options = self.options
distribution = options.get('egg')
if distribution is None:
......@@ -88,36 +137,28 @@ class Custom(Base):
distribution = options.get('egg', options.get('eggs', self.name)
).strip()
self._set_environment()
try:
return zc.buildout.easy_install.build(
distribution, options['_d'], self.build_ext,
self.links, self.index, options['executable'], [options['_e']],
setup_eggs = [
r.strip()
for r in options.get('setup-eggs', '').split('\n')
if r.strip()]
if setup_eggs:
ws = zc.buildout.easy_install.install(
setup_eggs, options['_e'],
links=self.links,
index=self.index,
executable=options['executable'],
path=[options['_d'], options['_e']],
newest=self.newest,
)
finally:
self._restore_environment()
def _set_environment(self):
self._saved_environment = {}
for key, value in self.environment.items():
if key in os.environ:
self._saved_environment[key] = os.environ[key]
# Interpolate value with variables from environment. Maybe there
# should be a general way of doing this in buildout with something
# like ${environ:foo}:
os.environ[key] = value % os.environ
extra_path = os.pathsep.join(ws.entries)
self.environment['PYTHONEXTRAPATH'] = os.environ['PYTHONEXTRAPATH'] = extra_path
def _restore_environment(self):
for key in self.environment:
if key in self._saved_environment:
os.environ[key] = self._saved_environment[key]
else:
try:
del os.environ[key]
except KeyError:
pass
patch_dict = self._get_patch_dict(options, distribution)
return zc.buildout.easy_install.build(
distribution, options['_d'], self.build_ext,
self.links, self.index, options['executable'], [options['_e']],
newest=self.newest, patch_dict=patch_dict)
class Develop(Base):
......@@ -127,7 +168,7 @@ class Develop(Base):
options['setup'] = os.path.join(buildout['buildout']['directory'],
options['setup'])
def install(self):
def _install(self):
options = self.options
return zc.buildout.easy_install.develop(
options['setup'], options['_d'], self.build_ext,
......
......@@ -61,6 +61,33 @@ class Eggs(object):
python = options.setdefault('python', b_options['python'])
options['executable'] = buildout[python]['executable']
def _get_patch_dict(self, options, distribution_list):
patch_dict = {}
global_patch_binary = options.get('patch-binary', 'patch')
def get_option(egg, key, default):
if len(distribution_list) == 1:
return options.get('%s-%s' % (egg, key),
options.get(key, default))
else:
return options.get('%s-%s' % (egg, key), default)
for distribution in distribution_list:
egg = re.sub('[<>=].*', '', distribution)
patches = filter(lambda x:x,
map(lambda x:x.strip(),
get_option(egg, 'patches', '').splitlines()))
if not patches:
continue
patch_options = get_option(egg, 'patch-options', '-p0').split()
patch_binary = get_option(egg, 'patch-binary', global_patch_binary)
patch_revision = int(get_option(egg, 'patch-revision', len(patches)))
patch_dict[egg] = {
'patches':patches,
'patch_options':patch_options,
'patch_binary':patch_binary,
'patch_revision':patch_revision,
}
return patch_dict
def working_set(self, extra=()):
"""Separate method to just get the working set
......@@ -88,6 +115,7 @@ class Eggs(object):
kw = {}
if 'unzip' in options:
kw['always_unzip'] = options.query_bool('unzip', None)
for option_key, kw_key in (
('__networkcache__download-cache-url', 'download_cache_url'),
('__networkcache__download-dir-url', 'download_dir_url'),
......@@ -109,6 +137,7 @@ class Eggs(object):
else:
kw[kw_key] = b_options[option_key]
patch_dict = self._get_patch_dict(options, distributions)
ws = zc.buildout.easy_install.install(
distributions, options['eggs-directory'],
links=self.links,
......@@ -119,6 +148,7 @@ class Eggs(object):
include_site_packages=self.include_site_packages,
allowed_eggs_from_site_packages=self.allowed_eggs,
allow_hosts=self.allow_hosts,
patch_dict=patch_dict,
**kw)
return orig_distributions, ws
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment