def chkpython(self, req): chk = VersionPredicate(req) ver = '.'.join([str(v) for v in sys.version_info[:2]]) if not chk.satisfied_by(ver): print >> sys.stderr, "Invalid python version, expected %s" % req return False return True
def fulfills_version_requirement(cls): """ Return whether the executable fulfills version_requirement. When this is called, cls.executable_path has been set. """ if not(cls.version_args is not None and cls.version_re and cls.version_requirement): return True cls.executable_version = cls.get_executable_version() if cls.executable_version: predicate = VersionPredicate( '{} ({})'.format(cls.name.replace('-', '.'), cls.version_requirement) ) if predicate.satisfied_by(cls.executable_version): persist.debug( '{}: ({}) satisfied by {}' .format(cls.name, cls.version_requirement, cls.executable_version) ) return True else: util.printf( 'WARNING: {} deactivated, version requirement ({}) not fulfilled by {}' .format(cls.name, cls.version_requirement, cls.executable_version) ) return False
def fulfills_version_requirement(cls): """ Return whether the executable fulfills version_requirement. When this is called, cls.executable_path has been set. """ if not(cls.version_args is not None and cls.version_re and cls.version_requirement): return True cls.executable_version = cls.get_executable_version() if cls.executable_version: predicate = VersionPredicate( '{} ({})'.format(cls.name.replace('-', '.'), cls.version_requirement) ) if predicate.satisfied_by(cls.executable_version): logger.info( '{}: ({}) satisfied by {}' .format(cls.name, cls.version_requirement, cls.executable_version) ) return True else: warning = '{} deactivated, version requirement ({}) not fulfilled by {}' msg = warning.format(cls.name, cls.version_requirement, cls.executable_version) logger.warning(msg) return False
def get_instance(name: str, version_constraint: Optional[str] = None, url: Optional[str] = None, config: Optional[JobExecutorConfig] = None) -> 'JobExecutor': """ Returns an instance of a `JobExecutor`. :param name: The name of the executor to return. :param version_constraint: A version constraint for the executor in the form '(' <op> <version>[, <op> <version[, ...]] ')', such as "( > 0.0.2, != 0.0.4)". :param url: An optional URL to pass to the `JobExecutor` instance. :param config: An optional configuration to pass to the instance. :return: A JobExecutor. """ # might want to cache these instances if url and config match if name not in JobExecutor._executors: raise ValueError('No such executor "{}"'.format(name)) versions = JobExecutor._executors[name] ecls = None # type: Optional[Type[JobExecutor]] if version_constraint: pred = VersionPredicate('x(' + version_constraint + ')') for entry in reversed(versions): if pred.satisfied_by(entry.version): ecls = entry.ecls else: ecls = versions[-1].ecls if ecls is None: raise ValueError('No executor "{}" found to satisfy "{}"'.format(name, version_constraint)) else: return ecls(url=url, config=config)
def check_python(self, req): chk = VersionPredicate(req) ver = '.'.join([str(v) for v in sys.version_info[:2]]) if not chk.satisfied_by(ver): log.error("Invalid python version, expected %s" % req) return False return True
def check_python(self, req): chk = VersionPredicate(req) ver = '.'.join([str(v) for v in sys.version_info[:2]]) if not chk.satisfied_by(ver): log.error("Invalid python version, expected {0}".format(req)) return False return True
def _check_dependency(self, depstring): # @TODO: use pkg_resources' parse_requirements and Requirement # if available: # for r in parse_requirements('gsdview >= 0.5'): # return r.key in self.plugins and avail_ver in r depstring = depstring.strip() if not depstring: return True modules = dict(self.plugins) # @TODO: use a cleaner way to provide extra modules for check #import gsdview #modules['gsdview'] = gsdview try: vp = VersionPredicate(depstring) except ValueError as e: # @TODO: remove dependency from self._app _log.error('invalid version predicate "%s": %s', depstring, e) return False if vp.name in modules: try: return vp.satisfied_by(modules[vp.name].version) except ValueError as e: _log.warning(str(e)) # , exc_info=True) return False else: return False
def fulfills_version_requirement(cls): """ Return whether the executable fulfills version_requirement. When this is called, cls.executable_path has been set. """ if not (cls.version_args is not None and cls.version_re and cls.version_requirement): return True cls.executable_version = cls.get_executable_version() if cls.executable_version: predicate = VersionPredicate('{} ({})'.format( cls.name.replace('-', '.'), cls.version_requirement)) if predicate.satisfied_by(cls.executable_version): logger.info('{}: ({}) satisfied by {}'.format( cls.name, cls.version_requirement, cls.executable_version)) return True else: warning = '{} deactivated, version requirement ({}) not fulfilled by {}' msg = warning.format(cls.name, cls.version_requirement, cls.executable_version) logger.warning(msg) return False
def _check_dependency(self, depstring): # @TODO: use pkg_resources' parse_requirements and Requirement # if available: # for r in parse_requirements('gsdview >= 0.5'): # return r.key in self.plugins and avail_ver in r depstring = depstring.strip() if not depstring: return True modules = dict(self.plugins) # @TODO: use a cleaner way to provide extra modules for check #import gsdview #modules['gsdview'] = gsdview try: vp = VersionPredicate(depstring) except ValueError as e: # @TODO: remove dependency from self._app self._app.logger.error('invalid version preficate "%s": %s' % ( depstring, e)) return False if vp.name in modules: try: return vp.satisfied_by(modules[vp.name].version) except ValueError as e: logging.warning(str(e)) # , exc_info=True) return False else: return False
def version_satisfies(cls, req): """Return whether executable_version satisfies req.""" if req not in cls.__version_satisfies: predicate = VersionPredicate('SublimeLinter.scalac ({})'.format(req)) cls.__version_satisfies[req] = predicate.satisfied_by(cls.executable_version) return cls.__version_satisfies[req]
def version_satisfies(cls, req): """Return whether executable_version satisfies req.""" if req not in cls.__version_satisfies: predicate = VersionPredicate( 'SublimeLinter.scalac ({})'.format(req)) cls.__version_satisfies[req] = predicate.satisfied_by( cls.executable_version) return cls.__version_satisfies[req]
def chkmodule(self, req): chk = VersionPredicate(req) try: mod = __import__(chk.name) except: print >> sys.stderr, "Missing mandatory %s python module" % chk.name return False for v in ['__version__', 'version']: ver = getattr(mod, v, None) break try: if ver and not chk.satisfied_by(ver): print >> sys.stderr, "Invalid module version, expected %s" % req return False except: pass return True
def check_package(self, req): chk = VersionPredicate(req) try: mod = __import__(chk.name) except: log.error("Missing mandatory {0} python module".format(chk.name)) return False for v in [ '__version__', 'version' ]: ver = getattr(mod, v, None) break try: if ver and not chk.satisfied_by(ver): log.error("Invalid module version, expected {0}".format(req)) return False except: pass return True
def chkmodule(self, req): chk = VersionPredicate(req) try: mod = __import__(chk.name) except: print >> sys.stderr, "Missing mandatory %s python module" % chk.name return False for v in [ '__version__', 'version' ]: ver = getattr(mod, v, None) break try: if ver and not chk.satisfied_by(ver): print >> sys.stderr, "Invalid module version, expected %s" % req return False except: pass return True
def check_package(self, req): chk = VersionPredicate(req) try: mod = __import__(chk.name) except: log.error("Missing mandatory {0} python module".format(chk.name)) return False for v in ['__version__', 'version']: ver = getattr(mod, v, None) break try: if ver and not chk.satisfied_by(ver): log.error("Invalid module version, expected {0}".format(req)) return False except: pass return True
def mpi_predicate(predicate): from mpi4py import MPI def key(s): s = s.replace(' ', '') s = s.replace('/', '') s = s.replace('-', '') s = s.replace('Microsoft', 'MS') return s.lower() vp = VersionPredicate(key(predicate)) if vp.name == 'mpi': name, version = 'mpi', MPI.Get_version() version = version + (0,) else: name, version = MPI.get_vendor() if vp.name == key(name): if vp.satisfied_by('%d.%d.%d' % version): return vp return None
def __init__(self, url_map, predicate): """ urlmap -- required for the BaseConverter predicate -- version predicate matching the parameter using VersionPredicate from distutils. """ super(VersionConverter, self).__init__(url_map) self.predicate = VersionPredicate('{} ({})'.format('foo.bar', predicate)) self.regex = r'(\d+)\.(\d+)(\.(\d+))?([ab](\d+))?'
def __init__(self, specification): try: predicate = VersionPredicate(specification) except (ValueError, AttributeError) as error: LOG.debug('unsuccessfull predicate compilation (%s); trying regexp check', error) super(VersionCheckFactory, self).__init__(specification) else: LOG.debug('using predicate: %s', predicate) self.check = predicate.satisfied_by
def skipMPI(predicate, *conditions): from mpi4py import MPI def key(s): s = s.replace(' ', '') s = s.replace('/', '') s = s.replace('-', '') s = s.replace('Microsoft', 'MS') return s.lower() vp = VersionPredicate(key(predicate)) if vp.name == 'mpi': name, version = 'mpi', MPI.Get_version() version = version + (0,) else: name, version = MPI.get_vendor() if vp.name == key(name): if vp.satisfied_by('%d.%d.%d' % version): if not conditions or any(conditions): return unittest.skip(str(vp)) return unittest.skipIf(False, '')
def _get_plugin_class( name: str, version_constraint: Optional[str], type: str, store: Dict[str, List[_VersionEntry[T]]]) -> _VersionEntry[T]: if name not in store: raise ValueError('No such {} "{}". Available {}s: {}'.format( type, name, type, _get_names(store))) versions = store[name] selected = None if version_constraint: pred = VersionPredicate('x(' + version_constraint + ')') for entry in reversed(versions): if pred.satisfied_by(entry.version): selected = entry else: selected = versions[-1] if selected is None: raise ValueError('No {} "{}" found to satisfy "{}"'.format( type, name, version_constraint)) elif selected.exc is not None: raise ValueError('Unable to load {} {}'.format(type, name)) from selected.exc else: return selected
def get_use_deps(deps): preds = [] for dep in deps: vp = VersionPredicate(dep) if vp.name not in USE_LIST: continue if len(vp.pred) > 1: raise Exception("it's too complicated for me, sorry :(") if len(vp.pred) == 1: sign, version = vp.pred[0] if sign not in use_bind: # XXX it's bad, needs to see how to work with other sign raise Exception( "i don't know how FreeBSD package works with it :(") add = str(version) + use_bind[sign] else: add = 'yes' preds.append('%s=%s' % (USE_LIST[vp.name], add)) return "\n".join(preds)
def get_run_deps(deps): preds = [] for dep in deps: vp = VersionPredicate(dep) if vp.name in USE_LIST: continue name, path = get_package_path(vp.name) if len(vp.pred) > 1: raise Exception("it's too complicated for me, sorry :(") if len(vp.pred) == 1: sign, version = vp.pred[0] if sign not in ver_bind: # XXX it's bad, needs to see how to work with other sign raise Exception( "i don't know how FreeBSD package works with it :(") add = ver_bind[sign] + str(version) else: add = '' preds.append('%s%s:${PORTSDIR}%s' % (name, add, path)) return " \\\n\t\t".join(preds)
class VersionConverter(BaseConverter): """ Convert and match version using StrictVersion.version_re as a regular expression and VersionPredicate as a comparison from distutils. """ def __init__(self, url_map, predicate): """ urlmap -- required for the BaseConverter predicate -- version predicate matching the parameter using VersionPredicate from distutils. """ super(VersionConverter, self).__init__(url_map) self.predicate = VersionPredicate('{} ({})'.format('foo.bar', predicate)) self.regex = r'(\d+)\.(\d+)(\.(\d+))?([ab](\d+))?' def to_python(self, value): value = StrictVersion(value) if self.predicate.satisfied_by(value): return value raise ValidationError()
def _check_dependency(self, depstring): # @TODO: use pkg_resources' parse_requirements and Requirement # if available: # for r in parse_requirements('gsdview >= 0.5'): # return r.key in self.plugins and avail_ver in r depstring = depstring.strip() if not depstring: return True modules = dict(self.plugins) # @TODO: use a cleaner way to provide extra modules for check #import gsdview #modules['gsdview'] = gsdview try: vp = VersionPredicate(depstring) except ValueError, e: # @TODO: remove dependency from self._app self._app.logger.error('invalid version preficate "%s": %s' % (depstring, e)) return False
def extract(project, version): data = download(pypi_api(project), JSON) if version and version[0] not in '<>!=': project_sub, version = f'{version} '.split(' ', 1) else: project_sub = None if version.strip(): version = f'({version})' version = VersionPredicate(f'{project}{version}') if version.pred: releases = sorted( ((StrictVersion(key), key) for key in data['releases']), key=lambda r: r[0], reverse=True) for release, key in releases: if stable_sp and release.prerelease: continue if version.satisfied_by(release): dists = sorted(data['releases'][key], key=lambda d: d['python_version'], reverse=True) break else: dists = data['urls'] dist_type = None for dist in dists: if dist['packagetype'] in ('bdist_wheel', 'bdist_egg') and ( is_supported_tags_1(dist['filename']) or is_supported_tags_2(dist['filename'])): dist_type = dist['packagetype'] break if not dist_type: for dist in dists: if dist['python_version'] == 'source': dist_type = dist['packagetype'] break url = dist['url'] filename = dist['filename'] if project_sub: filename = filename.replace(project, project_sub) while True: filename = filename.rpartition('.')[0] if not filename.endswith('.tar'): filename += '.egg' if os.path.exists(filename): return else: break sum = '|'.join(('sha256', dist['digests']['sha256'])) filepath = download(url, dist['filename'], sum) if filepath.endswith(('tar.gz', 'tar.xz', 'tar.bz2')): os.system(f'{_7z} e {filepath} {to_null}') os.remove(filepath) filepath = filepath.rpartition('.')[0] if filepath.endswith(('whl', 'egg', 'tar', 'zip')): os.system(f'{_7z} x -y {filepath} {to_null}') try: os.remove('@PaxHeader') except FileNotFoundError: pass os.remove(filepath) if filepath.endswith(('tar', 'zip')): # This is source code, may require a complicated installation process. # But in most cases, just pack it is okay. name = filepath[:-4] updir = '..' if os.path.exists(os.path.join(name, 'src')): name = os.path.join(name, 'src') updir = os.path.join('..', '..') for dirpath, dirnames, filenames in os.walk(name): for dirname in dirnames: old = os.path.join(dirpath, dirname) new = os.path.join(dirpath, updir, dirname) os.rename(old, new) for filename in filenames: if filename.startswith(('setup.', 'fuzz.')) or \ not filename.endswith('.py'): continue old = os.path.join(dirpath, filename) new = os.path.join(dirpath, updir, filename) os.rename(old, new) shutil.rmtree(filepath[:-4]) name = filepath.rpartition('.')[0] if project_sub: name = name.replace(project, project_sub) for dirpath, dirnames, filenames in os.walk('.'): for dirname in dirnames: if dirname != project_sub: filepath = os.path.join(dirpath, dirname) shutil.rmtree(filepath, True) for filename in filenames: if not filename.endswith('.egg'): filepath = os.path.join(dirpath, filename) os.remove(filepath) break return name
def extract(project, version): data = download(pypi_api(project), JSON) if version: version = VersionPredicate('%s(%s)' % (project, version)) if version.pred: releases = sorted(data['releases'].keys(), key=lambda r: StrictVersion(r), reverse=True) for release in releases: if stable_sp and NOTSTABLE(release): continue if version.satisfied_by(release): dists = data['releases'][release] break else: dists = data['urls'] dist_type = None for dist in dists: if ((py_ver in dist['python_version'].replace('.', '') and py_arch in dist['filename']) or 'py3-none-any' in dist['filename']) and \ dist['packagetype'] in ('bdist_wheel', 'bdist_egg'): dist_type = dist['packagetype'] break if not dist_type: for dist in dists: if dist['python_version'] == 'source': dist_type = dist['packagetype'] break url = dist['url'] filename = fn = dist['filename'] while True: fn = fn.rpartition('.')[0] if not fn.endswith('.tar'): fn += '.egg' if os.path.exists(fn): return else: break sum = '|'.join(('sha256', dist['digests']['sha256'])) filepath = download(url, filename, sum) if filepath.endswith('tar.gz'): cmd = '{7z} e {file} {to_null}'.format(file=filepath, **params_7z) os.system(cmd) os.remove(filepath) filepath = filepath[:-3] if filepath.endswith(('whl', 'egg', 'tar', 'zip')): cmd = '{7z} x {file} {to_null}'.format(file=filepath, **params_7z) os.system(cmd) os.remove(filepath) if filepath.endswith('tar'): # This is source code, may require a complicated installation process. # But in most cases, just pack it is okay. name = filepath[:-4] updir = '..' if os.path.exists(os.path.join(name, 'src')): name = os.path.join(name, 'src') updir = os.path.join('..', '..') for dirpath, dirnames, filenames in os.walk(name): for dirname in dirnames: old = os.path.join(dirpath, dirname) new = os.path.join(dirpath, updir, dirname) os.rename(old, new) for filename in filenames: if filename.startswith('setup.') or \ filename.endswith('.sh'): continue old = os.path.join(dirpath, filename) new = os.path.join(dirpath, updir, filename) os.rename(old, new) shutil.rmtree(filepath[:-4]) return filepath.rpartition('.')[0]
def extract(project, version): data = download(pypi_api(project), JSON) try: project_sub, version = split_provision(version) except ValueError: project_sub = None if version: version = VersionPredicate(f'{project}({version})') if version.pred: releases = sorted(data['releases'].keys(), key=lambda r: StrictVersion(r), reverse=True) for release in releases: if stable_sp and NOTSTABLE(release): continue if version.satisfied_by(release): dists = data['releases'][release] break else: dists = data['urls'] dist_type = None for dist in dists: if ((py_ver in dist['python_version'].replace('.', '') and py_arch in dist['filename']) or 'py3-none-any' in dist['filename']) and \ dist['packagetype'] in ('bdist_wheel', 'bdist_egg'): dist_type = dist['packagetype'] break if not dist_type: for dist in dists: if dist['python_version'] == 'source': dist_type = dist['packagetype'] break url = dist['url'] filename = fn = dist['filename'] if project_sub: filename = fn = filename.replace(project, project_sub) while True: fn = fn.rpartition('.')[0] if not fn.endswith('.tar'): fn += '.egg' if os.path.exists(fn): return else: break sum = '|'.join(('sha256', dist['digests']['sha256'])) filepath = download(url, filename, sum) if filepath.endswith(('tar.gz', 'tar.xz', 'tar.bz2')): os.system(f'{_7z} e {filepath} {to_null}') os.remove(filepath) filepath = filepath.rpartition('.')[0] if filepath.endswith(('whl', 'egg', 'tar', 'zip')): os.system(f'{_7z} x -y {filepath} {to_null}') try: os.remove('@PaxHeader') except FileNotFoundError: pass os.remove(filepath) if filepath.endswith(('tar', 'zip')): # This is source code, may require a complicated installation process. # But in most cases, just pack it is okay. name = filepath[:-4] updir = '..' if os.path.exists(os.path.join(name, 'src')): name = os.path.join(name, 'src') updir = os.path.join('..', '..') for dirpath, dirnames, filenames in os.walk(name): for dirname in dirnames: old = os.path.join(dirpath, dirname) new = os.path.join(dirpath, updir, dirname) os.rename(old, new) for filename in filenames: if filename.startswith(('setup.', 'fuzz.')) or \ not filename.endswith('.py'): continue old = os.path.join(dirpath, filename) new = os.path.join(dirpath, updir, filename) os.rename(old, new) shutil.rmtree(filepath[:-4]) name = filepath.rpartition('.')[0] if project_sub: for dirpath, dirnames, filenames in os.walk('.'): for dirname in dirnames: if dirname != project_sub: filepath = os.path.join(dirpath, dirname) shutil.rmtree(filepath, True) for filename in filenames: if not filename.endswith('.egg'): filepath = os.path.join(dirpath, filename) os.remove(filepath) break return name