Python pip._internal.req.parse_requirements() Examples
The following are 30
code examples of pip._internal.req.parse_requirements().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pip._internal.req
, or try the search function
.
Example #1
Source File: dependencies.py From cobra with MIT License | 6 votes |
def find_python_pip(self, file_path): for requirement in file_path: if 'requirements.txt' in requirement: reqs = parse_requirements(filename=requirement, session=False) for r in reqs: module_ = r.name version_ = r.specifier self._framework.append(module_) self._result.update( { module_: { 'version': str(version_), 'format': 'python', } } ) elif 'package.json' in requirement: self.find_nodejs_npm([requirement])
Example #2
Source File: setup.py From modoboa-amavis with MIT License | 6 votes |
def get_requirements(requirements_file): """Use pip to parse requirements file.""" requirements = [] if path.isfile(requirements_file): for req in parse_requirements(requirements_file, session="hack"): try: # check markers, such as # # rope_py3k ; python_version >= '3.0' # if req.match_markers(): requirements.append(str(req.req)) except AttributeError: # pip >= 20.0.2 requirements.append(req.requirement) return requirements
Example #3
Source File: setup.py From modoboa-webmail with MIT License | 6 votes |
def get_requirements(requirements_file): """Use pip to parse requirements file.""" requirements = [] if path.isfile(requirements_file): for req in parse_requirements(requirements_file, session="hack"): try: # check markers, such as # # rope_py3k ; python_version >= '3.0' # if req.match_markers(): requirements.append(str(req.req)) except AttributeError: # pip >= 20.0.2 requirements.append(req.requirement) return requirements
Example #4
Source File: requirements.py From python-repo-tools with Apache License 2.0 | 6 votes |
def read_requirements(req_file): """Reads a requirements file. Args: req_file (str): Filename of requirements file """ items = list(parse_requirements(req_file, session={})) result = [] for item in items: # Get line number from item line_number = item.comes_from.split(req_file + ' (line ')[1][:-1] if item.req: item.req.marker = item.markers result.append((item.req, line_number)) else: result.append((item, line_number)) return result
Example #5
Source File: model.py From setupmeta with MIT License | 5 votes |
def get_pip(): """ Deprecated, see https://github.com/zsimic/setupmeta/issues/49 Left around for a while because some callers import this, they will have to adapt to pip 20.1+ """ try: # pip >= 19.3 from pip._internal.req import parse_requirements from pip._internal.network.session import PipSession return parse_requirements, PipSession except ImportError: pass try: # pip >= 10.0 from pip._internal.req import parse_requirements from pip._internal.download import PipSession return parse_requirements, PipSession except ImportError: pass try: # pip < 10.0 from pip.req import parse_requirements from pip.download import PipSession return parse_requirements, PipSession except ImportError: from setupmeta import warn warn("Can't find PipSession, won't auto-fill requirements") return None, None
Example #6
Source File: setup.py From AsyncLine with MIT License | 5 votes |
def install_requires(): file = WORK_DIR / "requirements.txt" install_reqs = parse_requirements(str(file), session='sync') return [str(ir.req) for ir in install_reqs]
Example #7
Source File: setup.py From gnsspy with MIT License | 5 votes |
def load_requirements(fname): reqs = parse_requirements(fname, session="test") return [str(ir.req) for ir in reqs]
Example #8
Source File: detection.py From cobra with MIT License | 5 votes |
def _requirements(self): requirements_txt = os.path.join(self.target_directory, 'requirements.txt') logger.debug(requirements_txt) if os.path.isfile(requirements_txt): requirements = parse_requirements(requirements_txt, session=False) self.requirements = [req.name.strip().lower() for req in requirements] logger.debug('requirements modules count: {count} ({modules})'.format(count=len(self.requirements), modules=','.join(self.requirements))) else: logger.debug('requirements.txt not found!') self.requirements = []
Example #9
Source File: setup.py From treadmill with Apache License 2.0 | 5 votes |
def _read_requires(filename): reqs = [] for inst_req in pip_req.parse_requirements(filename, session='no session'): req = str(inst_req.req) if inst_req.markers: req += '; %s' % inst_req.markers reqs.append(req) return reqs
Example #10
Source File: setup.py From surfdist with MIT License | 5 votes |
def load_requirements(fname): reqs = parse_requirements(fname, session="test") return [str(ir.req) for ir in reqs]
Example #11
Source File: setup.py From excelcy with MIT License | 5 votes |
def get_requirements(r: str): try: # for pip >= 10 from pip._internal.req import parse_requirements except ImportError: # for pip <= 9.0.3 from pip.req import parse_requirements # parse_requirements() returns generator of pip.req.InstallRequirement objects if os.path.exists(r): install_reqs = parse_requirements(r, session=pkg) return install_reqs return []
Example #12
Source File: uninstall.py From guildai with Apache License 2.0 | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = InstallRequirement.from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #13
Source File: uninstall.py From coffeegrindsize with MIT License | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = install_req_from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #14
Source File: uninstall.py From CogAlg with MIT License | 5 votes |
def run(self, options, args): session = self.get_default_session(options) reqs_to_uninstall = {} for name in args: req = install_req_from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #15
Source File: pip_compat.py From rules_pip with MIT License | 5 votes |
def parse_requirements( filename, session, finder=None, options=None, constraint=False, isolated=False ): for parsed_req in _parse_requirements( filename, session, finder=finder, options=options, constraint=constraint ): yield install_req_from_parsed_requirement(parsed_req, isolated=isolated)
Example #16
Source File: setup.py From cloudbrain with GNU Affero General Public License v3.0 | 5 votes |
def parse_reqs(req_type): reqs_file = os.path.join('requirements', '%s.txt' % req_type) install_reqs = parse_requirements(reqs_file, session=PipSession()) reqs = [str(ir.req) for ir in install_reqs] return reqs # Get requirements for all types
Example #17
Source File: uninstall.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = install_req_from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #18
Source File: uninstall.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = install_req_from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #19
Source File: uninstall.py From android_universal with MIT License | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = install_req_from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #20
Source File: uninstall.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = install_req_from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #21
Source File: uninstall.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = install_req_from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #22
Source File: uninstall.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = install_req_from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #23
Source File: uninstall.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = install_req_from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #24
Source File: uninstall.py From twitter-stock-recommendation with MIT License | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = InstallRequirement.from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) protect_pip_from_modification_on_windows( modifying_pip="pip" in reqs_to_uninstall ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #25
Source File: setup.py From VIP with MIT License | 5 votes |
def resource(*args): return os.path.join(os.path.abspath(os.path.join(__file__, os.pardir)), *args) # parse_requirements() returns generator of pip.req.InstallRequirement objects
Example #26
Source File: uninstall.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = InstallRequirement.from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #27
Source File: setup.py From aioalice with MIT License | 5 votes |
def get_requirements(filename=None): """ Read requirements from 'requirements.txt' :return: requirements :rtype: list """ if filename is None: filename = 'requirements.txt' file = WORK_DIR / filename install_reqs = parse_requirements(str(file), session='hack') return [str(ir.req) for ir in install_reqs]
Example #28
Source File: uninstall.py From Python24 with MIT License | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = InstallRequirement.from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #29
Source File: uninstall.py From FuYiSpider with Apache License 2.0 | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = InstallRequirement.from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()
Example #30
Source File: uninstall.py From FuYiSpider with Apache License 2.0 | 5 votes |
def run(self, options, args): with self._build_session(options) as session: reqs_to_uninstall = {} for name in args: req = InstallRequirement.from_line( name, isolated=options.isolated_mode, ) if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req for filename in options.requirements: for req in parse_requirements( filename, options=options, session=session): if req.name: reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( 'You must give at least one requirement to %(name)s (see ' '"pip help %(name)s")' % dict(name=self.name) ) for req in reqs_to_uninstall.values(): uninstall_pathset = req.uninstall( auto_confirm=options.yes, verbose=self.verbosity > 0, ) if uninstall_pathset: uninstall_pathset.commit()