我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pip.req()。
def run(self, options, args): with self._build_session(options) as session: format_control = pip.index.FormatControl(set(), set()) wheel_cache = WheelCache(options.cache_dir, format_control) requirement_set = RequirementSet( build_dir=None, src_dir=None, download_dir=None, isolated=options.isolated_mode, session=session, wheel_cache=wheel_cache, ) for name in args: requirement_set.add_requirement( InstallRequirement.from_line( name, isolated=options.isolated_mode, wheel_cache=wheel_cache ) ) for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session, wheel_cache=wheel_cache): requirement_set.add_requirement(req) if not requirement_set.has_requirements: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) requirement_set.uninstall(auto_confirm=options.yes)
def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. """ links = [] reqs = [] for req in parse_requirements(requirements_file_path, session=False): if getattr(req, 'link', None): links.append(str(req.link)) reqs.append(str(req.req)) return (reqs, links)
def ireq(): return pip.req.InstallRequirement.from_line('reqwire==0.1a1')
def test_hashable_ireq_hashable(ireq): ireq2 = pip.req.InstallRequirement.from_line(str(ireq)) assert hash(ireq) != hash(ireq2) hireq = reqwire.helpers.requirements.HashableInstallRequirement.from_ireq( ireq=ireq) hireq2 = reqwire.helpers.requirements.HashableInstallRequirement.from_ireq( ireq=ireq2) assert hash(hireq) == hash(hireq2) assert hireq == hireq2
def test_format_requirement(req, expected): ireq = reqwire.helpers.requirements.HashableInstallRequirement.from_line(req) # noqa assert reqwire.helpers.requirements.format_requirement(ireq) == expected
def run(self): if self.blockchain == 'ethereum': install_reqs = parse_requirements('ethereum_requirements.txt', session=False) eth_reqs = [str(ir.req) for ir in install_reqs] reqs.append(eth_reqs) install(eth_reqs)
def _parse_requirements(filepath): pip_version = list(map(int, pkg_resources.get_distribution('pip').version.split('.')[:2])) if pip_version >= [6, 0]: raw = parse_requirements(filepath, session=pip.download.PipSession()) else: raw = parse_requirements(filepath) return [str(i.req) for i in raw]
def parse_requirement_file(req_file, constraint=False): """Returns dependencies parsed from a requirement file :param req_file: file to parse :param constraint: if file a constraints file :return: dictionary of dependencies """ if not os.path.exists(req_file): printer.warning('Requirement file "{}" not found'.format(req_file)) sys.exit() with open(req_file, 'r') as requirements_file: with tempfile.NamedTemporaryFile('r+', delete=False) as temp_file: requirements_lines = requirements_file.readlines() # Ignore links data = [ line for line in requirements_lines if not line.startswith('-r') and not line.startswith('-c') ] data = "".join(data) temp_file.write(data) processed_file_path = temp_file.name requirements = { item.name: item.req.specifier or None for item in pip.req.parse_requirements( filename=processed_file_path, session='session', constraint=constraint ) if isinstance(item, pip.req.InstallRequirement) } # Delete temporary file with contextlib.suppress(FileNotFoundError): os.remove(processed_file_path) return requirements