示例#1
0
def find_path_to_setup_from_repo_root(location, repo_root):
    # type: (str, str) -> Optional[str]
    """
    Find the path to `setup.py` by searching up the filesystem from `location`.
    Return the path to `setup.py` relative to `repo_root`.
    Return None if `setup.py` is in `repo_root` or cannot be found.
    """
    # find setup.py
    orig_location = location
    while not os.path.exists(os.path.join(location, 'setup.py')):
        last_location = location
        location = os.path.dirname(location)
        if location == last_location:
            # We've traversed up to the root of the filesystem without
            # finding setup.py
            logger.warning(
                "Could not find setup.py for directory %s (tried all "
                "parent directories)",
                orig_location,
            )
            return None

    if samefile(repo_root, location):
        return None

    return os.path.relpath(location, repo_root)
示例#2
0
 def _get_subdirectory(cls, location):
     """Return the relative path of setup.py to the git repo root."""
     # find the repo root
     git_dir = cls.run_command(["rev-parse", "--git-dir"],
                               show_stdout=False,
                               cwd=location).strip()
     if not os.path.isabs(git_dir):
         git_dir = os.path.join(location, git_dir)
     root_dir = os.path.join(git_dir, "..")
     # find setup.py
     orig_location = location
     while not os.path.exists(os.path.join(location, "setup.py")):
         last_location = location
         location = os.path.dirname(location)
         if location == last_location:
             # We've traversed up to the root of the filesystem without
             # finding setup.py
             logger.warning(
                 "Could not find setup.py for directory %s (tried all "
                 "parent directories)",
                 orig_location,
             )
             return None
     # relative path of setup.py to repo root
     if samefile(root_dir, location):
         return None
     return os.path.relpath(location, root_dir)
示例#3
0
文件: git.py 项目: jonparrott/pip
 def _get_subdirectory(self, location):
     """Return the relative path of setup.py to the git repo root."""
     # find the repo root
     git_dir = self.run_command(['rev-parse', '--git-dir'],
                                show_stdout=False, cwd=location).strip()
     if not os.path.isabs(git_dir):
         git_dir = os.path.join(location, git_dir)
     root_dir = os.path.join(git_dir, '..')
     # find setup.py
     orig_location = location
     while not os.path.exists(os.path.join(location, 'setup.py')):
         last_location = location
         location = os.path.dirname(location)
         if location == last_location:
             # We've traversed up to the root of the filesystem without
             # finding setup.py
             logger.warning(
                 "Could not find setup.py for directory %s (tried all "
                 "parent directories)",
                 orig_location,
             )
             return None
     # relative path of setup.py to repo root
     if samefile(root_dir, location):
         return None
     return os.path.relpath(location, root_dir)
    # find setup.py
    orig_location = location
    while not os.path.exists(os.path.join(location, 'setup.py')):
        last_location = location
        location = os.path.dirname(location)
        if location == last_location:
            # We've traversed up to the root of the filesystem without
            # finding setup.py
            logger.warning(
                "Could not find setup.py for directory %s (tried all "
                "parent directories)",
                orig_location,
            )
            return None

    if samefile(repo_root, location):
        return None

    return os.path.relpath(location, repo_root)


class RemoteNotFoundError(Exception):
    pass


class RevOptions(object):

    """
    Encapsulates a VCS-specific revision to install, along with any VCS
    install options.