def satisfyVersion( name, version_required, available, search_paths, working_directory, update_installed=None, type='module' # or 'target' ): ''' returns a Component/Target for the specified version (either to an already installed copy (from the available list, or from disk), or to a newly downloaded one), or None if the version could not be satisfied. update_installed = None / 'Update' None: prevent any attempt to look for new versions if the component/target already exists Update: replace any existing version with the newest available, if the newest available has a higher version ''' r = satisfyFromAvailable(name, available, type=type) if r is not None: if not sourceparse.parseSourceURL(version_required).semanticSpecMatches(r.getVersion()): raise access_common.SpecificationNotMet( "Installed %s %s doesn't match specification %s" % (type, name, version_required) ) return r r = satisfyVersionFromSearchPaths(name, version_required, search_paths, update_installed == 'Update', type=type) if r is not None: return r return satisfyVersionByInstalling(name, version_required, working_directory, type=type)
def satisfyDep(dspec): try: r = provider( dspec, available_components, search_dirs, modules_path, update_installed, self ) if r and not sourceparse.parseSourceURL(dspec.versionReq()).semanticSpecMatches(r.getVersion()): shrinkwrap_msg = '' if dspec.isShrinkwrapped(): shrinkwrap_msg = 'shrinkwrap on ' msg = 'does not meet specification %s required by %s%s' % ( dspec.versionReq(), shrinkwrap_msg, self.getName() ) logger.debug('%s %s', r.getName(), msg) r.setError(msg) return r except access_common.Unavailable as e: errors.append(e) self.dependencies_failed = True except vcs.VCSError as e: errors.append(e) self.dependencies_failed = True
def satisfyVersionFromSearchPaths(name, version_required, search_paths, update=False, type='module'): ''' returns a Component/Target for the specified version, if found in the list of search paths. If `update' is True, then also check for newer versions of the found component, and update it in-place (unless it was installed via a symlink). ''' v = None try: local_version = searchPathsFor( name, sourceparse.parseSourceURL(version_required).semanticSpec(), search_paths, type) except pack.InvalidDescription as e: logger.error(e) return None logger.debug("%s %s locally" % (('found', 'not found')[not local_version], name)) if local_version: if update and not local_version.installedLinked(): #logger.debug('attempt to check latest version of %s @%s...' % (name, version_required)) v = latestSuitableVersion(name, version_required, registry=_registryNamespaceForType(type)) if local_version: local_version.setLatestAvailable(v) # if we don't need to update, then we're done if local_version.installedLinked() or not local_version.outdated(): logger.debug("satisfy component from directory: %s" % local_version.path) # if a component exists (has a valid description file), and either is # not outdated, or we are not updating if name != local_version.getName(): raise Exception( 'Component %s found in incorrectly named directory %s (%s)' % (local_version.getName(), name, local_version.path)) return local_version # otherwise, we need to update the installed component logger.info('update outdated: %s@%s -> %s' % (name, local_version.getVersion(), v)) # must rm the old component before continuing fsutils.rmRf(local_version.path) return _satisfyVersionByInstallingVersion(name, version_required, local_version.path, v, type=type) return None
def satisfyVersionFromSearchPaths(name, version_required, search_paths, update=False, type='module', inherit_shrinkwrap=None): ''' returns a Component/Target for the specified version, if found in the list of search paths. If `update' is True, then also check for newer versions of the found component, and update it in-place (unless it was installed via a symlink). ''' v = None try: local_version = searchPathsFor( name, sourceparse.parseSourceURL(version_required).semanticSpec(), search_paths, type, inherit_shrinkwrap = inherit_shrinkwrap ) except pack.InvalidDescription as e: logger.error(e) return None logger.debug("%s %s locally" % (('found', 'not found')[not local_version], name)) if local_version: if update and not local_version.installedLinked(): #logger.debug('attempt to check latest version of %s @%s...' % (name, version_required)) v = latestSuitableVersion(name, version_required, registry=_registryNamespaceForType(type)) if local_version: local_version.setLatestAvailable(v) # if we don't need to update, then we're done if local_version.installedLinked() or not local_version.outdated(): logger.debug("satisfy component from directory: %s" % local_version.path) # if a component exists (has a valid description file), and either is # not outdated, or we are not updating if name != local_version.getName(): raise Exception('Component %s found in incorrectly named directory %s (%s)' % ( local_version.getName(), name, local_version.path )) return local_version # otherwise, we need to update the installed component logger.info('update outdated: %s@%s -> %s' % ( name, local_version.getVersion(), v )) # must rm the old component before continuing fsutils.rmRf(local_version.path) return _satisfyVersionByInstallingVersion( name, version_required, local_version.path, v, type=type, inherit_shrinkwrap=inherit_shrinkwrap ) return None
def satisfyDep(dspec): try: r = provider(dspec, available_components, search_dirs, modules_path, update_installed, self.getName()) if r and not sourceparse.parseSourceURL(dspec.version_req).semanticSpecMatches(r.getVersion()): logger.debug( "%s does not meet specification %s required by %s" % (r.getName(), dspec.version_req, self.getName()) ) r.setError("does not meet specification %s required by %s" % (dspec.version_req, self.getName())) return r except access_common.Unavailable as e: errors.append(e) self.dependencies_failed = True except vcs.VCSError as e: errors.append(e) self.dependencies_failed = True
def satisfyDep(dspec): try: r = provider(dspec, available_components, search_dirs, modules_path, update_installed, self.getName()) if r and not sourceparse.parseSourceURL( dspec.version_req).semanticSpecMatches(r.getVersion()): logger.debug( '%s does not meet specification %s required by %s' % (r.getName(), dspec.version_req, self.getName())) r.setError( 'does not meet specification %s required by %s' % (dspec.version_req, self.getName())) return r except access_common.Unavailable as e: errors.append(e) self.dependencies_failed = True except vcs.VCSError as e: errors.append(e) self.dependencies_failed = True
def satisfyVersion( name, version_required, available, search_paths, working_directory, update_installed=None, type='module' # or 'target' ): ''' returns a Component/Target for the specified version (either to an already installed copy (from the available list, or from disk), or to a newly downloaded one), or None if the version could not be satisfied. update_installed = None / 'Update' None: prevent any attempt to look for new versions if the component/target already exists Update: replace any existing version with the newest available, if the newest available has a higher version ''' r = satisfyFromAvailable(name, available, type=type) if r is not None: if not sourceparse.parseSourceURL( version_required).semanticSpecMatches(r.getVersion()): raise access_common.SpecificationNotMet( "Installed %s %s doesn't match specification %s" % (type, name, version_required)) return r r = satisfyVersionFromSearchPaths(name, version_required, search_paths, update_installed == 'Update', type=type) if r is not None: return r return satisfyVersionByInstalling(name, version_required, working_directory, type=type)
def remoteComponentFor(name, version_required, registry='modules'): ''' Return a RemoteComponent sublclass for the specified component name and source url (or version specification) Raises an exception if any arguments are invalid. ''' vs = sourceparse.parseSourceURL(version_required) if vs.source_type == 'registry': if registry not in ('modules', 'targets'): raise Exception('no known registry namespace "%s"' % registry) return registry_access.RegistryThing.createFromSource( vs, name, registry=registry) elif vs.source_type == 'github': return github_access.GithubComponent.createFromSource(vs, name) elif vs.source_type == 'git': return git_access.GitComponent.createFromSource(vs, name) elif vs.source_type == 'hg': return hg_access.HGComponent.createFromSource(vs, name) else: raise Exception('unsupported module source: "%s"' % vs.source_type)
def remoteComponentFor(name, version_required, registry='modules'): ''' Return a RemoteComponent sublclass for the specified component name and source url (or version specification) Raises an exception if any arguments are invalid. ''' vs = sourceparse.parseSourceURL(version_required) if vs.source_type == 'registry': if registry not in ('modules', 'targets'): raise Exception('no known registry namespace "%s"' % registry) return registry_access.RegistryThing.createFromSource( vs, name, registry=registry ) elif vs.source_type == 'github': return github_access.GithubComponent.createFromSource(vs, name) elif vs.source_type == 'git': return git_access.GitComponent.createFromSource(vs, name) elif vs.source_type == 'hg': return hg_access.HGComponent.createFromSource(vs, name) else: raise Exception('unsupported module source: "%s"' % vs.source_type)