Debian Codegraph @

lib-python/3/distutils/command/install_egg_info.py

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