Imports the module and sets version information
            If the module cannot be imported, the version is set to empty values.
326566
def tryImportModule(self, name):
        
        self._name = name
        try:
            import importlib
            self._module = importlib.import_module(name)
        except ImportError:
            self._module = None
            self._version = ''
            self._packagePath = ''
        else:
            if self._versionAttribute:
                self._version = getattr(self._module, self._versionAttribute, '???')
            if self._pathAttribute:
                self._packagePath = getattr(self._module, self._pathAttribute, '???')
1008373
def set(constants):
    
    if not constants:
        return
    constants = wrap(constants)

    for k, new_value in constants.leaves():
        errors = []
        try:
            old_value = mo_dots_set_attr(sys.modules, k, new_value)
            continue
        except Exception as e:
            errors.append(e)

        # ONE MODULE IS MISSING, THE CALLING MODULE
        try:
            caller_globals = sys._getframe(1).f_globals
            caller_file = caller_globals["__file__"]
            if not caller_file.endswith(".py"):
                raise Exception("do not know how to handle non-python caller")
            caller_module = caller_file[:-3].replace("/", ".")

            path = split_field(k)
            for i, p in enumerate(path):
                if i == 0:
                    continue
                prefix = join_field(path[:1])
                name = join_field(path[i:])
                if caller_module.endswith(prefix):
                    old_value = mo_dots_set_attr(caller_globals, name, new_value)
                    if DEBUG:
                        from mo_logs import Log

                        Log.note(
                            "Changed {{module}}[{{attribute}}] from {{old_value}} to {{new_value}}",
                            module=prefix,
                            attribute=name,
                            old_value=old_value,
                            new_value=new_value
                        )
                    break
        except Exception as e:
            errors.append(e)

        if errors:
            from mo_logs import Log

            Log.error("Can not set constant {{path}}", path=k, cause=errors)
1087725
private static void initializeVersion() {
        InputStream inputStream = ClassLoaderHelper.getResourceAsStream(
                VERSION_INFO_FILE, true, VersionInfoUtils.class);
        Properties versionInfoProperties = new Properties();
        try {
            if (inputStream == null)
                throw new Exception(VERSION_INFO_FILE + " not found on classpath");

            versionInfoProperties.load(inputStream);
            version = versionInfoProperties.getProperty("version");
            platform = versionInfoProperties.getProperty("platform");
        } catch (Exception e) {
            log.info("Unable to load version information for the running SDK: " + e.getMessage());
            version = "unknown-version";
            platform = "java";
        } finally {
            closeQuietly(inputStream, log);
        }
    }
256705
def update(self, module_name=None):
        
        if not module_name:
            return self._module.force_update()
        else:
            module_info = self._get_module_info(module_name)
            if module_info:
                module_info["module"].force_update()
444823
def init(self):
        
        # some modules might need to be imported "on the other side of the fork"
        # .. but the, when importing this module, the import is not tested
        #
        # 
        # from openalpr import Alpr
        from valkka.mvision.alpr.openalpr_fix import Alpr
        self.movement = MovementDetector()
        self.alpr = Alpr(self.country, self.conf_file, self.runtime_data)
        if not self.alpr.is_loaded():
            self.alpr = None
            return
        self.alpr.set_top_n(self.top_n)
        self.reset()
        
        """
        # test in ipython:
        from valkka.mvision.alpr.openalpr_fix import Alpr
        country="eu"
        conf_file="/usr/share/openalpr/config/openalpr.defaults.conf"
        runtime_data="/usr/share/openalpr/runtime_data"
        a = Alpr(country, conf_file, runtime_data)
        a.is_loaded()        
        """
286120
def _set_version():
    """"""
    global __version__
    from pkg_resources import get_distribution, DistributionNotFound
    import os
    # https://stackoverflow.com/questions/17583443/what-is-the-correct-way-to-share-package-version-with-setup-py-and-the-package
    try:
        dist = get_distribution("check50")
        # Normalize path for cross-OS compatibility.
        dist_loc = os.path.normcase(dist.location)
        here = os.path.normcase(__file__)
        if not here.startswith(os.path.join(dist_loc, "check50")):
            # This version is not installed, but another version is.
            raise DistributionNotFound
    except DistributionNotFound:
        __version__ = "locally installed, no version information available"
    else:
        __version__ = dist.version
641004
def import_optional(mod_name):
    ''' 

    '''
    try:
        return import_module(mod_name)
    except ImportError:
        pass
    except Exception:
        msg = "Failed to import optional module `{}`".format(mod_name)
        log.exception(msg)
1132792
def import_module(module):  # pylint: disable=R0201
        
        if isinstance(module, list):
            all_modules = module
        else:
            all_modules = [module]
        for mod in all_modules:
            globals()[mod] = __import__(mod.strip())
223321
def version_by_import(self, module_name):  # type: (str) ->Dict[str,str]
        
        if not module_name:
            return {}
        try:
            module = __import__(module_name)
        except ModuleNotFoundError:
            # hypothetical module would have to be on python path or execution folder, I think.
            return {}
        except FileNotFoundError:
            return {}

        if hasattr(module, "__version__"):
            version = module.__version__
            return {"module import": version}
        return {}
1278909
def set_loader(fxn):
    
    @functools.wraps(fxn)
    def set_loader_wrapper(self, *args, **kwargs):
        warnings.warn('The import system now takes care of this automatically.',
                      DeprecationWarning, stacklevel=2)
        module = fxn(self, *args, **kwargs)
        if getattr(module, '__loader__', None) is None:
            module.__loader__ = self
        return module
    return set_loader_wrapper
1151456
def resp_set_version(self, resp):
        
        if resp:
            self.vendor = resp.vendor
            self.product = resp.product
            self.version = resp.version
1049131
def _init():
    
    global finder

    if finder is None:
        finder = ModuleFinder()

    if finder not in sys.meta_path:
        sys.meta_path.insert(0, finder)
1343203
def register_module(module=None):
    

    global REGISTERED_MODULES

    if module is None:
        # Note: inspect.getmodule() can return the wrong module if it has been imported with different relatives paths.
        module = sys.modules.get(inspect.currentframe().f_back.f_globals["__name__"])

    REGISTERED_MODULES.add(module)
    return True
482978
public void addImportVersionClass(I_CmsImport importVersionClass) {

        if (LOG.isDebugEnabled()) {
            LOG.debug(
                Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_ADDED_IMPORT_VERSION_1, importVersionClass));
        }
        m_importVersionClasses.add(importVersionClass);
    }
798729
def rename_module(new, old):
    
    try:
        sys.modules[new] = imp.load_module(old, *imp.find_module(old))
        return True
    except ImportError:
        return False
291909
def _init_modules_stub(self, **_):
        
        from google.appengine.api import request_info
        # edit all_versions per modules & versions thereof needing tests
        all_versions = {}  # {'default': [1], 'andsome': [2], 'others': [1]}
        def_versions = {}  # {m: all_versions[m][0] for m in all_versions}
        m2h = {}  # {m: {def_versions[m]: 'localhost:8080'} for m in def_versions}
        for module in self.configuration.modules:
            module_name = module._module_name or 'default'
            module_version = module._version or '1'
            all_versions[module_name] = [module_version]
            def_versions[module_name] = module_version
            m2h[module_name] = {module_version: 'localhost:8080'}

        request_info._local_dispatcher = request_info._LocalFakeDispatcher(
            module_names=list(all_versions),
            module_name_to_versions=all_versions,
            module_name_to_default_versions=def_versions,
            module_name_to_version_to_hostname=m2h)
        self.testbed.init_modules_stub()
1209724
public static void validate(final Module module) {
        if (null == module) {
            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
                .entity("Module cannot be null!")
                .build());
        }
        if(module.getName() == null ||
                module.getName().isEmpty()){
            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
                    .entity("Module name cannot be null or empty!")
                    .build());
        }
        if(module.getVersion()== null ||
                module.getVersion().isEmpty()){
            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
                    .entity("Module version cannot be null or empty!")
                    .build());
        }

        // Check artifacts
        for(final Artifact artifact: DataUtils.getAllArtifacts(module)){
            validate(artifact);
        }

        // Check dependencies
        for(final Dependency dependency: DataUtils.getAllDependencies(module)){
            validate(dependency.getTarget());
        }
    }