find package base on folder name 根据目录位置查找是否属于某个 package 配置
195368
function findPkgByFolder(folder, list) {
  var ret = null;

  if (list && list.length) {
    list.every(function(item) {
      if (item.folder === folder || path.resolve(baseUrl, item.folder) === folder) {
        ret = item;
        return false;
      }

      return true;
    });
  }

  return ret;
}
111507
def find_all(name, opts={})
      # opts ||= {}
      all = [@packages.select {|x| x.name.to_s == name.to_s },
      find_all_by_provides(name, opts)].flatten.compact
      filter(all, opts)
    end
1144748
private void searchSubPackage(String packageName,
                                  ListBuffer<String> packages,
                                  List<String> excludedPackages,
                                  Collection<File> pathnames) {
        if (excludedPackages.contains(packageName))
            return;

        String packageFilename = packageName.replace('.', File.separatorChar);
        boolean addedPackage = false;
        for (File pathname : pathnames) {
            File f = new File(pathname, packageFilename);
            String filenames[] = f.list();
            // if filenames not null, then found directory
            if (filenames != null) {
                for (String filename : filenames) {
                    if (!addedPackage
                            && (isValidJavaSourceFile(filename) ||
                                isValidJavaClassFile(filename))
                            && !packages.contains(packageName)) {
                        packages.append(packageName);
                        addedPackage = true;
                    } else if (isValidClassName(filename) &&
                               (new File(f, filename)).isDirectory()) {
                        searchSubPackage(packageName + "." + filename,
                                         packages, excludedPackages, pathnames);
                    }
                }
            }
        }
    }
543342
def _package_path(package):
    
    from os import path
    confdir = config_dir()
    return path.join(confdir, "{}.cfg".format(package))
284358
def find_packages(path):
        
        matches = []
        root = join(path, 'src', 'main', 'java')
        for folder, dirnames, filenames in os.walk(root):
            for filename in fnmatch.filter(filenames, '*Package.java'):
                #: Open and make sure it's an EnamlPackage somewhere
                with open(join(folder, filename)) as f:
                    if "implements EnamlPackage" in f.read():
                        package = os.path.relpath(folder, root)
                        matches.append(os.path.join(package, filename))
        return matches
1127733
def bin_find(self):
        
        flag = []
        options = [
            "-f",
            "--find"
        ]
        additional_options = ["--case-ins"]
        for arg in self.args:
            if arg in additional_options:
                flag.append(arg)
                self.args.remove(arg)
        packages = self.args[1:]
        if len(self.args) > 1 and self.args[0] in options:
            PackageManager(packages).find(flag)
        else:
            usage("")
228637
def find_package_data():
    

    l = list()
    for start in ('ambry/support', 'ambry/bundle/default_files'):
        for root, dirs, files in os.walk(start):

            for f in files:

                if f.endswith('.pyc'):
                    continue

                path = os.path.join(root, f).replace('ambry/', '')

                l.append(path)

    return {'ambry': l}
776792
def find_single_file_project(self):  # type: () -> List[str]
        
        # TODO: use package_dirs
        packaged_dirs = ""
        try:
            # Right now only returns 1st.
            packaged_dirs = self.extract_package_dir()
        except:
            pass
        likely_src_folders = [".", "src/"]
        if packaged_dirs:
            likely_src_folders.append(packaged_dirs)

        candidates = []
        for likely_src in likely_src_folders:
            if not os.path.isdir(likely_src):
                continue
            files = [f for f in os.listdir(likely_src) if os.path.isfile(f)]

            # BUG: doesn't deal with src/foo/bar.py
            for file in files:
                if file.endswith("setup.py") or file == "setup":
                    continue  # duh
                if file.endswith(".py"):
                    candidate = file.replace(".py", "")
                    if candidate != "setup":
                        candidates.append(candidate)
                else:
                    if self.file_opener.is_python_inside(file):
                        candidates.append(file)
        return candidates
1108395
def getFilesForName(name):
    
    if not os.path.exists(name):
        # check for glob chars
        if containsAny(name, "*?[]"):
            files = glob.glob(name)
            list = []
            for file in files:
                list.extend(getFilesForName(file))
            return list

        # try to find module or package
        name = _get_modpkg_path(name)
        if not name:
            return []

    if os.path.isdir(name):
        # find all python files in directory
        list = []
        os.path.walk(name, _visit_pyfiles, list)
        return list
    elif os.path.exists(name):
        # a single file
        return [name]

    return []
939164
def get_from_package(package_name, path):
    
    filepath = pkg_resources.resource_filename(package_name, path)
    return os.path.abspath(filepath)
161897
def ensure_source_package_dir(nb_path, pkg_name):
    """"""

    pkg_path = join(dirname(nb_path), pkg_name)

    makedirs(join(pkg_path,'notebooks'),exist_ok=True)
    makedirs(join(pkg_path, 'docs'), exist_ok=True)

    return pkg_path
901443
def folder_name(self):
        ''''''
        name = self.site_packages_name
        if name is None:
            name = self.name
        return name
907633
def get_package_filename(filename, package_dir=None):
    ''''''
    if getattr(sys, 'frozen', False):
        package_dir = os.path.join(
            sys._MEIPASS,
            os.path.basename(os.path.dirname(__file__))
        )
    elif not package_dir:
        package_dir = os.path.dirname(__file__)

    return os.path.join(package_dir, filename)
1234853
String packageName() {
    for (Object context : contextStack) {
      if (context instanceof ProtoFile) return ((ProtoFile) context).packageName();
    }
    return null;
  }
1146672
function packageNameFromPath(path) {
  var matches = moduleRegex.exec(path);
  return matches && matches.length > 1 ? matches[1] : null;
}
970876
function findPackage(filename) {
    if (!ctr)
        return;
    filename = filename || require.main.filename;
    var parsed = path_1.parse(filename);
    var curPath = path_1.join(parsed.dir, 'package.json');
    if (!fs_1.existsSync(curPath)) {
        ctr--;
        return findPackage(parsed.dir);
    }
    else {
        return chek_1.tryRequire(curPath, {});
    }
}
1092572
def find_lib_dir(root):
    """"""
    root = path(root)
    log.debug('files in dir: %s', root)
    for x in root.walkfiles():
        log.debug('  %s', x)

    # only 1 dir in root? (example: github)
    if not len(root.files()) and len(root.dirs()) == 1:
        log.debug('go inside root')
        root = root.dirs()[0]

    if len(root.files('keywords.txt')):
        root = rename_root(root)
        return root, root

    keywords = list(root.walkfiles('keywords.txt'))
    if len(keywords):
        if len(keywords) > 1:
            log.warning('more keywords.txt found. Installing only one.  %s', keywords)  

        lib_dir = keywords[0].parent
        lib_dir = fix_libdir(lib_dir)
        return root, lib_dir

    header_only = len(list(noexample(root.walkfiles('*.cpp')))) == 0
    log.debug('header_only: %s', header_only)
    lib_dir = None

    headers = list(noexample(root.walkfiles('*.h')))

    for h in headers:
        cpp = h.stripext() + '.cpp'
        if (header_only or cpp.exists()) and h.parent.name.lower() == h.namebase.lower():
            assert not lib_dir
            lib_dir = h.parent
            log.debug('found lib: %s', lib_dir)

    if not lib_dir:
        if len(headers) == 1 and len(list(root.files('*.h'))) == 0:
            log.debug('only 1 header, not in root')
            lib_dir = headers[0].parent
            lib_dir = rename_root(lib_dir)

    if not lib_dir:
        # xxx.cpp and xxx.h in root? -> rename root dir
        root = rename_root(root)
        return root, root
#        for h in root.files('*.h'):
#            cpp = h.stripext() + '.cpp'
#            if  header_only or cpp.exists():
#                assert not lib_dir
#                root.rename(root.parent / h.namebase)
#                root = lib_dir = root.parent / h.namebase
    assert lib_dir
    return root, lib_dir