comparison lib/python3.8/site-packages/pip/_internal/operations/install/legacy.py @ 0:9e54283cc701 draft

"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author guerler
date Mon, 27 Jul 2020 03:47:31 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9e54283cc701
1 """Legacy installation process, i.e. `setup.py install`.
2 """
3
4 import logging
5 import os
6 from distutils.util import change_root
7
8 from pip._internal.utils.deprecation import deprecated
9 from pip._internal.utils.logging import indent_log
10 from pip._internal.utils.misc import ensure_dir
11 from pip._internal.utils.setuptools_build import make_setuptools_install_args
12 from pip._internal.utils.subprocess import runner_with_spinner_message
13 from pip._internal.utils.temp_dir import TempDirectory
14 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
15
16 if MYPY_CHECK_RUNNING:
17 from typing import List, Optional, Sequence
18
19 from pip._internal.models.scheme import Scheme
20 from pip._internal.req.req_install import InstallRequirement
21
22
23 logger = logging.getLogger(__name__)
24
25
26 def install(
27 install_req, # type: InstallRequirement
28 install_options, # type: List[str]
29 global_options, # type: Sequence[str]
30 root, # type: Optional[str]
31 home, # type: Optional[str]
32 prefix, # type: Optional[str]
33 use_user_site, # type: bool
34 pycompile, # type: bool
35 scheme, # type: Scheme
36 ):
37 # type: (...) -> None
38 # Extend the list of global and install options passed on to
39 # the setup.py call with the ones from the requirements file.
40 # Options specified in requirements file override those
41 # specified on the command line, since the last option given
42 # to setup.py is the one that is used.
43 global_options = list(global_options) + \
44 install_req.options.get('global_options', [])
45 install_options = list(install_options) + \
46 install_req.options.get('install_options', [])
47
48 header_dir = scheme.headers
49
50 with TempDirectory(kind="record") as temp_dir:
51 record_filename = os.path.join(temp_dir.path, 'install-record.txt')
52 install_args = make_setuptools_install_args(
53 install_req.setup_py_path,
54 global_options=global_options,
55 install_options=install_options,
56 record_filename=record_filename,
57 root=root,
58 prefix=prefix,
59 header_dir=header_dir,
60 home=home,
61 use_user_site=use_user_site,
62 no_user_config=install_req.isolated,
63 pycompile=pycompile,
64 )
65
66 runner = runner_with_spinner_message(
67 "Running setup.py install for {}".format(install_req.name)
68 )
69 with indent_log(), install_req.build_env:
70 runner(
71 cmd=install_args,
72 cwd=install_req.unpacked_source_directory,
73 )
74
75 if not os.path.exists(record_filename):
76 logger.debug('Record file %s not found', record_filename)
77 return
78 install_req.install_succeeded = True
79
80 # We intentionally do not use any encoding to read the file because
81 # setuptools writes the file using distutils.file_util.write_file,
82 # which does not specify an encoding.
83 with open(record_filename) as f:
84 record_lines = f.read().splitlines()
85
86 def prepend_root(path):
87 # type: (str) -> str
88 if root is None or not os.path.isabs(path):
89 return path
90 else:
91 return change_root(root, path)
92
93 for line in record_lines:
94 directory = os.path.dirname(line)
95 if directory.endswith('.egg-info'):
96 egg_info_dir = prepend_root(directory)
97 break
98 else:
99 deprecated(
100 reason=(
101 "{} did not indicate that it installed an "
102 ".egg-info directory. Only setup.py projects "
103 "generating .egg-info directories are supported."
104 ).format(install_req),
105 replacement=(
106 "for maintainers: updating the setup.py of {0}. "
107 "For users: contact the maintainers of {0} to let "
108 "them know to update their setup.py.".format(
109 install_req.name
110 )
111 ),
112 gone_in="20.2",
113 issue=6998,
114 )
115 # FIXME: put the record somewhere
116 return
117 new_lines = []
118 for line in record_lines:
119 filename = line.strip()
120 if os.path.isdir(filename):
121 filename += os.path.sep
122 new_lines.append(
123 os.path.relpath(prepend_root(filename), egg_info_dir)
124 )
125 new_lines.sort()
126 ensure_dir(egg_info_dir)
127 inst_files_path = os.path.join(egg_info_dir, 'installed-files.txt')
128 with open(inst_files_path, 'w') as f:
129 f.write('\n'.join(new_lines) + '\n')