def test_info_from_sdist(demo_sdist): info = PackageInfo.from_sdist(demo_sdist) demo_check_info(info)
def test_info_from_wheel(demo_wheel): info = PackageInfo.from_wheel(demo_wheel) demo_check_info(info)
def test_info_setup_complex_pep517_legacy(demo_setup_complex_pep517_legacy: Path): info = PackageInfo.from_directory(demo_setup_complex_pep517_legacy) demo_check_info(info, requires_dist={"package"})
def test_info_prefer_poetry_config_over_egg_info(): info = PackageInfo.from_directory( FIXTURE_DIR_INSPECTIONS / "demo_with_obsolete_egg_info" ) demo_check_info(info)
def test_info_setup_cfg(mocker: "MockerFixture", demo_setup_cfg: Path): spy = mocker.spy(VirtualEnv, "run") info = PackageInfo.from_directory(demo_setup_cfg) assert spy.call_count == 0 demo_check_info(info, requires_dist={"package"})
def test_info_setup_complex(demo_setup_complex: Path): info = PackageInfo.from_directory(demo_setup_complex) demo_check_info(info, requires_dist={"package"})
def test_info_from_requires_txt(): info = PackageInfo.from_metadata( FIXTURE_DIR_INSPECTIONS / "demo_only_requires_txt.egg-info" ) demo_check_info(info)
def test_info_from_setup_cfg(demo_setup_cfg: Path): info = PackageInfo.from_setup_files(demo_setup_cfg) demo_check_info(info, requires_dist={"package"})
def test_info_from_bdist(demo_wheel: Path): info = PackageInfo.from_bdist(demo_wheel) demo_check_info(info)
def test_info_from_poetry_directory(): info = PackageInfo.from_directory( FIXTURE_DIR_INSPECTIONS / "demo", disable_build=True ) demo_check_info(info)
def _get_release_info(self, name: str, version: str) -> dict: from poetry.inspection.info import PackageInfo self._log(f"Getting info for {name} ({version}) from PyPI", "debug") json_data = self._get(f"pypi/{name}/{version}/json") if json_data is None: raise PackageNotFound(f"Package [{name}] not found.") info = json_data["info"] data = PackageInfo( name=info["name"], version=info["version"], summary=info["summary"], platform=info["platform"], requires_dist=info["requires_dist"], requires_python=info["requires_python"], files=info.get("files", []), cache_version=str(self.CACHE_VERSION), ) try: version_info = json_data["releases"][version] except KeyError: version_info = [] for file_info in version_info: data.files.append({ "file": file_info["filename"], "hash": "sha256:" + file_info["digests"]["sha256"], }) if self._fallback and data.requires_dist is None: self._log("No dependencies found, downloading archives", level="debug") # No dependencies set (along with other information) # This might be due to actually no dependencies # or badly set metadata when uploading # So, we need to make sure there is actually no # dependencies by introspecting packages urls = defaultdict(list) for url in json_data["urls"]: # Only get sdist and wheels if they exist dist_type = url["packagetype"] if dist_type not in ["sdist", "bdist_wheel"]: continue urls[dist_type].append(url["url"]) if not urls: return data.asdict() info = self._get_info_from_urls(urls) data.requires_dist = info.requires_dist if not data.requires_python: data.requires_python = info.requires_python return data.asdict()
def _pep517_metadata(cls, path): try: return PackageInfo.from_setup_files(path) except PackageInfoError: pass return PackageInfo(name="demo", version="0.1.2")
def get_package_from_directory(cls, directory: Path) -> Package: return PackageInfo.from_directory(path=directory).to_package( root_dir=directory)
def test_info_no_setup_pkg_info_no_deps(): info = PackageInfo.from_directory(FIXTURE_DIR_INSPECTIONS / "demo_no_setup_pkg_info_no_deps") assert info.name == "demo" assert info.version == "0.1.0" assert info.requires_dist is None
def test_info_from_setup_py(): info = PackageInfo.from_setup_py(FIXTURE_DIR_INSPECTIONS / "demo_only_setup") demo_check_info(info)