Minor packaging cleanup.

- Use shortcut dist.version instead of going through metadata;
- Use %r throughout to display project names and paths.
This commit is contained in:
Éric Araujo 2011-07-29 02:37:21 +02:00
parent 7b0908a8e4
commit bab50cb124
5 changed files with 21 additions and 21 deletions

View file

@ -351,7 +351,7 @@ class EggInfoDistribution:
except IOError: except IOError:
requires = None requires = None
self.metadata = Metadata(path=path) self.metadata = Metadata(path=path)
self.name = self.metadata['name'] self.name = self.metadata['Name']
self.version = self.metadata['Version'] self.version = self.metadata['Version']
else: else:

View file

@ -72,7 +72,7 @@ class DependencyGraph:
self.missing[distribution].append(requirement) self.missing[distribution].append(requirement)
def _repr_dist(self, dist): def _repr_dist(self, dist):
return '%r %s' % (dist.name, dist.metadata['Version']) return '%r %s' % (dist.name, dist.version)
def repr_node(self, dist, level=1): def repr_node(self, dist, level=1):
"""Prints only a subgraph""" """Prints only a subgraph"""
@ -145,7 +145,7 @@ def generate_graph(dists):
graph.add_distribution(dist) graph.add_distribution(dist)
provides = (dist.metadata['Provides-Dist'] + provides = (dist.metadata['Provides-Dist'] +
dist.metadata['Provides'] + dist.metadata['Provides'] +
['%s (%s)' % (dist.name, dist.metadata['Version'])]) ['%s (%s)' % (dist.name, dist.version)])
for p in provides: for p in provides:
comps = p.strip().rsplit(" ", 1) comps = p.strip().rsplit(" ", 1)

View file

@ -85,7 +85,7 @@ def _run_packaging_install(path):
dist.parse_config_files() dist.parse_config_files()
try: try:
dist.run_command('install_dist') dist.run_command('install_dist')
name = dist.metadata['name'] name = dist.metadata['Name']
return database.get_distribution(name) is not None return database.get_distribution(name) is not None
except (IOError, os.error, PackagingError, CCompilerError) as msg: except (IOError, os.error, PackagingError, CCompilerError) as msg:
raise ValueError("Failed to install, " + str(msg)) raise ValueError("Failed to install, " + str(msg))
@ -118,10 +118,10 @@ def install_local_project(path):
""" """
path = os.path.abspath(path) path = os.path.abspath(path)
if os.path.isdir(path): if os.path.isdir(path):
logger.info('Installing from source directory: %s', path) logger.info('Installing from source directory: %r', path)
return _run_install_from_dir(path) return _run_install_from_dir(path)
elif _is_archive_file(path): elif _is_archive_file(path):
logger.info('Installing from archive: %s', path) logger.info('Installing from archive: %r', path)
_unpacked_dir = tempfile.mkdtemp() _unpacked_dir = tempfile.mkdtemp()
try: try:
shutil.unpack_archive(path, _unpacked_dir) shutil.unpack_archive(path, _unpacked_dir)
@ -129,7 +129,7 @@ def install_local_project(path):
finally: finally:
shutil.rmtree(_unpacked_dir) shutil.rmtree(_unpacked_dir)
else: else:
logger.warning('No projects to install.') logger.warning('No project to install.')
return False return False
@ -191,7 +191,7 @@ def install_dists(dists, path, paths=None):
# reverting # reverting
for installed_dist in installed_dists: for installed_dist in installed_dists:
logger.info('Reverting %s', installed_dist) logger.info('Reverting %r', installed_dist)
remove(installed_dist.name, paths) remove(installed_dist.name, paths)
raise e raise e
return installed_dists return installed_dists
@ -314,12 +314,12 @@ def get_infos(requirements, index=None, installed=None, prefer_final=True):
if predicate.name.lower() != installed_project.name.lower(): if predicate.name.lower() != installed_project.name.lower():
continue continue
found = True found = True
logger.info('Found %s %s', installed_project.name, logger.info('Found %r %s', installed_project.name,
installed_project.metadata['version']) installed_project.version)
# if we already have something installed, check it matches the # if we already have something installed, check it matches the
# requirements # requirements
if predicate.match(installed_project.metadata['version']): if predicate.match(installed_project.version):
return infos return infos
break break
@ -336,7 +336,7 @@ def get_infos(requirements, index=None, installed=None, prefer_final=True):
try: try:
release = index.get_release(requirements) release = index.get_release(requirements)
except (ReleaseNotFound, ProjectNotFound): except (ReleaseNotFound, ProjectNotFound):
raise InstallationException('Release not found: "%s"' % requirements) raise InstallationException('Release not found: %r' % requirements)
if release is None: if release is None:
logger.info('Could not find a matching project') logger.info('Could not find a matching project')
@ -386,7 +386,7 @@ def remove(project_name, paths=None, auto_confirm=True):
""" """
dist = get_distribution(project_name, use_egg_info=True, paths=paths) dist = get_distribution(project_name, use_egg_info=True, paths=paths)
if dist is None: if dist is None:
raise PackagingError('Distribution "%s" not found' % project_name) raise PackagingError('Distribution %r not found' % project_name)
files = dist.list_installed_files(local=True) files = dist.list_installed_files(local=True)
rmdirs = [] rmdirs = []
rmfiles = [] rmfiles = []
@ -423,7 +423,7 @@ def remove(project_name, paths=None, auto_confirm=True):
if not success: if not success:
logger.info('%r cannot be removed.', project_name) logger.info('%r cannot be removed.', project_name)
logger.info('Error: %s' % str(error)) logger.info('Error: %s', error)
return False return False
logger.info('Removing %r: ', project_name) logger.info('Removing %r: ', project_name)
@ -523,7 +523,7 @@ def install(project):
except InstallationConflict as e: except InstallationConflict as e:
if logger.isEnabledFor(logging.INFO): if logger.isEnabledFor(logging.INFO):
projects = ['%r %s' % (p.name, p.version) for p in e.args[0]] projects = ('%r %s' % (p.name, p.version) for p in e.args[0])
logger.info('%r conflicts with %s', project, ','.join(projects)) logger.info('%r conflicts with %s', project, ','.join(projects))
return True return True

View file

@ -302,7 +302,7 @@ class TestDatabase(support.LoggingCatcher,
self.assertIsInstance(dist, Distribution) self.assertIsInstance(dist, Distribution)
if (dist.name in dict(fake_dists) and if (dist.name in dict(fake_dists) and
dist.path.startswith(self.fake_dists_path)): dist.path.startswith(self.fake_dists_path)):
found_dists.append((dist.name, dist.metadata['version'], )) found_dists.append((dist.name, dist.version))
else: else:
# check that it doesn't find anything more than this # check that it doesn't find anything more than this
self.assertFalse(dist.path.startswith(self.fake_dists_path)) self.assertFalse(dist.path.startswith(self.fake_dists_path))
@ -323,7 +323,7 @@ class TestDatabase(support.LoggingCatcher,
self.assertIsInstance(dist, (Distribution, EggInfoDistribution)) self.assertIsInstance(dist, (Distribution, EggInfoDistribution))
if (dist.name in dict(fake_dists) and if (dist.name in dict(fake_dists) and
dist.path.startswith(self.fake_dists_path)): dist.path.startswith(self.fake_dists_path)):
found_dists.append((dist.name, dist.metadata['version'])) found_dists.append((dist.name, dist.version))
else: else:
self.assertFalse(dist.path.startswith(self.fake_dists_path)) self.assertFalse(dist.path.startswith(self.fake_dists_path))
@ -489,17 +489,17 @@ class TestDatabase(support.LoggingCatcher,
checkLists([], _yield_distributions(False, False, sys.path)) checkLists([], _yield_distributions(False, False, sys.path))
found = [(dist.name, dist.metadata['Version']) found = [(dist.name, dist.version)
for dist in _yield_distributions(False, True, sys.path) for dist in _yield_distributions(False, True, sys.path)
if dist.path.startswith(self.fake_dists_path)] if dist.path.startswith(self.fake_dists_path)]
checkLists(eggs, found) checkLists(eggs, found)
found = [(dist.name, dist.metadata['Version']) found = [(dist.name, dist.version)
for dist in _yield_distributions(True, False, sys.path) for dist in _yield_distributions(True, False, sys.path)
if dist.path.startswith(self.fake_dists_path)] if dist.path.startswith(self.fake_dists_path)]
checkLists(dists, found) checkLists(dists, found)
found = [(dist.name, dist.metadata['Version']) found = [(dist.name, dist.version)
for dist in _yield_distributions(True, True, sys.path) for dist in _yield_distributions(True, True, sys.path)
if dist.path.startswith(self.fake_dists_path)] if dist.path.startswith(self.fake_dists_path)]
checkLists(dists + eggs, found) checkLists(dists + eggs, found)

View file

@ -29,7 +29,7 @@ class InstalledDist:
self.metadata['Requires-Dist'] = deps self.metadata['Requires-Dist'] = deps
def __repr__(self): def __repr__(self):
return '<InstalledDist %s>' % self.metadata['Name'] return '<InstalledDist %r>' % self.metadata['Name']
class ToInstallDist: class ToInstallDist: