ยปCore Development>Code coverage>Lib/distutils/command/install_egg_info.py

Python code coverage for Lib/distutils/command/install_egg_info.py

#countcontent
1n/a"""distutils.command.install_egg_info
2n/a
3n/aImplements the Distutils 'install_egg_info' command, for installing
4n/aa package's PKG-INFO metadata."""
5n/a
6n/a
7n/afrom distutils.cmd import Command
8n/afrom distutils import log, dir_util
9n/aimport os, sys, re
10n/a
11n/aclass install_egg_info(Command):
12n/a """Install an .egg-info file for the package"""
13n/a
14n/a description = "Install package's PKG-INFO metadata as an .egg-info file"
15n/a user_options = [
16n/a ('install-dir=', 'd', "directory to install to"),
17n/a ]
18n/a
19n/a def initialize_options(self):
20n/a self.install_dir = None
21n/a
22n/a def finalize_options(self):
23n/a self.set_undefined_options('install_lib',('install_dir','install_dir'))
24n/a basename = "%s-%s-py%d.%d.egg-info" % (
25n/a to_filename(safe_name(self.distribution.get_name())),
26n/a to_filename(safe_version(self.distribution.get_version())),
27n/a *sys.version_info[:2]
28n/a )
29n/a self.target = os.path.join(self.install_dir, basename)
30n/a self.outputs = [self.target]
31n/a
32n/a def run(self):
33n/a target = self.target
34n/a if os.path.isdir(target) and not os.path.islink(target):
35n/a dir_util.remove_tree(target, dry_run=self.dry_run)
36n/a elif os.path.exists(target):
37n/a self.execute(os.unlink,(self.target,),"Removing "+target)
38n/a elif not os.path.isdir(self.install_dir):
39n/a self.execute(os.makedirs, (self.install_dir,),
40n/a "Creating "+self.install_dir)
41n/a log.info("Writing %s", target)
42n/a if not self.dry_run:
43n/a with open(target, 'w', encoding='UTF-8') as f:
44n/a self.distribution.metadata.write_pkg_file(f)
45n/a
46n/a def get_outputs(self):
47n/a return self.outputs
48n/a
49n/a
50n/a# The following routines are taken from setuptools' pkg_resources module and
51n/a# can be replaced by importing them from pkg_resources once it is included
52n/a# in the stdlib.
53n/a
54n/adef safe_name(name):
55n/a """Convert an arbitrary string to a standard distribution name
56n/a
57n/a Any runs of non-alphanumeric/. characters are replaced with a single '-'.
58n/a """
59n/a return re.sub('[^A-Za-z0-9.]+', '-', name)
60n/a
61n/a
62n/adef safe_version(version):
63n/a """Convert an arbitrary string to a standard version string
64n/a
65n/a Spaces become dots, and all other non-alphanumeric characters become
66n/a dashes, with runs of multiple dashes condensed to a single dash.
67n/a """
68n/a version = version.replace(' ','.')
69n/a return re.sub('[^A-Za-z0-9.]+', '-', version)
70n/a
71n/a
72n/adef to_filename(name):
73n/a """Convert a project or version name to its filename-escaped form
74n/a
75n/a Any '-' characters are currently replaced with '_'.
76n/a """
77n/a return name.replace('-','_')