comparison env/lib/python3.9/site-packages/pip/_internal/operations/install/legacy.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """Legacy installation process, i.e. `setup.py install`.
2 """
3
4 import logging
5 import os
6 import sys
7 from distutils.util import change_root
8
9 from pip._internal.exceptions import InstallationError
10 from pip._internal.utils.logging import indent_log
11 from pip._internal.utils.misc import ensure_dir
12 from pip._internal.utils.setuptools_build import make_setuptools_install_args
13 from pip._internal.utils.subprocess import runner_with_spinner_message
14 from pip._internal.utils.temp_dir import TempDirectory
15 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
16
17 if MYPY_CHECK_RUNNING:
18 from typing import List, Optional, Sequence
19
20 from pip._internal.build_env import BuildEnvironment
21 from pip._internal.models.scheme import Scheme
22
23
24 logger = logging.getLogger(__name__)
25
26
27 class LegacyInstallFailure(Exception):
28 def __init__(self):
29 # type: () -> None
30 self.parent = sys.exc_info()
31
32
33 def install(
34 install_options, # type: List[str]
35 global_options, # type: Sequence[str]
36 root, # type: Optional[str]
37 home, # type: Optional[str]
38 prefix, # type: Optional[str]
39 use_user_site, # type: bool
40 pycompile, # type: bool
41 scheme, # type: Scheme
42 setup_py_path, # type: str
43 isolated, # type: bool
44 req_name, # type: str
45 build_env, # type: BuildEnvironment
46 unpacked_source_directory, # type: str
47 req_description, # type: str
48 ):
49 # type: (...) -> bool
50
51 header_dir = scheme.headers
52
53 with TempDirectory(kind="record") as temp_dir:
54 try:
55 record_filename = os.path.join(temp_dir.path, 'install-record.txt')
56 install_args = make_setuptools_install_args(
57 setup_py_path,
58 global_options=global_options,
59 install_options=install_options,
60 record_filename=record_filename,
61 root=root,
62 prefix=prefix,
63 header_dir=header_dir,
64 home=home,
65 use_user_site=use_user_site,
66 no_user_config=isolated,
67 pycompile=pycompile,
68 )
69
70 runner = runner_with_spinner_message(
71 f"Running setup.py install for {req_name}"
72 )
73 with indent_log(), build_env:
74 runner(
75 cmd=install_args,
76 cwd=unpacked_source_directory,
77 )
78
79 if not os.path.exists(record_filename):
80 logger.debug('Record file %s not found', record_filename)
81 # Signal to the caller that we didn't install the new package
82 return False
83
84 except Exception:
85 # Signal to the caller that we didn't install the new package
86 raise LegacyInstallFailure
87
88 # At this point, we have successfully installed the requirement.
89
90 # We intentionally do not use any encoding to read the file because
91 # setuptools writes the file using distutils.file_util.write_file,
92 # which does not specify an encoding.
93 with open(record_filename) as f:
94 record_lines = f.read().splitlines()
95
96 def prepend_root(path):
97 # type: (str) -> str
98 if root is None or not os.path.isabs(path):
99 return path
100 else:
101 return change_root(root, path)
102
103 for line in record_lines:
104 directory = os.path.dirname(line)
105 if directory.endswith('.egg-info'):
106 egg_info_dir = prepend_root(directory)
107 break
108 else:
109 message = (
110 "{} did not indicate that it installed an "
111 ".egg-info directory. Only setup.py projects "
112 "generating .egg-info directories are supported."
113 ).format(req_description)
114 raise InstallationError(message)
115
116 new_lines = []
117 for line in record_lines:
118 filename = line.strip()
119 if os.path.isdir(filename):
120 filename += os.path.sep
121 new_lines.append(
122 os.path.relpath(prepend_root(filename), egg_info_dir)
123 )
124 new_lines.sort()
125 ensure_dir(egg_info_dir)
126 inst_files_path = os.path.join(egg_info_dir, 'installed-files.txt')
127 with open(inst_files_path, 'w') as f:
128 f.write('\n'.join(new_lines) + '\n')
129
130 return True