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

inspection: improve package info error message #2997

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Changes from all commits
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
40 changes: 28 additions & 12 deletions poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@


class PackageInfoError(ValueError):
def __init__(self, path): # type: (Union[Path, str]) -> None
def __init__(
self, path, *reasons
): # type: (Union[Path, str], *Union[BaseException, str]) -> None
reasons = (
"Unable to determine package info for path: {}".format(str(path)),
) + reasons
super(PackageInfoError, self).__init__(
"Unable to determine package info for path: {}".format(str(path))
"\n\n".join(str(msg).strip() for msg in reasons if msg)
)


Expand Down Expand Up @@ -290,12 +295,14 @@ def from_setup_files(cls, path): # type: (Path) -> PackageInfo
:param path: Path to `setup.py` file
"""
if not cls.has_setup_files(path):
raise PackageInfoError(path)
raise PackageInfoError(
path, "No setup files (setup.py, setup.cfg) was found."
)

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

python_requires = result["python_requires"]
if python_requires is None:
Expand Down Expand Up @@ -328,7 +335,10 @@ def from_setup_files(cls, path): # type: (Path) -> PackageInfo

if not (info.name and info.version) and not info.requires_dist:
# there is nothing useful here
raise PackageInfoError(path)
raise PackageInfoError(
path,
"No core metadata (name, version, requires-dist) could be retrieved.",
)

return info

Expand Down Expand Up @@ -474,15 +484,21 @@ def _pep517_metadata(cls, path): # type (Path) -> PackageInfo
cls._log("PEP517 build failed: {}".format(e), level="debug")
setup_py = path / "setup.py"
if not setup_py.exists():
raise PackageInfoError(path)
raise PackageInfoError(
path,
e,
"No fallback setup.py file was found to generate egg_info.",
)

cwd = Path.cwd()
os.chdir(path.as_posix())
try:
venv.run("python", "setup.py", "egg_info")
return cls.from_metadata(path)
except EnvCommandError:
raise PackageInfoError(path)
except EnvCommandError as fbe:
raise PackageInfoError(
path, "Fallback egg_info generation failed.", fbe
)
finally:
os.chdir(cwd.as_posix())

Expand All @@ -493,7 +509,7 @@ def _pep517_metadata(cls, path): # type (Path) -> PackageInfo
return info

# if we reach here, everything has failed and all hope is lost
raise PackageInfoError(path)
raise PackageInfoError(path, "Exhausted all core metadata sources.")

@classmethod
def from_directory(
Expand Down Expand Up @@ -572,8 +588,8 @@ def from_bdist(cls, path): # type: (Path) -> PackageInfo

try:
return cls._from_distribution(pkginfo.BDist(str(path)))
except ValueError:
raise PackageInfoError(path)
except ValueError as e:
raise PackageInfoError(path, e)

@classmethod
def from_path(cls, path): # type: (Path) -> PackageInfo
Expand Down