Skip to content

Commit

Permalink
Move run_egg_info into operations.generate_metadata (#7063)
Browse files Browse the repository at this point in the history
Merge pull request #7063 from pradyunsg/refactor/metadata-generator-legacy
  • Loading branch information
pradyunsg authored Sep 22, 2019
2 parents c787fcb + ab0322b commit 1515407
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
38 changes: 36 additions & 2 deletions src/pip/_internal/operations/generate_metadata.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
"""Metadata generation logic for source distributions.
"""

import logging
import os

from pip._internal.utils.misc import call_subprocess, ensure_dir
from pip._internal.utils.setuptools_build import make_setuptools_shim_args
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Callable
from typing import Callable, List
from pip._internal.req.req_install import InstallRequirement

logger = logging.getLogger(__name__)


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

def _generate_metadata_legacy(install_req):
# type: (InstallRequirement) -> None
install_req.run_egg_info()
req_details_str = install_req.name or "from {}".format(install_req.link)
logger.debug(
'Running setup.py (path:%s) egg_info for package %s',
install_req.setup_py_path, req_details_str,
)

# Compose arguments for subprocess call
base_cmd = make_setuptools_shim_args(install_req.setup_py_path)
if install_req.isolated:
base_cmd += ["--no-user-cfg"]

# For non-editable installs, don't put the .egg-info files at the root,
# to avoid confusion due to the source code being considered an installed
# egg.
egg_base_option = [] # type: List[str]
if not install_req.editable:
egg_info_dir = os.path.join(install_req.setup_py_dir, 'pip-egg-info')
egg_base_option = ['--egg-base', egg_info_dir]

# setuptools complains if the target directory does not exist.
ensure_dir(egg_info_dir)

with install_req.build_env:
call_subprocess(
base_cmd + ["egg_info"] + egg_base_option,
cwd=install_req.setup_py_dir,
command_desc='python setup.py egg_info',
)


def _generate_metadata(install_req):
Expand Down
32 changes: 0 additions & 32 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,38 +627,6 @@ def prepare_pep517_metadata(self):

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

def run_egg_info(self):
# type: () -> None
if self.name:
logger.debug(
'Running setup.py (path:%s) egg_info for package %s',
self.setup_py_path, self.name,
)
else:
logger.debug(
'Running setup.py (path:%s) egg_info for package from %s',
self.setup_py_path, self.link,
)
base_cmd = make_setuptools_shim_args(
self.setup_py_path,
no_user_config=self.isolated
)
egg_info_cmd = base_cmd + ['egg_info']
# We can't put the .egg-info files at the root, because then the
# source code will be mistaken for an installed egg, causing
# problems
if self.editable:
egg_base_option = [] # type: List[str]
else:
egg_info_dir = os.path.join(self.setup_py_dir, 'pip-egg-info')
ensure_dir(egg_info_dir)
egg_base_option = ['--egg-base', 'pip-egg-info']
with self.build_env:
call_subprocess(
egg_info_cmd + egg_base_option,
cwd=self.setup_py_dir,
command_desc='python setup.py egg_info')

@property
def egg_info_path(self):
# type: () -> str
Expand Down

0 comments on commit 1515407

Please sign in to comment.