def make_self_candidate(self, editable: bool = True) -> Candidate: req = parse_requirement(pip_shims.path_to_url(self.root.as_posix()), editable) req.name = self.meta.name return Candidate(req, self.environment, name=self.meta.name, version=self.meta.version)
def direct_url(self) -> dict[str, Any] | None: """PEP 610 direct_url.json data""" req = self.req if isinstance(req, VcsRequirement): if req.editable: assert self.ireq.source_dir return _filter_none({ "url": pip_shims.path_to_url(self.ireq.source_dir), "dir_info": { "editable": True }, "subdirectory": req.subdirectory, }) return _filter_none({ "url": url_without_fragments(req.repo), "vcs_info": _filter_none({ "vcs": req.vcs, "requested_revision": req.ref, "commit_id": self.revision, }), "subdirectory": req.subdirectory, }) elif isinstance(req, FileRequirement): if req.is_local_dir: return _filter_none({ "url": url_without_fragments(req.url), "dir_info": _filter_none({"editable": req.editable or None}), "subdirectory": req.subdirectory, }) url = expand_env_vars_in_auth( req.url.replace( "${PROJECT_ROOT}", self.environment.project.root.as_posix(). lstrip( # type: ignore "/"), )) with self.environment.get_finder() as finder: hash_cache = self.environment.project.make_hash_cache() hash_cache.session = finder.session # type: ignore return _filter_none({ "url": url_without_fragments(url), "archive_info": { "hash": hash_cache.get_hash(pip_shims.Link(url)).replace( ":", "=") }, "subdirectory": req.subdirectory, }) else: return None
def _parse_url(self) -> None: if not self.url: if self.path: self.url = path_to_url(self.path.as_posix()) else: try: self.path = Path(url_to_path(self.url)) except AssertionError: pass self._parse_name_from_url()
def _parse_url(self) -> None: if not self.url: if self.path: self.url = path_to_url(self.path.as_posix().replace( "${PROJECT_ROOT}", ".")) else: try: self.path = Path( url_to_path( self.url.replace( "${PROJECT_ROOT}", Path(".").absolute().as_posix().lstrip("/"), ))) except AssertionError: pass self._parse_name_from_url()
def test_sdist_candidate_with_wheel_cache(project, mocker): file_link = Link( path_to_url((FIXTURES / "artifacts/demo-0.0.1.tar.gz").as_posix())) built_path = (FIXTURES / "artifacts/demo-0.0.1-py2.py3-none-any.whl").as_posix() wheel_cache = project.make_wheel_cache() cache_path = wheel_cache.get_path_for_link(file_link) if not Path(cache_path).exists(): Path(cache_path).mkdir(parents=True) shutil.copy2(built_path, cache_path) req = parse_requirement(file_link.url) downloader = mocker.patch("pdm.models.pip_shims.unpack_url") prepared = Candidate(req).prepare(project.environment) prepared.prepare_metadata() downloader.assert_not_called() assert Path(prepared.wheel) == Path(cache_path) / Path(built_path).name prepared.wheel = None builder = mocker.patch("pdm.builders.WheelBuilder.build") wheel = prepared.build() builder.assert_not_called() assert Path(wheel) == Path(cache_path) / Path(built_path).name
), ( 'pip @ https://github.com/pypa/pip/archive/1.3.1.zip ; python_version > "3.4"', 'pip @ https://github.com/pypa/pip/archive/1.3.1.zip; python_version > "3.4"', ), ( "git+http://git.example.com/MyProject.git@master#egg=MyProject", "MyProject @ git+http://git.example.com/MyProject.git@master", ), ( "https://github.com/pypa/pip/archive/1.3.1.zip", None, ), ( (FIXTURES / "projects/demo").as_posix(), "demo @ " + path_to_url((FIXTURES / "projects/demo")), ), ( (FIXTURES / "artifacts/demo-0.0.1-py2.py3-none-any.whl").as_posix(), "demo @ " + path_to_url((FIXTURES / "artifacts/demo-0.0.1-py2.py3-none-any.whl")), ), ( (FIXTURES / "projects/demo").as_posix() + "[security]", "demo[security] @ " + path_to_url((FIXTURES / "projects/demo")), ), ( 'requests; python_version=="3.7.*"', 'requests; python_version == "3.7.*"', ), (