Find the project path by going up the file tree.

    This will look in the current directory and upwards for the pelconf file
    (.yaml or .py)
343726
def _find_proj_root():
    # type: () -> Optional[str]
    
    proj_files = frozenset(('pelconf.py', 'pelconf.yaml'))
    curr = os.getcwd()

    while curr.startswith('/') and len(curr) > 1:
        if proj_files & frozenset(os.listdir(curr)):
            return curr
        else:
            curr = os.path.dirname(curr)

    return None
213419
def search_project_root():
        

        while True:

            current = os.getcwd()

            if pathlib.Path("Miragefile.py").is_file() or pathlib.Path("Miragefile").is_file():
                return current
            elif os.getcwd() == "/":
                raise FileNotFoundError
            else:
                os.chdir("../")
717854
def index_path(self, root):
        
        basename = os.path.basename(root)
        if os.path.splitext(basename)[0] != '__init__' and basename.startswith('_'):
            return
        location = self._determine_location_for(root)
        if os.path.isfile(root):
            self._index_module(root, location)
        elif os.path.isdir(root) and os.path.exists(os.path.join(root, '__init__.py')):
            self._index_package(root, location)
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
929638
def get_project_root():
    """"""
    cfg = get_project_configuration()
    # At this point it can be sure that the configuration file exists
    # Now make sure the project structure exists
    for dirname in ["raw-datasets",
                    "preprocessed",
                    "feature-files",
                    "models",
                    "reports"]:
        directory = os.path.join(cfg['root'], dirname)
        if not os.path.exists(directory):
            os.makedirs(directory)

    raw_yml_path = pkg_resources.resource_filename('hwrt', 'misc/')

    # TODO: How to check for updates if it already exists?
    raw_data_dst = os.path.join(cfg['root'], "raw-datasets/info.yml")
    if not os.path.isfile(raw_data_dst):
        raw_yml_pkg_src = os.path.join(raw_yml_path, "info.yml")
        shutil.copy(raw_yml_pkg_src, raw_data_dst)

    # Make sure small-baseline folders exists
    for dirname in ["models/small-baseline", "feature-files/small-baseline",
                    "preprocessed/small-baseline"]:
        directory = os.path.join(cfg['root'], dirname)
        if not os.path.exists(directory):
            os.makedirs(directory)

    # Make sure small-baseline yml files exist
    paths = [("preprocessed/small-baseline/", "preprocessing-small-info.yml"),
             ("feature-files/small-baseline/", "feature-small-info.yml"),
             ("models/small-baseline/", "model-small-info.yml")]
    for dest, src in paths:
        raw_data_dst = os.path.join(cfg['root'], "%s/info.yml" % dest)
        if not os.path.isfile(raw_data_dst):
            raw_yml_pkg_src = os.path.join(raw_yml_path, src)
            shutil.copy(raw_yml_pkg_src, raw_data_dst)

    return cfg['root']
907273
def add_path(self, path):
        
        abspath = os.path.abspath(path)
        self.children.append(_build_project_tree(abspath, self.followsymlinks, self.file_filter))
1104819
def path (self):
        
        if not self.path_:
            if self.action_:
                p = self.action_.properties ()
                (target_path, relative_to_build_dir) = p.target_path ()

                if relative_to_build_dir:
                    # Indicates that the path is relative to
                    # build dir.
                    target_path = os.path.join (self.project_.build_dir (), target_path)

                # Store the computed path, so that it's not recomputed
                # any more
                self.path_ = target_path

        return os.path.normpath(self.path_)
1184766
def get_active_project_path(self):
        """"""
        active_project_path = None
        if self.current_active_project:
            active_project_path = self.current_active_project.root_path
        return active_project_path
1261912
def resource_path(package_name: str, relative_path: typing.Union[str, Path]) -> Path:
    
    relative_path = Path(relative_path)
    methods = [
        _get_from_dev,
        _get_from_package,
        _get_from_sys,
    ]
    for method in methods:
        path = method(package_name, relative_path)
        if path.exists():
            return path

    raise FileNotFoundError(relative_path)
1075292
def _find_directory_upwards(base: str, target: str) -> Optional[str]:
    
    while True:
        step = os.path.join(base, target)
        LOG.debug("Trying with: `%s`", step)
        if os.path.isdir(step):
            return step
        parent_directory = os.path.dirname(base)
        if parent_directory == base:
            # We have reached the root.
            break
        base = parent_directory
    return None
1114197
def project_path(*names):
    """"""
    return os.path.join(os.path.dirname(__file__), *names)
847264
def rel_path(*file_path):
        '''
        
        '''
        if hasattr(sys, 'frozen'):
            if file_path[0] == '__file__':
                return sys.executable
            return os.path.join(os.path.dirname(sys.executable), *file_path)
        else:
            try:
                main_file = AppBuilder.main_file
            except AttributeError:
                # The first call setting up the instance
                main_file = inspect.stack()[1][1]
            if file_path[0] == '__file__':
                return os.path.realpath(main_file)
            return os.path.join(os.path.dirname(main_file), *file_path)
28983
def _get_path(name, settings, mkdir=True):
    
    default_projects_path = settings.config.get("projects_path")
    path = None

    if default_projects_path:
        path = raw_input("\nWhere would you like to create this project? [{0}/{1}] ".format(default_projects_path, name))
        if not path:
            path = os.path.join(default_projects_path, name)
    else:
        while not path:
            path = raw_input("\nWhere would you like to create this project? (e.g. ~/tarbell/) ")

    return os.path.expanduser(path)
1290135
def get_conf_path_from_env():
    '''
    
    '''
    config_path = os.environ.get('PECAN_CONFIG')
    if not config_path:
        error = "PECAN_CONFIG is not set and " \
                "no config file was passed as an argument."
    elif not os.path.isfile(config_path):
        error = "PECAN_CONFIG was set to an invalid path: %s" % config_path
    else:
        return config_path

    raise RuntimeError(error)
531267
@Nullable
  private File findProjectGitDirectory() {
    if (this.mavenProject == null) {
      return null;
    }

    File basedir = mavenProject.getBasedir();
    while (basedir != null) {
      File gitdir = new File(basedir, Constants.DOT_GIT);
      if (gitdir.exists()) {
        if (gitdir.isDirectory()) {
          return gitdir;
        } else if (gitdir.isFile()) {
          return processGitDirFile(gitdir);
        } else {
          return null;
        }
      }
      basedir = basedir.getParentFile();
    }
    return null;
  }
896662
def find_workflow_path(self):
        
        for pth in settings.WORKFLOW_PACKAGES_PATHS:
            path = "%s/%s.bpmn" % (pth, self.current.workflow_name)
            if os.path.exists(path):
                return path
        err_msg = "BPMN file cannot found: %s" % self.current.workflow_name
        log.error(err_msg)
        raise RuntimeError(err_msg)
310462
def path(self) -> str:
        """"""
        return os.path.join(self.project_path, self.project.name)