Python pkg_resources.Requirement.parse() Examples
The following are 30
code examples of pkg_resources.Requirement.parse().
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
pkg_resources.Requirement
, or try the search function
.
Example #1
Source File: config.py From checkQC with GNU General Public License v3.0 | 6 votes |
def get_logging_config_dict(config_path): """ Loads the specified logger config. This is useful when CheckQC is used more like a library, so that the default logging configuration can be overridden. :param config_path: Path to the logging config. :returns: The content of the logging config file. """ try: if not config_path: config_path = resource_filename(Requirement.parse('checkQC'), 'checkQC/default_config/logger.yaml') log.info("No logging config file specified, using default config from {}.".format(config_path)) with open(config_path) as stream: return yaml.load(stream) except FileNotFoundError as e: log.error("Could not find config file: {}".format(e)) raise e
Example #2
Source File: util.py From syntheticmass with Apache License 2.0 | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #3
Source File: util.py From jbox with MIT License | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #4
Source File: util.py From planespotter with MIT License | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #5
Source File: package.py From py2deb with MIT License | 6 votes |
def find_egg_info_file(self, pattern=''): """ Find pip metadata files in unpacked source distributions. When pip unpacks a source distribution archive it creates a directory ``pip-egg-info`` which contains the package metadata in a declarative and easy to parse format. This method finds such metadata files. :param pattern: The :mod:`glob` pattern to search for (a string). :returns: A list of matched filenames (strings). """ full_pattern = os.path.join(self.requirement.source_directory, 'pip-egg-info', '*.egg-info', pattern) logger.debug("Looking for %r file(s) using pattern %r ..", pattern, full_pattern) matches = glob.glob(full_pattern) if len(matches) > 1: msg = "Source distribution directory of %s (%s) contains multiple *.egg-info directories: %s" raise Exception(msg % (self.requirement.project_name, self.requirement.version, concatenate(matches))) elif matches: logger.debug("Matched %s: %s.", pluralize(len(matches), "file", "files"), concatenate(matches)) return matches[0] else: logger.debug("No matching %r files found.", pattern)
Example #6
Source File: util.py From kobo-predict with BSD 2-Clause "Simplified" License | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #7
Source File: util.py From Flask-P2P with MIT License | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #8
Source File: util.py From Financial-Portfolio-Flask with MIT License | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #9
Source File: diagd.py From ambassador with Apache License 2.0 | 6 votes |
def get_templates_dir(): res_dir = None try: # this will fail when not in a distribution res_dir = resource_filename(Requirement.parse("ambassador"), "templates") except: pass maybe_dirs = [ res_dir, os.path.join(os.path.dirname(__file__), "..", "templates") ] for d in maybe_dirs: if d and os.path.isdir(d): return d raise FileNotFoundError # Get the Flask app defined early. Setup happens later.
Example #10
Source File: utils.py From requirementslib with MIT License | 6 votes |
def clean_requires_python(candidates): """Get a cleaned list of all the candidates with valid specifiers in the `requires_python` attributes.""" all_candidates = [] sys_version = ".".join(map(str, sys.version_info[:3])) from packaging.version import parse as parse_version py_version = parse_version(os.environ.get("PIP_PYTHON_VERSION", sys_version)) for c in candidates: requires_python = _get_requires_python(c) if requires_python: # Old specifications had people setting this to single digits # which is effectively the same as '>=digit,<digit+1' if requires_python.isdigit(): requires_python = ">={0},<{1}".format( requires_python, int(requires_python) + 1 ) try: specifierset = SpecifierSet(requires_python) except InvalidSpecifier: continue else: if not specifierset.contains(py_version): continue all_candidates.append(c) return all_candidates
Example #11
Source File: test_server.py From anybox.recipe.odoo with GNU Affero General Public License v3.0 | 6 votes |
def test_install_scripts_indirect_soft_deps(self, exc=None): """If a requirement is soft and indirect, UserError is properly raised. """ self.make_recipe(version='local %s' % os.path.join(TEST_DIR, 'odoo10'), gunicorn='direct', with_devtools='true') self.recipe.version_detected = "10.0" somereq = 'zztest-req' softreq = 'zztest-softreq' self.recipe.missing_deps_instructions[softreq] = ( "This is an expected condition in this test.") self.recipe.soft_requirements = (softreq,) self.recipe.b_options['offline'] = 'true' # the key fact is that the requirement that exc is about is not # in recipe.options['eggs'] self.exc_distributions[somereq] = MissingDistribution( Requirement.parse(softreq), []) self.assertRaises(UserError, self.install_scripts, extra_requirements=(somereq,))
Example #12
Source File: config.py From ambassador with Apache License 2.0 | 6 votes |
def get_jsonschema_validator(self, apiVersion, kind) -> Optional[Validator]: # Do we have a JSONSchema on disk for this? schema_path = os.path.join(self.schema_dir_path, apiVersion, f"{kind}.schema") try: schema = json.load(open(schema_path, "r")) # Note that we'll never get here if the schema doesn't parse. if schema: self.logger.debug(f"using validate_with_jsonschema for getambassador.io/{apiVersion} {kind}") # Ew. Early binding for Python lambdas is kinda weird. return typecast(Validator, lambda resource, schema=schema: self.validate_with_jsonschema(resource, schema)) except OSError: self.logger.debug(f"no schema at {schema_path}, not validating") return None except json.decoder.JSONDecodeError as e: self.logger.warning(f"corrupt schema at {schema_path}, skipping ({e})") return None # This can't actually happen -- the only way to get here is to have an uncaught # exception. But it shuts up mypy so WTF. return None
Example #13
Source File: toolchain.py From calmjs with GNU General Public License v2.0 | 6 votes |
def transpile_modname_source_target(self, spec, modname, source, target): """ The function that gets called by compile_transpile_entry for processing the provided JavaScript source file provided by some Python package through the transpiler instance. """ if not isinstance(self.transpiler, BaseUnparser): _deprecation_warning( 'transpiler callable assigned to %r must be an instance of ' 'calmjs.parse.unparsers.base.BaseUnparser by calmjs-4.0.0; ' 'if the original transpile behavior is to be retained, the ' 'subclass may instead override this method to call ' '`simple_transpile_modname_source_target` directly, as ' 'this fallback behavior will be removed by calmjs-4.0.0' % ( self, ) ) return self.simple_transpile_modname_source_target( spec, modname, source, target) # do the new thing here. return self._transpile_modname_source_target( spec, modname, source, target)
Example #14
Source File: toolchain.py From calmjs with GNU General Public License v2.0 | 6 votes |
def _init_entry_point(self, entry_point): if not entry_point.dist: logger.warning( 'entry_points passed to %s for registration must provide a ' 'distribution with a project name; registration of %s skipped', cls_to_name(type(self)), entry_point, ) return key = entry_point.dist.project_name self.records.setdefault(key, []) # have to cast the entry point into try: requirement = Requirement.parse(str(entry_point).split('=', 1)[1]) except ValueError as e: logger.warning( "entry_point '%s' cannot be registered to %s due to the " "following error: %s", entry_point, cls_to_name(type(self)), e ) else: self.records[key].append(requirement)
Example #15
Source File: util.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #16
Source File: utils.py From pydeface with MIT License | 6 votes |
def initial_checks(template=None, facemask=None): """Initial sanity checks.""" if template is None: template = resource_filename(Requirement.parse("pydeface"), "pydeface/data/mean_reg2mean.nii.gz") if facemask is None: facemask = resource_filename(Requirement.parse("pydeface"), "pydeface/data/facemask.nii.gz") if not os.path.exists(template): raise Exception('Missing template: %s' % template) if not os.path.exists(facemask): raise Exception('Missing face mask: %s' % facemask) if 'FSLDIR' not in os.environ: raise Exception("FSL must be installed and " "FSLDIR environment variable must be defined.") sys.exit(2) return template, facemask
Example #17
Source File: util.py From telegram-robot-rss with Mozilla Public License 2.0 | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #18
Source File: haros.py From haros with MIT License | 6 votes |
def _analyse_parser(self, parser): parser.add_argument("-r", "--use-repos", action = "store_true", help = "use repository information") parser.add_argument("-p", "--project-file", help = ("package index file (default: " "packages below current dir)")) parser.add_argument("-n", "--parse-nodes", action = "store_true", help = "parse C++/Python nodes (slow)") parser.add_argument("--env", action = "store_true", help = "use a copy of current environment") parser.add_argument("-d", "--data-dir", help = "load/export using the given directory") parser.add_argument("--no-cache", action = "store_true", help = "do not use available caches") parser.add_argument("--junit-xml-output", action='store_true', help = "output JUnit XML report file(s)") parser.add_argument("--minimal-output", action='store_true', help = "output only those file(s) required to view the report") group = parser.add_mutually_exclusive_group() group.add_argument("-w", "--whitelist", nargs = "*", help = "execute only these plugins") group.add_argument("-b", "--blacklist", nargs = "*", help = "skip these plugins") parser.set_defaults(command = self.command_analyse)
Example #19
Source File: haros.py From haros with MIT License | 6 votes |
def parse_arguments(self, argv = None): parser = ArgumentParser(prog = "haros", description = "ROS quality assurance.") parser.add_argument("--home", help=("HAROS data and config directory (default: " + self.haros_dir)) parser.add_argument("--config", help=("HAROS config location (default: " + self.haros_dir + "configs.yaml")) parser.add_argument("--debug", action = "store_true", help = "set debug logging") parser.add_argument("-c", "--cwd", help = "change current directory before running") subparsers = parser.add_subparsers() self._init_parser(subparsers.add_parser("init")) self._full_parser(subparsers.add_parser("full")) self._analyse_parser(subparsers.add_parser("analyse")) self._export_parser(subparsers.add_parser("export")) self._viz_parser(subparsers.add_parser("viz")) self._parse_parser(subparsers.add_parser("parse")) return parser.parse_args(argv)
Example #20
Source File: haros.py From haros with MIT License | 6 votes |
def command_parse(self, args): if not self.initialised: self.initialised = self._init_haros_dir(overwrite=False) if args.data_dir and not os.path.isdir(args.data_dir): raise ValueError("Not a directory: " + args.data_dir) project_file = args.project_file or self.index_path if not os.path.isfile(project_file): raise ValueError("Not a file: " + project_file) if args.ws: if not os.path.isdir(args.ws): raise ValueError("Not a directory: " + args.ws) parse = HarosParseRunner(self.haros_dir, self.config_path, project_file, args.data_dir, log=self.log, run_from_source=self.run_from_source, use_repos=args.use_repos, ws=args.ws, copy_env=args.env, use_cache=(not args.no_cache), junit_xml_output=args.junit_xml_output, minimal_output=args.minimal_output) return parse.run()
Example #21
Source File: cmd.py From netwrok-server with MIT License | 6 votes |
def create(): parser = argparse.ArgumentParser(description='Create a new NetWrok server.') parser.add_argument("name", help="The name of the new netwrok instance.") parser.add_argument("dsn", help="Connection string to an empty PostgreSQL database.") args = parser.parse_args() print("Connecting to: " + args.dsn) try: conn = psycopg2.connect(args.dsn) except Exception as e: print(e) return sql_file = resource_filename(Requirement.parse("NetWrok-Server"),"netwrok/data/schema.sql") print("Creating new DB schema...") cursor = conn.cursor() cursor.execute("begin") cursor.execute(open(sql_file, "r").read()) config["DB"]["WRITE"] = args.dsn config["DB"]["READ"] = [args.dsn,args.dsn,args.dsn] new_config_file = "netwrok_%s.ini"%args.name print("Writing config file to: %s"%new_config_file) with open(new_config_file, "w") as nf: json.dump(config, nf, sort_keys=True, indent=4, separators=(',', ': ')) cursor.execute("commit") cursor.close() print("You can now start the server with 'netwrok %s'"%new_config_file)
Example #22
Source File: util.py From PhonePi_SampleServer with MIT License | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #23
Source File: util.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #24
Source File: utils.py From enterprise with MIT License | 6 votes |
def make_ecc_interpolant(): """ Make interpolation function from eccentricity file to determine number of harmonics to use for a given eccentricity. :returns: interpolant """ pth = resource_filename(Requirement.parse("libstempo"), "libstempo/ecc_vs_nharm.txt") fil = np.loadtxt(pth) return interp1d(fil[:, 0], fil[:, 1]) # get interpolant for eccentric binaries
Example #25
Source File: util.py From Ansible with MIT License | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #26
Source File: util.py From ImageFusion with MIT License | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #27
Source File: utils.py From pipenv with MIT License | 6 votes |
def clean_requires_python(candidates): """Get a cleaned list of all the candidates with valid specifiers in the `requires_python` attributes.""" all_candidates = [] sys_version = ".".join(map(str, sys.version_info[:3])) from packaging.version import parse as parse_version py_version = parse_version(os.environ.get("PIP_PYTHON_VERSION", sys_version)) for c in candidates: requires_python = _get_requires_python(c) if requires_python: # Old specifications had people setting this to single digits # which is effectively the same as '>=digit,<digit+1' if requires_python.isdigit(): requires_python = ">={0},<{1}".format( requires_python, int(requires_python) + 1 ) try: specifierset = SpecifierSet(requires_python) except InvalidSpecifier: continue else: if not specifierset.contains(py_version): continue all_candidates.append(c) return all_candidates
Example #28
Source File: config.py From checkQC with GNU General Public License v3.0 | 6 votes |
def _get_config_file(config_path): """ Load the content of the config file. If no config_path is specified, get the default of config file. :param config_path: path to the config file or None :returns: the content of the config file """ try: if not config_path: config_path = resource_filename(Requirement.parse('checkQC'), 'checkQC/default_config/config.yaml') log.info("No config file specified, using default config from {}.".format(config_path)) with open(config_path) as stream: return yaml.load(stream) except FileNotFoundError as e: log.error("Could not find config file: {}".format(e)) raise e
Example #29
Source File: util.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def matches_requirement(req, wheels): """List of wheels matching a requirement. :param req: The requirement to satisfy :param wheels: List of wheels to search. """ try: from pkg_resources import Distribution, Requirement except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") req = Requirement.parse(req) selected = [] for wf in wheels: f = wf.parsed_filename dist = Distribution(project_name=f.group("name"), version=f.group("ver")) if dist in req: selected.append(wf) return selected
Example #30
Source File: ah_bootstrap.py From banzai with GNU General Public License v3.0 | 5 votes |
def _do_upgrade(self, dist): # Build up a requirement for a higher bugfix release but a lower minor # release (so API compatibility is guaranteed) next_version = _next_version(dist.parsed_version) req = pkg_resources.Requirement.parse( '{0}>{1},<{2}'.format(DIST_NAME, dist.version, next_version)) package_index = PackageIndex(index_url=self.index_url) upgrade = package_index.obtain(req) if upgrade is not None: return self._do_download(version=upgrade.version)