예제 #1
0
 def specForDependency(name, version_spec, istest):
     shrinkwrap = self.getShrinkwrapMapping()
     shrinkwrap_version_req = None
     if name in shrinkwrap:
         # exact version, and pull from registry:
         shrinkwrap_version_req = shrinkwrap[name]
         logger.debug('respecting %s shrinkwrap version %s for %s',
                      self.getName(), shrinkwrap_version_req, name)
     return pack.DependencySpec(
         name,
         version_spec,
         istest,
         shrinkwrap_version_req=shrinkwrap_version_req,
         specifying_module=self.getName())
예제 #2
0
파일: target.py 프로젝트: bearsh/yotta
 def baseTargetSpec(self):
     ''' returns pack.DependencySpec for the base target of this target (or
         None if this target does not inherit from another target.
     '''
     inherits = self.description.get('inherits', {})
     if len(inherits) == 1:
         return pack.DependencySpec(
             list(inherits.items())[0][0],
             list(inherits.items())[0][1])
     elif len(inherits) > 1:
         logger.error(
             'target %s specifies multiple base targets, but only one is allowed',
             self.getName())
     return None
예제 #3
0
 def baseTargetSpec(self):
     ''' returns pack.DependencySpec for the base target of this target (or
         None if this target does not inherit from another target.
     '''
     inherits = self.description.get('inherits', {})
     if len(inherits) == 1:
         name, version_req = list(inherits.items())[0]
         shrinkwrap_version_req = self.getShrinkwrapMapping('targets').get(name, None)
         if shrinkwrap_version_req is not None:
             logger.debug(
                 'respecting shrinkwrap version %s for %s', shrinkwrap_version_req, name
             )
         return pack.DependencySpec(
             name,
             version_req,
             shrinkwrap_version_req = shrinkwrap_version_req
         )
     elif len(inherits) > 1:
         logger.error('target %s specifies multiple base targets, but only one is allowed', self.getName())
     return None
예제 #4
0
파일: target.py 프로젝트: bearsh/yotta
def getDerivedTarget(target_name_and_version,
                     targets_path,
                     application_dir=None,
                     install_missing=True,
                     update_installed=False,
                     additional_config=None):
    # access, , get components, internal
    from yotta.lib import access
    from yotta.lib import access_common
    ''' Get the specified target description, optionally ensuring that it (and
        all dependencies) are installed in targets_path.

        Returns (DerivedTarget, errors), or (None, errors) if the leaf target
        could not be found/installed.
    '''
    logger.debug('satisfy target: %s' % target_name_and_version)
    if ',' in target_name_and_version:
        name, ver = target_name_and_version.split(',')
        dspec = pack.DependencySpec(name, ver)
    else:
        dspec = pack.DependencySpec(target_name_and_version, "*")

    leaf_target = None
    previous_name = dspec.name
    search_dirs = [targets_path]
    target_hierarchy = []
    errors = []
    while True:
        t = None
        try:
            if install_missing:
                t = access.satisfyVersion(
                    name=dspec.name,
                    version_required=dspec.versionReq(),
                    available=target_hierarchy,
                    search_paths=search_dirs,
                    working_directory=targets_path,
                    update_installed=('Update' if update_installed else None),
                    type='target')
            else:
                t = access.satisfyVersionFromSearchPaths(
                    name=dspec.name,
                    version_required=dspec.versionReq(),
                    search_paths=search_dirs,
                    type='target')
        except access_common.Unavailable as e:
            errors.append(e)
        if not t:
            if install_missing:
                logger.error('could not install target %s for %s' %
                             (dspec, previous_name))
            break
        else:
            target_hierarchy.append(t)
            previous_name = dspec.name
            assert (isinstance(t, Target))
            dspec = t.baseTargetSpec()  #pylint: disable=no-member
            if not leaf_target:
                leaf_target = t
            if dspec is None:
                break
    if leaf_target is None:
        return (None, errors)
    # if we have a valid target, try to load the app-specific config data (if
    # any):
    app_config = {}
    if application_dir is not None:
        app_config_fname = os.path.join(application_dir, App_Config_File)
        if os.path.exists(app_config_fname):
            try:
                app_config = ordered_json.load(app_config_fname)
            except Exception as e:
                errors.append(
                    Exception("Invalid application config.json: %s" % (e)))
    return (DerivedTarget(leaf_target, target_hierarchy[1:], app_config,
                          additional_config), errors)