Пример #1
0
    def update_local(self, path='.'):
        """Attempt to resolve all LOCAL dependencies in this IOTile by installing them into build/deps
        """

        tile = IOTile(path)
        if tile.release:
            raise ArgumentError(
                "Cannot update dependencies on a release mode tile that cannot have dependencies"
            )

        depdir = os.path.join(tile.folder, 'build', 'deps')

        #FIXME: Read resolver_settings.json file
        resolver_chain = DependencyResolverChain()
        reg = ComponentRegistry()

        for dep in tile.dependencies:

            # Check each dependency to see if it's local
            try:
                local_tile = reg.find_component(dep['name'])
                if local_tile.release:
                    continue
                if local_tile is not None:
                    result = resolver_chain.update_dependency(tile, dep)

            except ArgumentError:
                continue

            iprint("Resolving %s: %s" % (dep['name'], result))
Пример #2
0
    def run(self):
        component = os.path.abspath('.')
        deps = self._get_dependencies(component)
        reg = ComponentRegistry()

        found = []
        not_found = []

        for name in deps:
            try:
                tile = reg.find_component(name)
                found.append(tile)
            except ArgumentError:
                not_found.append(name)

        deplines = []

        for tile in found:
            deplines.append('- %s' % tile.name)

        for name in not_found:
            deplines.append('- %s (NOT INSTALLED)' % name)

        view = ViewList(deplines, 'dependencies-directive')

        node = docutils.nodes.paragraph()
        sphinx.util.nodes.nested_parse_with_titles(self.state, view, node)
        return node.children
Пример #3
0
    def check(self, depinfo, deptile, depsettings):
        from iotile.core.dev.registry import ComponentRegistry

        reg = ComponentRegistry()

        try:
            comp = reg.find_component(depinfo['name'])
        except ArgumentError:
            return True

        #If the component does not have a matching version, we cannot assess up-to-date-ness
        #FIXME: We should return that we cannot assess up to dateness, not that we are up to date
        reqver = depinfo['required_version']
        if not reqver.check(comp.parsed_version):
            return True

        #If the component in the registry has a higher version or a newer release date, it should
        #be updated
        if comp.parsed_version > deptile.parsed_version:
            return False

        if comp.release_date is not None and comp.release_date > deptile.release_date:
            return False

        return True
Пример #4
0
def find_proxy_plugin(component, plugin_name):
    """ Attempt to find a proxy plugin provided by a specifc component

    Args:
        component (string): The name of the component that provides the plugin
        plugin_name (string): The name of the plugin to load

    Returns:
        TileBuxProxPlugin: The plugin, if found, otherwise raises DataError
    """

    reg = ComponentRegistry()

    #Try to find plugin in an installed component, otherwise look through installed
    #packages
    try:
        comp = reg.find_component(component)

        plugins = comp.proxy_plugins()

        for plugin in plugins:
            objs = import_proxy(plugin, TileBusProxyPlugin)
            for obj in objs:
                if obj.__name__ == plugin_name:
                    return obj
    except ArgumentError:
        pass

    for entry in pkg_resources.iter_entry_points('iotile.proxy_plugin'):
        module = entry.load()
        objs = [
            obj for obj in itervalues(module.__dict__)
            if inspect.isclass(obj) and issubclass(obj, TileBusProxyPlugin)
            and obj != TileBusProxyPlugin
        ]
        for obj in objs:
            if obj.__name__ == plugin_name:
                return obj

    raise DataError(
        "Could not find proxy plugin module in registered components or installed distributions",
        component=component,
        name=plugin_name)
Пример #5
0
def find_proxy(component, proxy_name=None, obj_type=TileBusProxyObject):
    """
    Search through the registered component data base for a proxy or proxy plugin module provided by
    a specific component optionally having a specific name.

    Proxy modules must inherit from TileBusProxyObject. Proxy plugin modules must inherit from TileBusProxyPlugin
    """

    # Find all of the registered IOTile components and see if we need to add any proxies for them
    reg = ComponentRegistry()
    comp = reg.find_component(component)

    proxies = comp.proxy_modules()
    if len(proxies) != 1:
        raise DataError(
            "Attempting to find proxy module from component that does not provide exactly 1 proxy",
            proxies=proxies)

    proxy_mod = proxies[0]

    proxy_objs = import_proxy(proxy_mod, obj_type)

    if len(proxy_objs) == 0:
        raise DataError(
            "Specified component did not define any proxies but said that it did provide them",
            component=component)
    elif len(proxy_objs) > 1 and proxy_name is None:
        raise DataError(
            "Sepcific component defined multiple proxy objects and a name was not specified",
            component=component,
            proxies=proxy_objs)
    elif len(proxy_objs) == 1 and proxy_name is None:
        return proxy_objs[0]

    for obj in proxy_objs:
        if obj.__name__ == proxy_name:
            return obj

    raise DataError("Named proxy could not be found",
                    component=component,
                    proxies=proxy_objs,
                    desired_name=proxy_name)
Пример #6
0
def load_external_components(typesys):
    """Load all external types defined by iotile plugins.

    This allows plugins to register their own types for type annotations and
    allows all registered iotile components that have associated type libraries to
    add themselves to the global type system.
    """

    # Find all of the registered IOTile components and see if we need to add any type libraries for them
    from iotile.core.dev.registry import ComponentRegistry

    reg = ComponentRegistry()
    modules = reg.list_components()

    typelibs = reduce(lambda x, y: x+y, [reg.find_component(x).find_products('type_package') for x in modules], [])
    for lib in typelibs:
        if lib.endswith('.py'):
            lib = lib[:-3]

        typesys.load_external_types(lib)
Пример #7
0
    def _setup_proxies(self):
        """Load in proxy module objects for all of the registered components on this system."""

        # Find all of the registered IOTile components and see if we need to add any proxies for them
        reg = ComponentRegistry()
        modules = reg.list_components()

        proxies = reduce(
            lambda x, y: x + y,
            [reg.find_component(x).proxy_modules() for x in modules], [])
        proxy_classes = []
        for prox in proxies:
            proxy_classes += self._load_module_classes(prox,
                                                       TileBusProxyObject)

        # Find all installed proxy objects through registered entry points
        for entry in pkg_resources.iter_entry_points('iotile.proxy'):
            mod = entry.load()
            proxy_classes += [
                x for x in itervalues(mod.__dict__)
                if inspect.isclass(x) and issubclass(x, TileBusProxyObject)
                and x != TileBusProxyObject
            ]

        for obj in proxy_classes:
            if obj.__name__ in self._proxies:
                continue  #Don't readd proxies that we already know about

            self._proxies[obj.__name__] = obj

            #Check if this object matches a specific shortened name so that we can
            #automatically match a hw module to a proxy without user intervention
            try:
                short_name = obj.ModuleName()
                if short_name in self._name_map:
                    self._name_map[short_name].append(obj)
                else:
                    self._name_map[short_name] = [obj]
            except Exception:  #pylint: disable=broad-except;We don't want this to die if someone loads a misbehaving plugin
                self.logger.exception(
                    "Error importing misbehaving proxy module, skipping.")
Пример #8
0
    def _setup_apps(self):
        """Load in all iotile app objects for all registered or installed components on this system."""

        reg = ComponentRegistry()
        modules = reg.list_components()

        apps = reduce(lambda x, y: x + y,
                      [reg.find_component(x).app_modules() for x in modules],
                      [])
        app_classes = []
        for app in apps:
            app_classes += self._load_module_classes(app, IOTileApp)

        # Find all installed proxy objects through registered entry points
        for entry in pkg_resources.iter_entry_points('iotile.app'):
            mod = entry.load()
            app_classes += [
                x for x in itervalues(mod.__dict__) if inspect.isclass(x)
                and issubclass(x, IOTileApp) and x != IOTileApp
            ]

        for app in app_classes:
            try:
                matches = app.MatchInfo()
                name = app.AppName()
                for tag, ver_range, quality in matches:
                    if tag not in self._known_apps:
                        self._known_apps[tag] = []

                    self._known_apps[tag].append((ver_range, quality, app))

                if name in self._named_apps:
                    self.logger.warning(
                        "Added an app module with an existing name, overriding previous app, name=%s",
                        name)

                self._named_apps[name] = app
            except Exception:  #pylint: disable=broad-except;We don't want this to die if someone loads a misbehaving plugin
                self.logger.exception(
                    "Error importing misbehaving app module, skipping.")
Пример #9
0
    def list_local(self, path='.'):
        """List the absolute path of all local dependencies of this tile.

        A local dependency is defined as one that is located in the local
        ComponentRegistry().  The primary utility of this function is to
        figure out which dependencies could productively be built locally
        before building this component, vs which of its dependencies are
        pulled down from released code that is immutable.

        Args:
            path (str): The path to the iotile component that we wish to
                check local dependencies on.  If not specified, this
                defaults to the current working directory.

        Returns:
            list(str): A list of paths to each locally installed dependency.
        """

        tile = IOTile(path)

        if tile.release:
            raise ArgumentError(
                "Cannot check dependencies on a release mode tile that cannot have dependencies"
            )

        dep_paths = []
        reg = ComponentRegistry()

        for dep in tile.dependencies:
            try:
                local_tile = reg.find_component(dep['name'])
                if local_tile.release:
                    continue

                dep_paths.append(os.path.abspath(local_tile.folder))
            except ArgumentError:
                continue

        return dep_paths
Пример #10
0
    def resolve(self, depinfo, destdir):
        from iotile.core.dev.registry import ComponentRegistry

        reg = ComponentRegistry()

        try:
            comp = reg.find_component(depinfo['name'])
        except ArgumentError:
            return {'found': False}

        # Make sure the tile we found in the registry has the required version
        reqver = depinfo['required_version']
        if not reqver.check(comp.parsed_version):
            return {'found': False}

        # If the component is in the local registry but hasn't been built,
        # raise an error.

        if not os.path.exists(comp.output_folder):
            raise ExternalError(
                "Component found in registry but has not been built",
                path=comp.folder,
                name=comp.name,
                suggestion="Run iotile build on this component first")

        try:
            IOTile(comp.output_folder)
        except IOTileException:
            raise ExternalError(
                "Component found in registry but its build/output folder is not valid",
                path=comp.folder,
                name=comp.name,
                suggestion="Cleanly rebuild the component")

        self._copy_folder_contents(comp.output_folder, destdir)
        return {'found': True}