def test_parse_pyproject_toml(tmp_path): content = """[project] name = "foo" version = "0.1.0" requires-python = ">=3.6" dependencies = ["click", "requests"] [project.optional-dependencies] tui = ["rich"] """ tmp_path.joinpath("pyproject.toml").write_text(content) result = Setup("foo", "0.1.0", ["click", "requests"], {"tui": ["rich"]}, ">=3.6") assert Setup.from_directory(tmp_path) == result
def _check_installable(self) -> None: if not (self.path.joinpath("setup.py").exists() or self.path.joinpath("pyproject.toml").exists()): raise RequirementError( f"The local path '{self.path}' is not installable.") result = Setup.from_directory(self.path.absolute()) self.name = result.name
def get_metadata( self, allow_all_wheels: bool = True, raising: bool = False ) -> Optional[Metadata]: """Get the metadata of the candidate. For editable requirements, egg info are produced, otherwise a wheel is built. If raising is True, error will pop when the package fails to build. """ if self.metadata is not None: return self.metadata ireq = self.ireq if self.link and not ireq.link: ireq.link = self.link try: built = self.environment.build(ireq, self.hashes, allow_all_wheels) except BuildError: if raising: raise termui.logger.warn("Failed to build package, try parsing project files.") meta_dict = Setup.from_directory( Path(ireq.unpacked_source_directory) ).as_dict() meta_dict.update(summary="UNKNOWN") meta_dict["requires_python"] = meta_dict.pop("python_requires", None) self.metadata = Namespace(**meta_dict) else: if self.req.editable: if not self.req.is_local_dir and not self.req.is_vcs: raise RequirementError( "Editable installation is only supported for " "local directory and VCS location." ) sdist = get_sdist(built) self.metadata = sdist.metadata if sdist else None else: # It should be a wheel path. self.wheel = Wheel(built) self.metadata = self.wheel.metadata if not self.name: self.name = self.metadata.name self.req.name = self.name if not self.version: self.version = self.metadata.version self.link = ireq.link return self.metadata
def parse_metadata_from_source(src_dir: str) -> Distribution: setup = Setup.from_directory(Path(src_dir)) return MockDistribution(setup)
def test_parse_setup_py(content, result, tmp_path): tmp_path.joinpath("setup.py").write_text(content) assert Setup.from_directory(tmp_path) == result
import pytest from pdm.models.setup import Setup @pytest.mark.parametrize( "content, result", [ ( """[metadata] name = foo version = 0.1.0 """, Setup("foo", "0.1.0"), ), ( """[metadata] name = foo version = attr:foo.__version__ """, Setup("foo", "0.0.0"), ), ( """[metadata] name = foo version = 0.1.0 [options] python_requires = >=3.6 install_requires = click