Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify metadata generation flow, to be a lot more "linear" #7287

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reduce operations.build.metadata's API to 1 function
Why: There isn't any state being maintained, or multiple uses of the
metadata generator for a single requirement. The additional complexity
does not help in any significant manner.
  • Loading branch information
pradyunsg committed Nov 4, 2019
commit 33ccea2e0c4a7e0a07d41fc056dd06b33896dfdb
17 changes: 6 additions & 11 deletions src/pip/_internal/operations/build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,20 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Callable

from pip._internal.req.req_install import InstallRequirement

logger = logging.getLogger(__name__)


def get_metadata_generator(install_req):
# type: (InstallRequirement) -> Callable[[InstallRequirement], str]
"""Return a callable metadata generator for this InstallRequirement.

A metadata generator takes an InstallRequirement (install_req) as an input,
generates metadata via the appropriate process for that install_req and
returns the generated metadata directory.
def generate_metadata(install_req):
# type: (InstallRequirement) -> str
"""Generate metadata and return the metadata directory.
"""
func = _generate_metadata
if not install_req.use_pep517:
return _generate_metadata_legacy
func = _generate_metadata_legacy

return _generate_metadata
return func(install_req)


def _generate_metadata(install_req):
Expand Down
5 changes: 2 additions & 3 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pip._internal.exceptions import InstallationError
from pip._internal.locations import distutils_scheme
from pip._internal.models.link import Link
from pip._internal.operations.build.metadata import get_metadata_generator
from pip._internal.operations.build.metadata import generate_metadata
from pip._internal.pyproject import load_pyproject_toml, make_pyproject_path
from pip._internal.req.req_uninstall import UninstallPathSet
from pip._internal.utils.compat import native_str
Expand Down Expand Up @@ -615,9 +615,8 @@ def prepare_metadata(self):
"""
assert self.source_dir

metadata_generator = get_metadata_generator(self)
with indent_log():
self.metadata_directory = metadata_generator(self)
self.metadata_directory = generate_metadata(self)

if not self.name:
self.move_to_correct_build_directory()
Expand Down