Esempio n. 1
0
    def test_bdist_wheel(self):
        filename = data_path('test_package34-0.3.1-py2-none-any.whl')

        with open(filename, 'rb') as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(
                filename, fd)

        expected_file_data = {
            'attrs': {
                'abi': None,
                'build_no': 0,
                'packagetype': 'bdist_wheel',
                'python_version': 'py2'
            },
            'basename': 'test_package34-0.3.1-py2-none-any.whl',
            'dependencies': expected_whl_dependencies,
            'platform': None
        }

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_file_data), set(file_data))
        for key in expected_file_data:
            self.assertEqual(expected_file_data[key], file_data[key])
Esempio n. 2
0
    def test_sdist_distutils(self):
        filename = data_dir('test_package34-distutils-0.3.1.tar.gz')
        with open(filename, 'rb') as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd)


        expected_file_data = {'attrs': {'packagetype': 'sdist', 'python_version': 'source'},
                              'basename': 'test_package34-distutils-0.3.1.tar.gz',
                              'dependencies': {'depends': [{'name': 'requests',
                                                            'specs': [('>=', '2.0'), ('<=', '3.0')]},
                                                           {'name': 'pyyaml', 'specs': [('==', '2.0')]},
                                                           {'name': 'pytz', 'specs': []}],
                                               'extras': [],
                                               'has_dep_errors': False}}

        dexpected_package_data = expected_package_data.copy()
        dexpected_package_data['name'] = dexpected_package_data['name'].replace('-', '_')
        self.assertEqual(dexpected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)
        self.assertEqual(set(expected_file_data), set(file_data))

        for key in expected_file_data:
            print(expected_file_data[key])
            print(file_data[key])
            self.assertEqual(expected_file_data[key], file_data[key])
Esempio n. 3
0
    def test_sdist_distutils(self):
        filename = data_path("test_package34-distutils-0.3.1.tar.gz")
        with open(filename, "rb") as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd)

        expected_file_data = {
            "attrs": {"packagetype": "sdist", "python_version": "source"},
            "basename": "test_package34-distutils-0.3.1.tar.gz",
            "dependencies": {
                "depends": [
                    {"name": "requests", "specs": [(">=", "2.0"), ("<=", "3.0")]},
                    {"name": "pyyaml", "specs": [("==", "2.0")]},
                    {"name": "pytz", "specs": []},
                ],
                "extras": [],
                "has_dep_errors": False,
            },
        }

        dexpected_package_data = expected_package_data.copy()
        dexpected_package_data["name"] = dexpected_package_data["name"].replace("-", "_")
        self.assertEqual(dexpected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)
        self.assertEqual(set(expected_file_data), set(file_data))

        for key in expected_file_data:
            self.assertEqual(expected_file_data[key], file_data[key])
Esempio n. 4
0
    def test_bdist_egg_dashed_path(self):
        filename = data_path("test_package34-0.3.1-py2.7.egg")
        tmpdir = tempfile.gettempdir()
        dash_count = tmpdir.count("-")
        if dash_count == 0:
            tmpdir = path.join(tmpdir, "has-dash")
            try:
                os.mkdir(tmpdir)
            except (IOError, OSError):
                raise unittest.SkipTest("Cannot create temporary directory %r" % tmpdir)
        elif dash_count > 1:
            raise unittest.SkipTest("Too many dashes in temporary directory path %r" % tmpdir)

        try:
            shutil.copy(filename, tmpdir)
        except (IOError, OSError):
            raise unittest.SkipTest("Cannot copy package to temporary directory")

        tmpfilename = path.join(tmpdir, "test_package34-0.3.1-py2.7.egg")

        with open(tmpfilename, "rb") as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(tmpfilename, fd)

        # If we could create this file, we ought to be able to delete it
        os.remove(tmpfilename)
        if dash_count == 0:
            # We created a temporary directory like /tmp/has-dash, delete it
            os.rmdir(tmpdir)

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_egg_file_data), set(file_data))
        self.assertEqual(expected_egg_file_data["platform"], file_data["platform"])
        self.assertEqual(expected_egg_file_data["attrs"]["python_version"], file_data["attrs"]["python_version"])
Esempio n. 5
0
    def get_package(self, spec, parent_channels=()):

        res = req.get('https://pypi.python.org/pypi/%s/json' % spec.package)
        info = res.json()
        versions = {Version.coerce(v):r for v, r in info['releases'].items()}
        version = max(spec.version_spec.filter(versions.keys()))
        releases = versions[version]

        data = info['info']
        data['files'] = []

        for file_info in releases:
            file_info['basename'] = file_info['filename']
            file_info['attrs'] = {'packagetype': file_info['packagetype']}
            file_info['distribution_type'] = 'pypi'
            file_info['version'] = str(version)
            file_info['md5'] = file_info['md5_digest']

            data['files'].append(file_info)

        pkg = Package(self.env, data)

        self.fetch(pkg.file)

        with open(pkg.file.cache_path) as fileobj:
            _, _, data = pypi_inspect.inspect_pypi_package(pkg.file.cache_path, fileobj)
            file_info['dependencies'] = data.get('dependencies', [])

        return pkg
Esempio n. 6
0
    def test_bdist_egg(self):
        filename = data_path("test_package34-0.3.1-py2.7.egg")

        with open(filename, "rb") as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd)

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_egg_file_data), set(file_data))
        for key in expected_egg_file_data:
            self.assertEqual(expected_egg_file_data[key], file_data[key])
Esempio n. 7
0
    def test_bdist_egg(self):
        filename = data_path('test_package34-0.3.1-py2.7.egg')

        with open(filename, 'rb') as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(
                filename, fd)

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_egg_file_data), set(file_data))
        for key in expected_egg_file_data:
            self.assertEqual(expected_egg_file_data[key], file_data[key])
Esempio n. 8
0
    def test_sdist(self):
        filename = data_dir('test_package34-0.3.1.tar.gz')
        with open(filename, 'rb') as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd)


        expected_file_data = {'attrs': {'packagetype': 'sdist', 'python_version': 'source'},
                              'basename': 'test_package34-0.3.1.tar.gz',
                              'dependencies': expected_dependencies}

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_file_data), set(file_data))
        for key in expected_file_data:
            self.assertEqual(expected_file_data[key], file_data[key])
Esempio n. 9
0
    def test_sdist(self):
        filename = data_path("test_package34-0.3.1.tar.gz")
        with open(filename, "rb") as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd)

        expected_file_data = {
            "attrs": {"packagetype": "sdist", "python_version": "source"},
            "basename": "test_package34-0.3.1.tar.gz",
            "dependencies": expected_dependencies,
        }

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_file_data), set(file_data))
        for key in expected_file_data:
            self.assertEqual(expected_file_data[key], file_data[key])
Esempio n. 10
0
    def test_bdist_egg(self):
        filename = data_path('test_package34-0.3.1-py2.7.egg')

        with open(filename, 'rb') as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd)


        expected_file_data = {'attrs': {'packagetype': 'bdist_egg', 'python_version': 'source'},
                             'basename': 'test_package34-0.3.1-py2.7.egg',
                             'dependencies': expected_dependencies,
                             'platform': None}

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_file_data), set(file_data))
        for key in expected_file_data:
            self.assertEqual(expected_file_data[key], file_data[key])
Esempio n. 11
0
    def test_bdist_wheel_newer_version(self):
        filename_whl = 'azure_cli_extension-0.2.1-py2.py3-none-any.whl'
        filename = data_dir(filename_whl)

        with open(filename, 'rb') as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd)

        expected_file_data = {
            'platform': None,
            'basename': filename_whl,
            'dependencies': {
                u'depends': [
                    {u'name': u'azure-cli-command-modules-nspkg', u'specs': [(u'>=', u'2.0.0')]},
                    {u'name': u'azure-cli-core', u'specs': []}, {u'name': u'pip', u'specs': []},
                    {u'name': u'wheel', u'specs': [(u'==', u'0.30.0')]}
                ],
                u'extras': [],
                u'has_dep_errors': False,
                u'environments': []},
            u'attrs': {
                'abi': None,
                'packagetype': u'bdist_wheel',
                'python_version': u'py2.py3',
                'build_no': 0
            }
        }
        expected_package_data = {
            u'name': 'azure-cli-extension',
            u'license': 'MIT',
            u'summary': 'Microsoft Azure Command-Line Tools Extension Command Module',
        }
        expected_version_data = {
            u'home_page': 'https://github.com/Azure/azure-cli',
            u'version': '0.2.1',
            u'description': u"Microsoft Azure CLI 'extension' Command Module",
        }
        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)
        self.assertEqual(set(expected_file_data), set(file_data))
        for key in expected_file_data:
            print(expected_file_data[key])
            print(file_data[key])
            self.assertEqual(expected_file_data[key], file_data[key])
Esempio n. 12
0
    def test_bdist_wheel(self):
        filename = data_path("test_package34-0.3.1-py2-none-any.whl")

        with open(filename, "rb") as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd)

        expected_file_data = {
            "attrs": {"abi": None, "build_no": 0, "packagetype": "bdist_wheel", "python_version": "py2"},
            "basename": "test_package34-0.3.1-py2-none-any.whl",
            "dependencies": expected_whl_dependencies,
            "platform": None,
        }

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_file_data), set(file_data))
        for key in expected_file_data:
            self.assertEqual(expected_file_data[key], file_data[key])
Esempio n. 13
0
    def test_bdist_wheel(self):
        filename = data_path('test_package34-0.3.1-py2-none-any.whl')

        with open(filename, 'rb') as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd)

        expected_file_data = {'attrs': {'abi': None, 'build_no': 0,
                                        'packagetype': 'bdist_wheel',
                                        'python_version': 'py2'},
                             'basename': 'test_package34-0.3.1-py2-none-any.whl',
                             'dependencies': expected_whl_dependencies,
                             'platform': None}

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)


        self.assertEqual(set(expected_file_data), set(file_data))
        for key in expected_file_data:
            self.assertEqual(expected_file_data[key], file_data[key])
Esempio n. 14
0
    def test_bdist_egg_dashed_path(self):
        filename = data_path('test_package34-0.3.1-py2.7.egg')
        tmpdir = tempfile.gettempdir()
        dash_count = tmpdir.count('-')
        if dash_count == 0:
            tmpdir = path.join(tmpdir, 'has-dash')
            try:
                os.mkdir(tmpdir)
            except (IOError, OSError):
                raise unittest.SkipTest(
                    'Cannot create temporary directory %r' % tmpdir)
        elif dash_count > 1:
            raise unittest.SkipTest(
                'Too many dashes in temporary directory path %r' % tmpdir)

        try:
            shutil.copy(filename, tmpdir)
        except (IOError, OSError):
            raise unittest.SkipTest(
                'Cannot copy package to temporary directory')

        tmpfilename = path.join(tmpdir, 'test_package34-0.3.1-py2.7.egg')

        with open(tmpfilename, 'rb') as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(
                tmpfilename, fd)

        # If we could create this file, we ought to be able to delete it
        os.remove(tmpfilename)
        if dash_count == 0:
            # We created a temporary directory like /tmp/has-dash, delete it
            os.rmdir(tmpdir)

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_egg_file_data), set(file_data))
        self.assertEqual(expected_egg_file_data['platform'],
                         file_data['platform'])
        self.assertEqual(expected_egg_file_data['attrs']['python_version'],
                         file_data['attrs']['python_version'])
Esempio n. 15
0
    def test_bdist_egg(self):
        filename = data_path('test_package34-0.3.1-py2.7.egg')

        with open(filename, 'rb') as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(
                filename, fd)

        expected_file_data = {
            'attrs': {
                'packagetype': 'bdist_egg',
                'python_version': 'source'
            },
            'basename': 'test_package34-0.3.1-py2.7.egg',
            'dependencies': expected_dependencies,
            'platform': None
        }

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_file_data), set(file_data))
        for key in expected_file_data:
            self.assertEqual(expected_file_data[key], file_data[key])
    def test_bdist_egg_dashed_path(self):
        filename = data_dir('test_package34-0.3.1-py2.7.egg')
        tmpdir = tempfile.gettempdir()
        dash_count = tmpdir.count('-')
        if dash_count == 0:
            tmpdir = os.path.join(tmpdir, 'has-dash')
            try:
                os.mkdir(tmpdir)
            except (IOError, OSError):
                raise unittest.SkipTest('Cannot create temporary directory %r' % tmpdir)
        elif dash_count > 1:
            raise unittest.SkipTest('Too many dashes in temporary directory path %r' % tmpdir)

        try:
            shutil.copy(filename, tmpdir)
        except (IOError, OSError):
            raise unittest.SkipTest('Cannot copy package to temporary directory')

        tmpfilename = os.path.join(tmpdir, 'test_package34-0.3.1-py2.7.egg')

        with open(tmpfilename, 'rb') as fd:
            package_data, version_data, file_data = pypi.inspect_pypi_package(tmpfilename, fd)

        # If we could create this file, we ought to be able to delete it
        os.remove(tmpfilename)
        if dash_count == 0:
            # We created a temporary directory like /tmp/has-dash, delete it
            os.rmdir(tmpdir)

        self.assertEqual(expected_package_data, package_data)
        self.assertEqual(expected_version_data, version_data)

        self.assertEqual(set(expected_egg_file_data), set(file_data))
        self.assertEqual(expected_egg_file_data['platform'], file_data['platform'])
        self.assertEqual(expected_egg_file_data['attrs']['python_version'],
                         file_data['attrs']['python_version'])