Skip to content

Commit

Permalink
remove the setup reader
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Mar 2, 2024
1 parent 658d964 commit 1d06c17
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 795 deletions.
74 changes: 5 additions & 69 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from poetry.utils.env import EnvCommandError
from poetry.utils.env import ephemeral_environment
from poetry.utils.helpers import extractall
from poetry.utils.setup_reader import SetupReader


if TYPE_CHECKING:
Expand Down Expand Up @@ -322,58 +321,6 @@ def _from_sdist_file(cls, path: Path) -> PackageInfo:

return info.update(new_info)

@staticmethod
def has_setup_files(path: Path) -> bool:
return any((path / f).exists() for f in SetupReader.FILES)

@classmethod
def from_setup_files(cls, path: Path) -> PackageInfo:
"""
Mechanism to parse package information from a `setup.[py|cfg]` file. This uses
the implementation at `poetry.utils.setup_reader.SetupReader` in order to parse
the file. This is not reliable for complex setup files and should only attempted
as a fallback.
:param path: Path to `setup.py` file
"""
if not cls.has_setup_files(path):
raise PackageInfoError(
path, "No setup files (setup.py, setup.cfg) was found."
)

try:
result = SetupReader.read_from_directory(path)
except Exception as e:
raise PackageInfoError(path, e)

python_requires = result["python_requires"]
if python_requires is None:
python_requires = "*"

requires = "".join(dep + "\n" for dep in result["install_requires"])
if result["extras_require"]:
requires += "\n"

for extra_name, deps in result["extras_require"].items():
requires += f"[{extra_name}]\n"

for dep in deps:
requires += dep + "\n"

requires += "\n"

requirements = parse_requires(requires)

info = cls(
name=result.get("name"),
version=result.get("version"),
summary=result.get("description", ""),
requires_dist=requirements,
requires_python=python_requires,
)

return info

@staticmethod
def _find_dist_info(path: Path) -> Iterator[Path]:
"""
Expand Down Expand Up @@ -472,16 +419,13 @@ def _get_poetry_package(path: Path) -> ProjectPackage | None:
return None

@classmethod
def from_directory(cls, path: Path, disable_build: bool = False) -> PackageInfo:
def from_directory(cls, path: Path) -> PackageInfo:
"""
Generate package information from a package source directory. If `disable_build`
is not `True` and introspection of all available metadata fails, the package is
attempted to be built in an isolated environment so as to generate required
metadata.
Generate package information from a package source directory. If introspection
of all available metadata fails, the package is attempted to be built in an
isolated environment so as to generate required metadata.
:param path: Path to generate package information from.
:param disable_build: If not `True` and setup reader fails, PEP 517 isolated
build is attempted in order to gather metadata.
"""
project_package = cls._get_poetry_package(path)
info: PackageInfo | None
Expand All @@ -492,10 +436,7 @@ def from_directory(cls, path: Path, disable_build: bool = False) -> PackageInfo:

if not info or info.requires_dist is None:
try:
if disable_build:
info = cls.from_setup_files(path)
else:
info = get_pep517_metadata(path)
info = get_pep517_metadata(path)
except PackageInfoError:
if not info:
raise
Expand Down Expand Up @@ -572,11 +513,6 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
"""
info = None

with contextlib.suppress(PackageInfoError):
info = PackageInfo.from_setup_files(path)
if all(x is not None for x in (info.version, info.name, info.requires_dist)):
return info

with ephemeral_environment(
flags={"no-pip": False, "no-setuptools": True, "no-wheel": True}
) as venv:
Expand Down
Loading

0 comments on commit 1d06c17

Please sign in to comment.