Exemple #1
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
Exemple #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', 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
Exemple #3
0
def smoke_test(args):
    """Test subcommand that runs pydep on a few popular repositories and prints the results."""
    testcases = [
        ('Flask', 'https://github.com/mitsuhiko/flask.git'),
        ('Graphite, a webapp that depends on Django', 'https://github.com/graphite-project/graphite-web'),
        # TODO: update smoke_test to call setup_dirs/list instead of assuming setup.py exists at the repository root
        # ('Node', 'https://github.com/joyent/node.git'),
    ]
    tmpdir = None
    try:
        tmpdir = tempfile.mkdtemp()
        for title, cloneURL in testcases:
            print('Downloading and processing %s...' % title)
            subdir = path.splitext(path.basename(cloneURL))[0]
            dir_ = path.join(tmpdir, subdir)
            with open('/dev/null', 'w') as devnull:
                subprocess.call(['git', 'clone', cloneURL, dir_], stdout=devnull, stderr=devnull)

            print('')
            reqs, err = pydep.req.requirements(dir_, True)
            if err is None:
                print('Here is some info about the dependencies of %s' % title)
                if len(reqs) == 0:
                    print('(There were no dependencies found for %s)' % title)
                else:
                    print(json.dumps(reqs, indent=2))
            else:
                print('failed with error: %s' % err)

            print('')
            setup_dict, err = pydep.setup_py.setup_info_dir(dir_)
            if err is None:
                print('Here is the metadata for %s' % title)
                print(json.dumps(setup_dict_to_json_serializable_dict(setup_dict), indent=2))
            else:
                print('failed with error: %s' % err)

    except Exception as e:
        print('failed with exception %s' % str(e))
    finally:
        if tmpdir:
            util.rmtree(tmpdir)