_cache_generated_egg = False
-def _yield_distributions(include_dist, include_egg, paths=sys.path):
+def _yield_distributions(include_dist, include_egg, paths):
"""
Yield .dist-info and .egg(-info) distributions, based on the arguments
yield EggInfoDistribution(dist_path)
-def _generate_cache(use_egg_info=False, paths=sys.path):
+def _generate_cache(use_egg_info, paths):
global _cache_generated, _cache_generated_egg
if _cache_generated_egg or (_cache_generated and not use_egg_info):
return '-'.join([name, normalized_version]) + file_extension
-def get_distributions(use_egg_info=False, paths=sys.path):
+def get_distributions(use_egg_info=False, paths=None):
"""
Provides an iterator that looks for ``.dist-info`` directories in
``sys.path`` and returns :class:`Distribution` instances for each one of
:rtype: iterator of :class:`Distribution` and :class:`EggInfoDistribution`
instances
"""
+ if paths is None:
+ paths = sys.path
+
if not _cache_enabled:
for dist in _yield_distributions(True, use_egg_info, paths):
yield dist
:rtype: :class:`Distribution` or :class:`EggInfoDistribution` or None
"""
- if paths == None:
+ if paths is None:
paths = sys.path
if not _cache_enabled:
def get_file_path(distribution_name, relative_path):
"""Return the path to a resource file."""
dist = get_distribution(distribution_name)
- if dist != None:
+ if dist is not None:
return dist.get_resource_path(relative_path)
raise LookupError('no distribution named %r found' % distribution_name)
try:
os.makedirs(os.path.dirname(new))
except OSError as e:
- if e.errno == errno.EEXIST:
- pass
- else:
- raise e
+ if e.errno != errno.EEXIST:
+ raise
os.rename(old, new)
yield old, new
os.chdir(old_dir)
-def install_dists(dists, path, paths=sys.path):
+def install_dists(dists, path, paths=None):
"""Install all distributions provided in dists, with the given prefix.
If an error occurs while installing one of the distributions, uninstall all
# reverting
for installed_dist in installed_dists:
logger.info('Reverting %s', installed_dist)
- _remove_dist(installed_dist, paths)
+ remove(installed_dist.name, paths)
raise e
return installed_dists
def install_from_infos(install_path=None, install=[], remove=[], conflicts=[],
- paths=sys.path):
+ paths=None):
"""Install and remove the given distributions.
The function signature is made to be compatible with the one of get_infos.
infos[key].extend(new_infos[key])
-def _remove_dist(dist, paths=sys.path):
- remove(dist.name, paths)
-
-
-def remove(project_name, paths=sys.path, auto_confirm=True):
+def remove(project_name, paths=None, auto_confirm=True):
"""Removes a single project from the installation.
Returns True on success
def _main(**attrs):
if 'script_args' not in attrs:
- import sys
attrs['requirements'] = sys.argv[1]
get_infos(**attrs)
# Note that we're making changes to sys.path
super(BuildExtTestCase, self).setUp()
self.tmp_dir = self.mkdtemp()
- self.sys_path = sys.path, sys.path[:]
sys.path.append(self.tmp_dir)
filename = _get_source_filename()
if os.path.exists(filename):
def tearDown(self):
# Get everything back to normal
unload('xx')
- sys.path = self.sys_path[0]
- sys.path[:] = self.sys_path[1]
+ sys.path.remove(self.tmp_dir)
if sys.version > "2.6":
site.USER_BASE = self.old_user_base
build_ext.USER_BASE = self.old_user_base
disable_cache()
# Setup the path environment with our fake distributions
current_path = os.path.abspath(os.path.dirname(__file__))
- self.sys_path = sys.path[:]
self.fake_dists_path = os.path.join(current_path, 'fake_dists')
sys.path.insert(0, self.fake_dists_path)
def tearDown(self):
- sys.path[:] = self.sys_path
+ sys.path.remove(self.fake_dists_path)
enable_cache()
super(TestDatabase, self).tearDown()
dists = [('choxie', '2.0.0.9'), ('grammar', '1.0a4'),
('towel-stuff', '0.1'), ('babar', '0.1')]
- checkLists([], _yield_distributions(False, False))
+ checkLists([], _yield_distributions(False, False, sys.path))
found = [(dist.name, dist.metadata['Version'])
- for dist in _yield_distributions(False, True)
+ for dist in _yield_distributions(False, True, sys.path)
if dist.path.startswith(self.fake_dists_path)]
checkLists(eggs, found)
found = [(dist.name, dist.metadata['Version'])
- for dist in _yield_distributions(True, False)
+ for dist in _yield_distributions(True, False, sys.path)
if dist.path.startswith(self.fake_dists_path)]
checkLists(dists, found)
found = [(dist.name, dist.metadata['Version'])
- for dist in _yield_distributions(True, True)
+ for dist in _yield_distributions(True, True, sys.path)
if dist.path.startswith(self.fake_dists_path)]
checkLists(dists + eggs, found)