Resolves relative imports from a module.
771697
def resolve_import(import_path, from_module):
    '''
    '''
    if not import_path or not import_path.startswith('.'):
        return import_path

    from_module = from_module.split('.')
    dots = 0
    for c in import_path:
        if c == '.':
            dots += 1
        else:
            break

    if dots:
        from_module = from_module[:-dots]
        import_path = import_path[dots:]

    if import_path:
        from_module.append(import_path)

    return '.'.join(from_module)
383853
def get_imported_resource(self, context):
        
        if self.level == 0:
            return context.project.find_module(
                self.module_name, folder=context.folder)
        else:
            return context.project.find_relative_module(
                self.module_name, context.folder, self.level)
655718
def import_submodules(package_name, *submodules):
    """"""
    package = sys.modules[package_name]
    return {
        name: importlib.import_module(package_name + '.' + name)
        for _, name, _ in pkgutil.walk_packages(package.__path__)
        if not submodules or name in submodules
    }
1028563
def refactor_froms_to_imports(self, offset):
        """"""
        refactor = ImportOrganizer(self.project)
        changes = refactor.froms_to_imports(self.resource, offset)
        return translate_changes(changes)
642882
def resolve_import(name, is_from, is_star):
    
    # Don't try to resolve relative imports or builtins here; they will be
    # handled by resolve.Resolver
    if name.startswith('.') or is_builtin(name):
        return None
    ret = _resolve_import(name)
    if ret is None and is_from and not is_star:
        package, _ = name.rsplit('.', 1)
        ret = _resolve_import(package)
    return ret
1273129
def resolve_module(module, definitions):
  """"""

  assert module in definitions, "No definition for module '%s'" % module
  
  d = definitions[module]
  if type(d) == dict:
    if 'filename' in d:
      with open(d['filename']) as f:
        return [f.read().strip()]
    elif 'reference' in d:
      return resolve_module(d['reference'], definitions)
    elif 'group' in d:
      return sum([resolve_module(m,definitions) for m in d['group']],[])
    else:
      assert False
  else:
    assert type(d) == str
    return [d]
502312
function resolvePath (moduleName, relativePath)
{
  if (! moduleName) {
    return null;
  }

  if (! relativePath) {
    return null;
  }

  const mainPath = require.resolve(moduleName);
  if (! mainPath) {
    return null;
  }

  const rootLocations = [];
  const dirs = mainPath.split(path.sep);
  let lastSegment = dirs.pop();
  while (lastSegment) {
    const location = dirs.concat(['package.json']).join(path.sep);
    rootLocations.push(location);
    lastSegment = dirs.pop();
  }

  for(const location of rootLocations) {
    if (fs.existsSync(location)) {
      const cli = path.resolve(path.dirname(location), relativePath);
      if (fs.existsSync(cli)) {
        return cli;
      }
    }
  }

  return null;
}
992770
def resolve_annotations(raw_annotations: Dict[str, AnyType], module_name: Optional[str]) -> Dict[str, AnyType]:
    
    if module_name:
        base_globals: Optional[Dict[str, Any]] = sys.modules[module_name].__dict__
    else:
        base_globals = None
    annotations = {}
    for name, value in raw_annotations.items():
        if isinstance(value, str):
            value = ForwardRef(value, is_argument=False)
        try:
            value = _eval_type(value, base_globals, None)
        except NameError:
            # this is ok, it can be fixed with update_forward_refs
            pass
        annotations[name] = value
    return annotations
17795
def __push_import_modules(self):
        
        for module in self.__import_modules:
            sys.modules[module.__name__] = module
218556
function _resolvePackageSync(base, relativePath) {
    var packageJsonPath;
    var packagePath;

    // try to fetch node package
    try {
        packageJsonPath = _resolvePackagePathSync(base, PATH.join(relativePath, 'package.json'));
        packagePath = dirname(packageJsonPath);
    } catch (err) {
        if (err.code !== 'ENOENT') {
            throw err;
        }

        // try to resolve package itself
        packagePath = _resolvePackagePathSync(base, relativePath);
    }

    // compiling resolved metadata
    var packageJson = packageJsonPath && require(packageJsonPath) || {};
    var metadata = packageJson.pym || {};

    metadata.interface =
        metadata.interface ||
        packageJson.pym ? 'pym' :
        packageJson.plugin ? 'architect' :
        // what 'bout amd?
        'commonjs';

    // load package itself
    var packageMainPath;
    var nodeModule;
    switch (metadata.interface) {
        case 'pym':
            packageMainPath = PATH.join(packagePath, metadata.main || packageJson.main);
            nodeModule = require(packageMainPath);
            metadata.provides = metadata.provides || nodeModule.provides || [];
            metadata.consumes = metadata.consumes || nodeModule.consumes || [];
            metadata.packagePath = packagePath;
            metadata.exports = nodeModule;
            break;
        case 'architect':
            var pluginData = packageJson.plugin || {};
            nodeModule = require(packagePath);
            metadata.provides = pluginData.provides || nodeModule.provides || [];
            metadata.consumes = pluginData.consumes || nodeModule.consumes || [];
            metadata.packagePath = packagePath;
            metadata.exports = _wrapToArchitect(nodeModule, metadata);
            break;
        default:
            throw new Error('Unsupported package format ' + relativePath);
    }

    return metadata;
}
964072
def resolve_node_modules(self):
        ''
        if not self.resolved_node_modules:
            try:
                self.resolved_node_modules = [
                    importlib.import_module(mod, self.node_package)
                    for mod in self.node_modules
                ]
            except ImportError:
                self.resolved_node_modules = []
                raise

        return self.resolved_node_modules
1099878
def _import_module(module_name):
    
    fromlist = []
    dot_position = module_name.rfind('.')
    if dot_position > -1:
        fromlist.append(
            module_name[dot_position+1:len(module_name)]
        )

    # Import module
    module = __import__(module_name, globals(), locals(), fromlist, 0)

    return module
1107649
def import_from(module, name):
    '''
    
    '''
    module = importlib.import_module(module)
    return getattr(module, name)
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())
710409
def load_modules(self, args):
        """"""

        # Init the plugins dict
        # Active plugins dictionnary
        self._plugins = collections.defaultdict(dict)
        # Load the plugins
        self.load_plugins(args=args)

        # Init the export modules dict
        # Active exporters dictionnary
        self._exports = collections.defaultdict(dict)
        # All available exporters dictionnary
        self._exports_all = collections.defaultdict(dict)
        # Load the export modules
        self.load_exports(args=args)

        # Restoring system path
        sys.path = sys_path
26887
function collectDependencies(){
	const files = glob.sync(posix.resolve(__dirname, "../Tone/!(shim)/!(Tone).js"));
	const modules = files.map(f => f.slice(0, -3));
	let reqString = modules.map(r => {
		const relativePath = posix.relative(posix.resolve(__dirname, "../Tone"), r);
		// const exportName = r.split("/")[r.split("/").length - 1];
		// return `export { default as ${exportName} } from "./${relativePath}";`;
		// return `import "./${relativePath}";`;
		return `require("./${relativePath}");`;
	}).join("\n");
	// reqString += "\nexport { default } from \"./core/Tone\";\n";
	reqString += "\nmodule.exports = require(\"./core/Tone\").default;\n";
	fs.writeFileSync(posix.resolve(__dirname, "../Tone/index.js"), reqString);
}
1235920
def do_import_module(self, modname=None):
        
        # handle special case where we are on a package node importing a module
        # using the same name as the package, which may end in an infinite loop
        # on relative imports
        # XXX: no more needed ?
        mymodule = self.root()
        level = getattr(self, "level", None)  # Import as no level
        if modname is None:
            modname = self.modname
        # XXX we should investigate deeper if we really want to check
        # importing itself: modname and mymodule.name be relative or absolute
        if mymodule.relative_to_absolute_name(modname, level) == mymodule.name:
            # FIXME: we used to raise InferenceError here, but why ?
            return mymodule

        return mymodule.import_module(
            modname, level=level, relative_only=level and level >= 1
        )