Locate top-level project directory
350860
def find_project_directory(start_path) -> str:
        
        start_path = os.path.realpath(start_path)
        possible_name = os.path.join(start_path, ModelConfig.PROJECT_FILE_NAME)

        if os.path.exists(possible_name):
            return start_path
        else:
            up_path = os.path.realpath(os.path.join(start_path, '..'))
            if os.path.realpath(start_path) == up_path:
                raise RuntimeError(f"Couldn't find project file starting from {start_path}")
            else:
                return ModelConfig.find_project_directory(up_path)
1041758
def top_directory(self):
        """"""
        if self.handle:
            return os.path.commonprefix(self.handle.getnames()).rstrip('/')
1022257
def list_projects(root, backend=os.listdir):
    
    projects = list()
    for project in sorted(backend(root)):
        abspath = os.path.join(root, project)
        if not isproject(abspath):
            continue
        projects.append(project)
    return projects
311212
def path(project, credentials):
        """"""
        user, oauth_access_token = parsecredentials(credentials) #pylint: disable=unused-variable
        return settings.ROOT + "projects/" + user + '/' + project + "/"
451911
def find_component(name)
      Find.find(self["frameworks/projects"]) do |filename|
        break File.dirname(filename).sub(%r{.+/src/}, "").gsub("/", ".") if
          File.basename(filename).sub(/\..*/, "") == name
      end
    end
690688
def in_project_roots(self, filename):
        '''
        
        '''
        project_roots = self._get_project_roots()
        if not filename.endswith('>'):
            filename = self._normpath(filename)

        found_in_project = []
        for root in project_roots:
            if root and filename.startswith(root):
                found_in_project.append(root)

        found_in_library = []
        library_roots = self._get_library_roots()
        for root in library_roots:
            if root and filename.startswith(root):
                found_in_library.append(root)

        if not project_roots:
            # If we have no project roots configured, consider it being in the project
            # roots if it's not found in site-packages (because we have defaults for those
            # and not the other way around).
            if filename.endswith('>'):
                # This is a dummy filename that is usually used for eval or exec. Assume
                # that it is user code, with one exception: <frozen ...> is used in the
                # standard library.
                in_project = not filename.startswith('<frozen ')
            else:
                in_project = not found_in_library
        else:
            in_project = False
            if found_in_project:
                if not found_in_library:
                    in_project = True
                else:
                    # Found in both, let's see which one has the bigger path matched.
                    if max(len(x) for x in found_in_project) > max(len(x) for x in found_in_library):
                        in_project = True

        return in_project
661075
def setup_dirs():
    
    try:
        top_dir = os.path.abspath(os.path.expanduser(os.environ["XDG_CACHE_HOME"]))
    except KeyError:
        top_dir = os.path.abspath(os.path.expanduser("~/.cache"))
    our_cache_dir = os.path.join(top_dir, PROJECT_NAME)
    os.makedirs(our_cache_dir, mode=0o775, exist_ok=True)
    return our_cache_dir
637996
def find_user_file(self, option_name, filename_list):
        """"""
        if option_name is not None:
            filePath = self._options.get(option_name, None)
        else:
            filePath = None
        
        # Look for default filenames if a path wasn't provided.
        if filePath is None:
            for filename in filename_list:
                thisPath = os.path.join(self.project_dir, filename)
                if os.path.isfile(thisPath):
                    filePath = thisPath
                    break
        # Use the path passed in options, which may be absolute, relative to the
        # home directory, or relative to the project directory.
        else:
            filePath = os.path.expanduser(filePath)
            if not os.path.isabs(filePath):
                filePath = os.path.join(self.project_dir, filePath)
        
        return filePath
1114197
def project_path(*names):
    """"""
    return os.path.join(os.path.dirname(__file__), *names)
186456
function locateRootFolder() {
    var firstDefaultPlugin = DEFAULT_PLUGINS.first();
    var pluginPath = resolve.sync(firstDefaultPlugin.getNpmID() + '/package.json', {
        basedir: __dirname
    });
    var nodeModules = path.resolve(pluginPath, '../../..');

    return nodeModules;
}
353874
def get_project_files():
    
    if is_git_project():
        return get_git_project_files()

    project_files = []
    for top, subdirs, files in os.walk('.'):
        for subdir in subdirs:
            if subdir.startswith('.'):
                subdirs.remove(subdir)

        for f in files:
            if f.startswith('.'):
                continue
            project_files.append(os.path.join(top, f))

    return project_files
1331430
def find_top_level_modules_by_dunder_init(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", "lib"]
        if packaged_dirs and packaged_dirs not in likely_src_folders:
            likely_src_folders.append(packaged_dirs)

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

            for folder in folders:
                if os.path.isfile(os.path.join(likely_src, folder, "__init__.py")):
                    # dunder_source = self.file_opener.read_file(folder + "/__init__.py")
                    candidates.append(folder)

        return list(set([x for x in candidates if x]))
1310725
private String getProjectStageFromLocators() {

        // try to locate web.xml
        WebResourceLocator webResourceLocator = new WebResourceLocator();
        URL webXmlLocation = webResourceLocator.getWebResourceUrl("/WEB-INF/web.xml");

        // try to parse the web.xml if the locator returned a result
        if (webXmlLocation != null) {

            String projectStage = parseWebXml(webXmlLocation);

            // accept the first result
            if (projectStage != null) {
                return projectStage;
            }

        }

        // not result found
        return null;

    }
1374976
def _getBatchDirectory(self, projectRootDirectory):
        
        # Set output directory to main directory as default
        batchDirectory = projectRootDirectory

        # Get the replace folder card
        replaceFolderCard = self.getCard('REPLACE_FOLDER')

        if replaceFolderCard:
            replaceDir = replaceFolderCard.value.strip('"')
            batchDirectory = os.path.join(batchDirectory, replaceDir)

        # Create directory if it doesn't exist
        if not os.path.isdir(batchDirectory):
            os.mkdir(batchDirectory)
            log.info('Creating directory for batch output: {0}'.format(batchDirectory))

        return batchDirectory
197934
def check_topdir(cls, dap):
        ''''''
        problems = list()
        dirname = os.path.dirname(dap._meta_location)

        if not dirname:
            msg = 'meta.yaml is not in top-level directory'
            problems.append(DapProblem(msg))

        else:
            for path in dap.files:
                if not path.startswith(dirname):
                    msg = path + ' is outside of ' + dirname + ' top-level directory'
                    problems.append(DapProblem(msg))

        if dap.meta['package_name'] and dap.meta['version']:
            desired_dirname = dap._dirname()
            desired_filename = desired_dirname + '.dap'

            if dirname and dirname != desired_dirname:
                msg = 'Top-level directory with meta.yaml is not named ' + desired_dirname
                problems.append(DapProblem(msg))

            if dap.basename != desired_filename:
                msg = 'The dap filename is not ' + desired_filename
                problems.append(DapProblem(msg))

        return problems
1192587
function findInProject(dir, name) {
    return new Promise((resolve, reject) => {
        const fullPath = process.cwd();
        const pieces = fullPath.split(path.sep);

        let folderCounter = 0;
        let found = false;
        let folder = dir;
        while (folderCounter < pieces.length - 1 && !found) {
            if (fs.existsSync(path.join(folder, name))) {
                found = true;
            } else {
                folderCounter++;
                folder = path.join('..', folder);
            }
        }
        resolve({
            found,
            folder,
        });
    });
}
1143192
def find_root
      Pathname.pwd.ascend do |root|
        config_dir = root.join(Project::CONFIG_DIR)

        if config_dir.directory?
          config_file = config_dir.join(Project::CONFIG_FILE)
          return root if config_file.file?

          environments_dir = config_dir.join(Project::ENVIRONMENTS_DIR)
          return root if environments_dir.directory?
        end
      end

      shell.say "Could not find '#{Project::CONFIG_FILE}' in any parent directories", :red
      exit -1
    end