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)
43
with open(target, 'w', encoding='UTF-8') as f:
44
self.distribution.metadata.write_pkg_file(f)
46
def get_outputs(self):
50
# The following routines are taken from setuptools' pkg_resources module and
51
# can be replaced by importing them from pkg_resources once it is included
55
"""Convert an arbitrary string to a standard distribution name
57
Any runs of non-alphanumeric/. characters are replaced with a single '-'.
59
return re.sub('[^A-Za-z0-9.]+', '-', name)
62
def safe_version(version):
63
"""Convert an arbitrary string to a standard version string
65
Spaces become dots, and all other non-alphanumeric characters become
66
dashes, with runs of multiple dashes condensed to a single dash.
68
version = version.replace(' ','.')
69
return re.sub('[^A-Za-z0-9.]+', '-', version)
72
def to_filename(name):
73
"""Convert a project or version name to its filename-escaped form
75
Any '-' characters are currently replaced with '_'.
77
return name.replace('-','_')