Skip to content

Commit

Permalink
Generate legacy metadata in temporary directory
Browse files Browse the repository at this point in the history
Before it was generated in a pip-egg-info
subdirectory of the source dir. This will avoid
polluting source dir when we build in place.
  • Loading branch information
sbidoul committed Apr 4, 2020
1 parent 2a1f3c2 commit ced9040
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
27 changes: 12 additions & 15 deletions src/pip/_internal/operations/build/metadata_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
import os

from pip._internal.exceptions import InstallationError
from pip._internal.utils.misc import ensure_dir
from pip._internal.utils.setuptools_build import make_setuptools_egg_info_args
from pip._internal.utils.subprocess import call_subprocess
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
from pip._internal.vcs import vcs

if MYPY_CHECK_RUNNING:
from typing import List, Optional
from typing import List

from pip._internal.build_env import BuildEnvironment

logger = logging.getLogger(__name__)


def _find_egg_info(source_directory, is_editable):
# type: (str, bool) -> str
"""Find an .egg-info in `source_directory`, based on `is_editable`.
def _find_egg_info(source_directory):
# type: (str) -> str
"""Find an .egg-info in `source_directory`.
"""

def looks_like_virtual_env(path):
Expand Down Expand Up @@ -58,11 +58,7 @@ def depth_of_directory(dir_):
)

base = source_directory
if is_editable:
filenames = locate_editable_egg_info(base)
else:
base = os.path.join(base, 'pip-egg-info')
filenames = os.listdir(base)
filenames = locate_editable_egg_info(base)

if not filenames:
raise InstallationError(
Expand Down Expand Up @@ -96,14 +92,15 @@ def generate_metadata(
setup_py_path, details,
)

egg_info_dir = None # type: Optional[str]
# 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.
if not editable:
egg_info_dir = os.path.join(source_dir, 'pip-egg-info')
# setuptools complains if the target directory does not exist.
ensure_dir(egg_info_dir)
egg_info_dir = TempDirectory(
kind="pip-egg-info", globally_managed=True
).path
else:
egg_info_dir = source_dir

args = make_setuptools_egg_info_args(
setup_py_path,
Expand All @@ -119,4 +116,4 @@ def generate_metadata(
)

# Return the .egg-info directory.
return _find_egg_info(source_dir, editable)
return _find_egg_info(egg_info_dir)
2 changes: 0 additions & 2 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,6 @@ def archive(self, build_dir):
os.path.abspath(self.unpacked_source_directory)
)
for dirpath, dirnames, filenames in os.walk(dir):
if 'pip-egg-info' in dirnames:
dirnames.remove('pip-egg-info')
for dirname in dirnames:
dir_arcname = self._get_archive_name(
dirname, parentdir=dirpath, rootdir=dir,
Expand Down

0 comments on commit ced9040

Please sign in to comment.