def test_install_req_from_string_invalid_requirement(self) -> None: """ Requirement strings that cannot be parsed by packaging.requirements.Requirement raise an InstallationError. """ with pytest.raises(InstallationError) as excinfo: install_req_from_req_string("http:/this/is/invalid") assert str(excinfo.value) == ("Invalid requirement: 'http:/this/is/invalid'")
def test_install_req_from_string_with_comes_from_without_link(self) -> None: """ Test to make sure that install_req_from_string succeeds when called with URL (PEP 508) and comes_from does not have a link. """ # Test with a PEP 508 url install string: wheel_url = ( "https://download.pytorch.org/whl/cu90/" "torch-1.0.0-cp36-cp36m-win_amd64.whl" ) install_str = "torch@ " + wheel_url # Dummy numpy "comes_from" requirement without link: comes_from = InstallRequirement(Requirement("numpy>=1.15.0"), comes_from=None) # Attempt install from install string comes: install_req = install_req_from_req_string(install_str, comes_from=comes_from) assert isinstance(install_req, InstallRequirement) assert isinstance(install_req.comes_from, InstallRequirement) assert install_req.comes_from.link is None assert install_req.link is not None assert install_req.link.url == wheel_url assert install_req.req is not None assert install_req.req.url == wheel_url assert install_req.is_wheel
def build_requirement_information( name: str, parent: Optional[InstallationCandidate] ) -> List["PreferenceInformation"]: install_requirement = install_req_from_req_string(name) # RequirementInformation is typed as a tuple, but it is a namedtupled. # https://github.com/sarugaku/resolvelib/blob/7bc025aa2a4e979597c438ad7b17d2e8a08a364e/src/resolvelib/resolvers.pyi#L20-L22 requirement_information: "PreferenceInformation" = RequirementInformation( requirement=SpecifierRequirement( install_requirement), # type: ignore[call-arg] parent=parent, ) return [requirement_information]
def add_req(subreq, extras_requested): sub_install_req = install_req_from_req_string( str(subreq), req_to_install, isolated=self.isolated, wheel_cache=self.wheel_cache, use_pep517=self.use_pep517, ) parent_req_name = req_to_install.name to_scan_again, add_to_parent = requirement_set.add_requirement( sub_install_req, parent_req_name=parent_req_name, extras_requested=extras_requested ) if parent_req_name and add_to_parent: self._discovered_dependencies[parent_req_name].append(add_to_parent) more_reqs.extend(to_scan_again)
def test_install_req_from_string_without_comes_from(self): """ Test to make sure that install_req_from_string succeeds when called with URL (PEP 508) but without comes_from. """ # Test with a PEP 508 url install string: wheel_url = ("https://download.pytorch.org/whl/cu90/" "torch-1.0.0-cp36-cp36m-win_amd64.whl") install_str = "torch@ " + wheel_url install_req = install_req_from_req_string(install_str) assert isinstance(install_req, InstallRequirement) assert install_req.link.url == wheel_url assert install_req.req.url == wheel_url assert install_req.comes_from is None assert install_req.is_wheel
def add_req(subreq, extras_requested): sub_install_req = install_req_from_req_string( str(subreq), req_to_install, isolated=self.isolated, wheel_cache=self.wheel_cache, use_pep517=self.use_pep517 ) parent_req_name = req_to_install.name to_scan_again, add_to_parent = requirement_set.add_requirement( sub_install_req, parent_req_name=parent_req_name, extras_requested=extras_requested, ) if parent_req_name and add_to_parent: self._discovered_dependencies[parent_req_name].append( add_to_parent ) more_reqs.extend(to_scan_again)