1
"""distutils.command.install_egg_info
3
Implements the Distutils 'install_egg_info' command, for installing
4
a package's PKG-INFO metadata."""
7
from distutils.cmd import Command
8
from distutils import log, dir_util
11
class install_egg_info(Command):
12
"""Install an .egg-info file for the package"""
14
description = "Install package's PKG-INFO metadata as an .egg-info file"
16
('install-dir=', 'd', "directory to install to"),
19
def initialize_options(self):
20
self.install_dir = None
22
def finalize_options(self):
23
self.set_undefined_options('install_lib',('install_dir','install_dir'))
24
basename = "%s-%s-py%s.egg-info" % (
25
to_filename(safe_name(self.distribution.get_name())),
26
to_filename(safe_version(self.distribution.get_version())),
29
self.target = os.path.join(self.install_dir, basename)
30
self.outputs = [self.target]
34
if os.path.isdir(target) and not os.path.islink(target):
35
dir_util.remove_tree(target, dry_run=self.dry_run)
36
elif os.path.exists(target):
37
self.execute(os.unlink,(self.target,),"Removing "+target)
38
elif not os.path.isdir(self.install_dir):
39
self.execute(os.makedirs, (self.install_dir,),
40
"Creating "+self.install_dir)
41
log.info("Writing %s", target)
44
self.distribution.metadata.write_pkg_file(f)
47
def get_outputs(self):
51
# The following routines are taken from setuptools' pkg_resources module and
52
# can be replaced by importing them from pkg_resources once it is included
56
"""Convert an arbitrary string to a standard distribution name
58
Any runs of non-alphanumeric/. characters are replaced with a single '-'.
60
return re.sub('[^A-Za-z0-9.]+', '-', name)
63
def safe_version(version):
64
"""Convert an arbitrary string to a standard version string
66
Spaces become dots, and all other non-alphanumeric characters become
67
dashes, with runs of multiple dashes condensed to a single dash.
69
version = version.replace(' ','.')
70
return re.sub('[^A-Za-z0-9.]+', '-', version)
73
def to_filename(name):
74
"""Convert a project or version name to its filename-escaped form
76
Any '-' characters are currently replaced with '_'.
78
return name.replace('-','_')