def sources_for_test_packages(data_directory): sources = Sources() package_names = ["setupcfg-package"] for package_name in package_names: sources.add( package_name, PathSource( os.path.join(data_directory, f"{package_name}-1.0.tar.gz")), ) return sources
def _update_path(self, requirement_name: str, requirement_path: str) -> str: if not os.path.isabs(requirement_path): requirement_path = os.path.relpath( os.path.join(os.path.dirname(self._original_path), requirement_path) ) self._sources.add(requirement_name, PathSource(path=requirement_path)) if os.path.isabs(requirement_path): return requirement_path else: absolute_path = os.path.abspath(requirement_path) return absolute_path
def source(self) -> PackageSource: if self._url.startswith("git+"): return self._handle_git_source(self._url[4:]) elif self._url.startswith("git://"): return self._handle_git_source(self._url) elif self._url.startswith("hg+"): return self._handle_hg_source(self._url[3:]) elif self.url_scheme() == "file": return PathSource(path=self.url_path()) else: return UrlSource(url=self._url, logger=self._logger)
def source(self) -> PackageSource: if self._url.startswith("git+"): return self._handle_git_source(self._url[4:]) elif self._url.startswith("git://"): return self._handle_git_source(self._url) elif self._url.startswith("hg+"): return self._handle_hg_source(self._url[3:]) elif self._url.startswith("http://"): return UrlSource(url=self._url) elif self._url.startswith("https://"): return UrlSource(url=self._url) else: return PathSource(path=self._url)
def generate_setuptools_package( self, name: str, version: str = "1.0", install_requires: List[str] = [], extras_require: Dict[str, List[str]] = {}, ) -> SourceDistribution: with TemporaryDirectory() as directory_path_string: build_directory: Path = Path(directory_path_string) self._generate_setup_py(build_directory, name=name, version=version) self._generate_setup_cfg( build_directory, name=name, version=version, install_requires=install_requires, extras_require=extras_require, ) self._generate_python_module( build_directory, name=name, ) built_distribution_archive = self._build_package( build_directory=build_directory, name=name, version=version) source_distribution = SourceDistribution.from_archive( built_distribution_archive, logger=self._logger, requirement_parser=self._requirement_parser, ) self._move_package_target_directory(built_distribution_archive) self._sources.add( name=name, source=PathSource( path=str(self._get_distribution_path(name, version))), ) return source_distribution
def path_source(tmpdir_factory): path = Path(str(tmpdir_factory.mktemp("path_source") / "test.txt")) path.write_text("") return PathSource(str(path))
def test_path_source_paths_with_one_segement_get_dot_appended_for_nix(): source = PathSource("segment") assert source.nix_expression() == "segment/."
def path_source(): return PathSource("/test/path")
def test_items_returns_length_on_tuple_for_one_entry(sources): sources.add("testitem", PathSource("/test/path")) assert len(sources.items()) == 1
def test_sources_can_be_merged(sources, other_sources): assert "testsource" not in sources other_sources.add("testsource", PathSource("/test/path")) sources.update(other_sources) assert "testsource" in sources
def test_sources_can_be_queried_by_name(sources): source = PathSource("/test/path") sources.add("testsource", source) assert sources["testsource"] is source
def test_sources_can_be_added_to(sources): sources.add("testsource", PathSource("/test/path")) assert "testsource" in sources
def _handle_requirements_path(self, name: str, path: str) -> str: self._sources.add(name, PathSource(path)) return os.path.abspath(path)
def source(self) -> PathSource: return PathSource(path=self._path)