Skip to content

Commit 1515407

Browse files
authored
Move run_egg_info into operations.generate_metadata (#7063)
Merge pull request #7063 from pradyunsg/refactor/metadata-generator-legacy
2 parents c787fcb + ab0322b commit 1515407

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

src/pip/_internal/operations/generate_metadata.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
"""Metadata generation logic for source distributions.
22
"""
33

4+
import logging
5+
import os
6+
7+
from pip._internal.utils.misc import call_subprocess, ensure_dir
8+
from pip._internal.utils.setuptools_build import make_setuptools_shim_args
49
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
510

611
if MYPY_CHECK_RUNNING:
7-
from typing import Callable
12+
from typing import Callable, List
813
from pip._internal.req.req_install import InstallRequirement
914

15+
logger = logging.getLogger(__name__)
16+
1017

1118
def get_metadata_generator(install_req):
1219
# type: (InstallRequirement) -> Callable[[InstallRequirement], None]
@@ -18,7 +25,34 @@ def get_metadata_generator(install_req):
1825

1926
def _generate_metadata_legacy(install_req):
2027
# type: (InstallRequirement) -> None
21-
install_req.run_egg_info()
28+
req_details_str = install_req.name or "from {}".format(install_req.link)
29+
logger.debug(
30+
'Running setup.py (path:%s) egg_info for package %s',
31+
install_req.setup_py_path, req_details_str,
32+
)
33+
34+
# Compose arguments for subprocess call
35+
base_cmd = make_setuptools_shim_args(install_req.setup_py_path)
36+
if install_req.isolated:
37+
base_cmd += ["--no-user-cfg"]
38+
39+
# For non-editable installs, don't put the .egg-info files at the root,
40+
# to avoid confusion due to the source code being considered an installed
41+
# egg.
42+
egg_base_option = [] # type: List[str]
43+
if not install_req.editable:
44+
egg_info_dir = os.path.join(install_req.setup_py_dir, 'pip-egg-info')
45+
egg_base_option = ['--egg-base', egg_info_dir]
46+
47+
# setuptools complains if the target directory does not exist.
48+
ensure_dir(egg_info_dir)
49+
50+
with install_req.build_env:
51+
call_subprocess(
52+
base_cmd + ["egg_info"] + egg_base_option,
53+
cwd=install_req.setup_py_dir,
54+
command_desc='python setup.py egg_info',
55+
)
2256

2357

2458
def _generate_metadata(install_req):

src/pip/_internal/req/req_install.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -627,38 +627,6 @@ def prepare_pep517_metadata(self):
627627

628628
self.metadata_directory = os.path.join(metadata_dir, distinfo_dir)
629629

630-
def run_egg_info(self):
631-
# type: () -> None
632-
if self.name:
633-
logger.debug(
634-
'Running setup.py (path:%s) egg_info for package %s',
635-
self.setup_py_path, self.name,
636-
)
637-
else:
638-
logger.debug(
639-
'Running setup.py (path:%s) egg_info for package from %s',
640-
self.setup_py_path, self.link,
641-
)
642-
base_cmd = make_setuptools_shim_args(
643-
self.setup_py_path,
644-
no_user_config=self.isolated
645-
)
646-
egg_info_cmd = base_cmd + ['egg_info']
647-
# We can't put the .egg-info files at the root, because then the
648-
# source code will be mistaken for an installed egg, causing
649-
# problems
650-
if self.editable:
651-
egg_base_option = [] # type: List[str]
652-
else:
653-
egg_info_dir = os.path.join(self.setup_py_dir, 'pip-egg-info')
654-
ensure_dir(egg_info_dir)
655-
egg_base_option = ['--egg-base', 'pip-egg-info']
656-
with self.build_env:
657-
call_subprocess(
658-
egg_info_cmd + egg_base_option,
659-
cwd=self.setup_py_dir,
660-
command_desc='python setup.py egg_info')
661-
662630
@property
663631
def egg_info_path(self):
664632
# type: () -> str

0 commit comments

Comments
 (0)