Skip to content

Commit 4276811

Browse files
authored
inspection: improve package info error message (#2997)
1 parent 09071b0 commit 4276811

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

poetry/inspection/info.py

+28-12
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@
4343

4444

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

5156

@@ -290,12 +295,14 @@ def from_setup_files(cls, path): # type: (Path) -> PackageInfo
290295
:param path: Path to `setup.py` file
291296
"""
292297
if not cls.has_setup_files(path):
293-
raise PackageInfoError(path)
298+
raise PackageInfoError(
299+
path, "No setup files (setup.py, setup.cfg) was found."
300+
)
294301

295302
try:
296303
result = SetupReader.read_from_directory(path)
297-
except Exception:
298-
raise PackageInfoError(path)
304+
except Exception as e:
305+
raise PackageInfoError(path, e)
299306

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

329336
if not (info.name and info.version) and not info.requires_dist:
330337
# there is nothing useful here
331-
raise PackageInfoError(path)
338+
raise PackageInfoError(
339+
path,
340+
"No core metadata (name, version, requires-dist) could be retrieved.",
341+
)
332342

333343
return info
334344

@@ -463,15 +473,21 @@ def _pep517_metadata(cls, path): # type (Path) -> PackageInfo
463473
cls._log("PEP517 build failed: {}".format(e), level="debug")
464474
setup_py = path / "setup.py"
465475
if not setup_py.exists():
466-
raise PackageInfoError(path)
476+
raise PackageInfoError(
477+
path,
478+
e,
479+
"No fallback setup.py file was found to generate egg_info.",
480+
)
467481

468482
cwd = Path.cwd()
469483
os.chdir(path.as_posix())
470484
try:
471485
venv.run("python", "setup.py", "egg_info")
472486
return cls.from_metadata(path)
473-
except EnvCommandError:
474-
raise PackageInfoError(path)
487+
except EnvCommandError as fbe:
488+
raise PackageInfoError(
489+
path, "Fallback egg_info generation failed.", fbe
490+
)
475491
finally:
476492
os.chdir(cwd.as_posix())
477493

@@ -482,7 +498,7 @@ def _pep517_metadata(cls, path): # type (Path) -> PackageInfo
482498
return info
483499

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

487503
@classmethod
488504
def from_directory(
@@ -561,8 +577,8 @@ def from_bdist(cls, path): # type: (Path) -> PackageInfo
561577

562578
try:
563579
return cls._from_distribution(pkginfo.BDist(str(path)))
564-
except ValueError:
565-
raise PackageInfoError(path)
580+
except ValueError as e:
581+
raise PackageInfoError(path, e)
566582

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

0 commit comments

Comments
 (0)