Esempio n. 1
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', str(self.url), tmpdir], stdout=devnull, stderr=devnull)
         elif self.vcs == 'hg':
             subprocess.call(['hg', 'clone', str(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 {} (from {}) with unrecognized VCS: {}'.format(
                 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
     rmtree(tmpdir)
     self.metadata = setup_dict
     return None
Esempio n. 2
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.
        """
        tmp_dir = tempfile.mkdtemp()
        with open(os.devnull, 'w') as devnull:
            try:
                cmd = ['install', '--quiet',
                       '--download',  tmp_dir,
                       '--build',  tmp_dir,
                       '--no-clean', '--no-deps',
                       '--no-binary', ':all:', str(self.req)]
                pip.main(cmd)
            except Exception as e:
                rmtree(tmp_dir)
                return 'error downloading requirement: {}'.format(str(e))

        project_dir = path.join(tmp_dir, self.req.project_name)
        setup_dict, err = setup_py.setup_info_dir(project_dir)
        if err is not None:
            return None, err
        rmtree(tmp_dir)

        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(os.devnull, '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(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:
                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