Esempio n. 1
0
File: req.py Progetto: xizhao/pydep
 def resolve(self):
     """
     Downloads this requirement from the VCS repository or archive file and returns metadata from its setup.py.
     Returns an error string or None if no error.
     """
     tmpdir = tempfile.mkdtemp()
     with open(os.devnull, 'w') as devnull:
         # Because of a bug in pip when dealing with VCS URLs, we can't use pip to download the repository
         if self.vcs == 'git':
             subprocess.call(['git', 'clone', '--depth=1', self.url, tmpdir], stdout=devnull, stderr=devnull)
         elif self.vcs == 'hg':
             subprocess.call(['hg', 'clone', self.url, tmpdir], stdout=devnull, stderr=devnull)
         else:
             #for zip or tar files w/o VCS
             install_url = self._install_req.url
             if self.vcs is None and re.compile(r'^(http|https)://[^/]+/.+\.(zip|tar)(\.gz|)$', re.IGNORECASE).match(install_url) is not None:
                 self.type = 'archive'
                 tmparchive = tempfile.mkstemp()[1]
                 subprocess.call(['wget', '-O', tmparchive, install_url], stdout=devnull, stderr=devnull)
                 if install_url[-3:] == ".gz":
                     subprocess.call(['gunzip', '-c', tmparchive], stdout=devnull, stderr=devnull)
                     install_url = install_url[0:-3]
                 if install_url[-4:] == ".tar":
                     subprocess.call(['tar', '-xvf', tmparchive, '-C', tmpdir], stdout=devnull, stderr=devnull)
                 elif install_url[-4:] == ".zip":
                     subprocess.call(['unzip', '-j', '-o', tmparchive, '-d', tmpdir], stdout=devnull, stderr=devnull)
             else:
                 return 'cannot resolve requirement %s (from %s) with unrecognized VCS: %s' % (str(self), str(self._install_req), self.vcs)
     setup_dict, err = setup_py.setup_info_dir(tmpdir)
     if err is not None:
         return None, err
     shutil.rmtree(tmpdir)
     self.metadata = setup_dict
     return None
Esempio n. 2
0
 def resolve(self):
     """
     Downloads this requirement from the VCS repository or archive file and returns metadata from its setup.py.
     Returns an error string or None if no error.
     """
     tmpdir = tempfile.mkdtemp()
     with open(os.devnull, 'w') as devnull:
         # Because of a bug in pip when dealing with VCS URLs, we can't use pip to download the repository
         if self.vcs == 'git':
             subprocess.call(['git', 'clone', '--depth=1', self.url, tmpdir], stdout=devnull, stderr=devnull)
         elif self.vcs == 'hg':
             subprocess.call(['hg', 'clone', self.url, tmpdir], stdout=devnull, stderr=devnull)
         elif self.vcs is None and self.type == 'archive':
             install_url = self._install_req.url
             tmparchive = tempfile.mkstemp()[1]
             subprocess.call(['curl', '-L', install_url, '-o', tmparchive], stdout=devnull, stderr=devnull)
             if install_url.endswith(".gz"):
                 subprocess.call(['gunzip', '-c', tmparchive], stdout=devnull, stderr=devnull)
                 install_url = install_url[0:-3]
             if install_url.endswith(".tar"):
                 subprocess.call(['tar', '-xvf', tmparchive, '-C', tmpdir], stdout=devnull, stderr=devnull)
             elif install_url.endswith(".zip"):
                 subprocess.call(['unzip', '-j', '-o', tmparchive, '-d', tmpdir], stdout=devnull, stderr=devnull)
         else:
             return 'cannot resolve requirement %s (from %s) with unrecognized VCS: %s' % (str(self), str(self._install_req), self.vcs)
     setup_dict, err = setup_py.setup_info_dir(tmpdir)
     if err is not None:
         return None, err
     shutil.rmtree(tmpdir)
     self.metadata = setup_dict
     return None
Esempio n. 3
0
    def resolve(self):
        """Downloads this requirement from PyPI and returns metadata from its setup.py. Returns an error string or None if no error."""
        tmpdir = tempfile.mkdtemp()
        with open('/dev/null', 'w') as devnull:
            subprocess.call(['pip', 'install', '--build',  tmpdir, '--upgrade', '--force-reinstall', '--no-install', '--no-deps', '--no-use-wheel', str(self.req)],
                            stdout=devnull, stderr=devnull)
        projectdir = path.join(tmpdir, self.req.project_name)
        setup_dict, err = setup_py.setup_info_dir(projectdir)
        if err is not None:
            return None, err
        shutil.rmtree(tmpdir)

        self.metadata = setup_dict
        return None
Esempio n. 4
0
def requirements_from_setup_py(rootdir):
    """
    Accepts the root directory of a PyPI package and returns its requirements extracted from its setup.py
    Returns [], {'', None}
    """
    setup_dict, err = setup_py.setup_info_dir(rootdir)
    if err is not None:
        return None, err

    reqs = []
    if 'install_requires' in setup_dict:
        req_strs = setup_dict['install_requires']
        for req_str in req_strs:
            reqs.append(SetupToolsRequirement(pr.Requirement.parse(req_str)))
    return reqs, None
Esempio n. 5
0
    def resolve(self):
        """
        Downloads this requirement from the VCS repository and returns metadata from its setup.py.
        Returns an error string or None if no error.
        """
        tmpdir = tempfile.mkdtemp()
        with open('/dev/null', 'w') as devnull:
            # Because of a bug in pip when dealing with VCS URLs, we can't use pip to download the repository
            if self.vcs == 'git':
                subprocess.call(['git', 'clone', '--depth=1', self.url, tmpdir], stdout=devnull, stderr=devnull)
            elif self.vcs == 'hg':
                subprocess.call(['hg', 'clone', self.url, tmpdir], stdout=devnull, stderr=devnull)
            else:
                return 'cannot resolve requirement %s (from %s) with unrecognized VCS: %s' % (str(self), str(self._install_req), self.vcs)
        setup_dict, err = setup_py.setup_info_dir(tmpdir)
        if err is not None:
            return None, err
        shutil.rmtree(tmpdir)

        self.metadata = setup_dict
        return None