diff --git a/poetry/inspection/info.py b/poetry/inspection/info.py index ec0c4a64123..260066cf7e5 100644 --- a/poetry/inspection/info.py +++ b/poetry/inspection/info.py @@ -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) ) @@ -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: @@ -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 @@ -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()) @@ -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( @@ -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