Revert "Refactor out read_pyproject_toml() and resolve_pyproject_toml()."

This reverts commit f66c1f7639.
This commit is contained in:
Chris Jerdonek 2019-04-26 20:21:04 -07:00
parent fb2533a945
commit 285a23fb8f
1 changed files with 32 additions and 77 deletions

View File

@ -10,7 +10,7 @@ from pip._internal.exceptions import InstallationError
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
if MYPY_CHECK_RUNNING:
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Tuple, Optional, List
def _is_list_of_str(obj):
@ -32,44 +32,42 @@ def make_pyproject_path(setup_py_dir):
return path
def read_pyproject_toml(path):
# type: (str) -> Optional[Dict[str, str]]
"""
Read a project's pyproject.toml file.
:param path: The path to the pyproject.toml file.
:return: The "build_system" value specified in the project's
pyproject.toml file.
"""
with io.open(path, encoding="utf-8") as f:
pp_toml = pytoml.load(f)
build_system = pp_toml.get("build-system")
return build_system
def resolve_pyproject_toml(
build_system, # type: Optional[Dict[str, str]]
has_pyproject, # type: bool
has_setup, # type: bool
def load_pyproject_toml(
use_pep517, # type: Optional[bool]
req_name, # type: str
pyproject_toml, # type: str
setup_py, # type: str
req_name # type: str
):
# type: (...) -> Optional[Tuple[List[str], str, List[str]]]
"""
Return how a pyproject.toml file's contents should be interpreted.
"""Load the pyproject.toml file.
:param build_system: the "build_system" value specified in a project's
pyproject.toml file, or None if the project either doesn't have the
file or does but the file doesn't have a "build_system" value.
:param has_pyproject: whether the project has a pyproject.toml file.
:param has_setup: whether the project has a setup.py file.
:param use_pep517: whether the user requested PEP 517 processing. None
means the user didn't explicitly specify.
:param req_name: the name of the requirement we're processing (for
error reporting).
Parameters:
use_pep517 - Has the user requested PEP 517 processing? None
means the user hasn't explicitly specified.
pyproject_toml - Location of the project's pyproject.toml file
setup_py - Location of the project's setup.py file
req_name - The name of the requirement we're processing (for
error reporting)
Returns:
None if we should use the legacy code path, otherwise a tuple
(
requirements from pyproject.toml,
name of PEP 517 backend,
requirements we should check are installed after setting
up the build environment
)
"""
has_pyproject = os.path.isfile(pyproject_toml)
has_setup = os.path.isfile(setup_py)
if has_pyproject:
with io.open(pyproject_toml, encoding="utf-8") as f:
pp_toml = pytoml.load(f)
build_system = pp_toml.get("build-system")
else:
build_system = None
# The following cases must use PEP 517
# We check for use_pep517 being non-None and falsey because that means
# the user explicitly requested --no-use-pep517. The value 0 as
@ -171,46 +169,3 @@ def resolve_pyproject_toml(
check = ["setuptools>=40.8.0", "wheel"]
return (requires, backend, check)
def load_pyproject_toml(
use_pep517, # type: Optional[bool]
pyproject_toml, # type: str
setup_py, # type: str
req_name # type: str
):
# type: (...) -> Optional[Tuple[List[str], str, List[str]]]
"""Load the pyproject.toml file.
Parameters:
use_pep517 - Has the user requested PEP 517 processing? None
means the user hasn't explicitly specified.
pyproject_toml - Location of the project's pyproject.toml file
setup_py - Location of the project's setup.py file
req_name - The name of the requirement we're processing (for
error reporting)
Returns:
None if we should use the legacy code path, otherwise a tuple
(
requirements from pyproject.toml,
name of PEP 517 backend,
requirements we should check are installed after setting
up the build environment
)
"""
has_pyproject = os.path.isfile(pyproject_toml)
has_setup = os.path.isfile(setup_py)
if has_pyproject:
build_system = read_pyproject_toml(pyproject_toml)
else:
build_system = None
return resolve_pyproject_toml(
build_system=build_system,
has_pyproject=has_pyproject,
has_setup=has_setup,
use_pep517=use_pep517,
req_name=req_name,
)