我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pkg_resources.Requirement.parse()。
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
def setUp(self): file_path = resource_filename(Requirement.parse('search_google'), 'search_google/config.json') with open(file_path, 'r') as in_file: defaults = json.load(in_file) buildargs = { 'serviceName': 'customsearch', 'version': 'v1', 'developerKey': defaults['build_developerKey'] } cseargs = { 'q': 'google', 'num': 1, 'fileType': 'png', 'cx': defaults['cx'] } self.results = search_google.api.results(buildargs, cseargs) tempfile = TemporaryFile() self.tempfile = str(tempfile.name) tempfile.close() self.tempdir = str(TemporaryDirectory().name)
def load_yaml(self, filename, serialization, k8s=False): try: # XXX This is a bit of a hack -- yaml.safe_load_all returns a # generator, and if we don't use list() here, any exception # dealing with the actual object gets deferred ocount = 1 for obj in yaml.safe_load_all(serialization): if k8s: self.prep_k8s(filename, ocount, obj) else: self.objects_to_process.append((filename, ocount, obj)) ocount += 1 except Exception as e: # No sense letting one attribute with bad YAML take down the whole # gateway, so post the error but keep any objects we were able to # parse before hitting the error. self.filename = filename self.ocount = ocount self.post_error(RichStatus.fromError("%s: could not parse YAML" % filename))
def setUp(self): file_path = resource_filename(Requirement.parse('google_streetview'), 'google_streetview/config.json') with open(file_path, 'r') as in_file: defaults = json.load(in_file) params = [{ 'size': '600x300', # max 640x640 pixels 'location': '46.414382,10.013988', 'heading': '151.78', 'pitch': '-0.76', 'key': defaults['key'] }] self.results = google_streetview.api.results(params) tempfile = TemporaryFile() self.tempfile = str(tempfile.name) tempfile.close() self.tempdir = str(TemporaryDirectory().name)
def convert_package_names(package_names): """ Convert package names, which can be a string of a number of package names or requirements separated by spaces. """ results = [] errors = [] for name in ( package_names.split() if hasattr(package_names, 'split') else package_names): try: Requirement.parse(name) except ValueError: errors.append(name) else: results.append(name) return results, errors
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)
def copy_default_config_to_user_directory( basename, clobber=False, dst_dir='~/.config/scriptabit'): """ Copies the default configuration file into the user config directory. Args: basename (str): The base filename. clobber (bool): If True, the default will be written even if a user config already exists. dst_dir (str): The destination directory. """ dst_dir = os.path.expanduser(dst_dir) dst = os.path.join(dst_dir, basename) src = resource_filename( Requirement.parse("scriptabit"), os.path.join('scriptabit', basename)) if not os.path.exists(dst_dir): os.makedirs(dst_dir) if clobber or not os.path.isfile(dst): shutil.copy(src, dst)
def __get_plugin_manager(): """ Discovers and instantiates all plugins, returning a management object. Returns: yapsy.PluginManager: The plugin manager with the loaded plugins. """ # Build the manager plugin_manager = PluginManager() # the location of the plugins that ship with scriptabit package_plugin_path = resource_filename( Requirement.parse("scriptabit"), os.path.join('scriptabit', 'plugins')) # user plugin location user_plugin_path = __init_user_plugin_directory() # Set plugin locations plugin_manager.setPluginPlaces([package_plugin_path, user_plugin_path]) # Load all plugins plugin_manager.collectPlugins() return plugin_manager
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