Ejemplo n.º 1
0
    def transform_name(self, python_package_name, *extras):
        """
        Transform Python package name to Debian package name.

        :param python_package_name: The name of a Python package
                                    as found on PyPI (a string).
        :param extras: Any extras requested to be included (a tuple of strings).
        :returns: The transformed name (a string).

        Examples:

        >>> from py2deb.converter import PackageConverter
        >>> converter = PackageConverter()
        >>> converter.transform_name('example')
        'python-example'
        >>> converter.set_name_prefix('my-custom-prefix')
        >>> converter.transform_name('example')
        'my-custom-prefix-example'
        >>> converter.set_name_prefix('some-web-app')
        >>> converter.transform_name('raven', 'flask')
        'some-web-app-raven-flask'

        """
        key = python_package_name.lower()
        # Check for a system package override by the caller.
        debian_package_name = self.system_packages.get(key)
        if debian_package_name:
            # We don't modify the names of system packages.
            return debian_package_name
        # Check for a package rename override by the caller.
        debian_package_name = self.name_mapping.get(key)
        if not debian_package_name:
            # No override. Make something up :-).
            debian_package_name = convert_package_name(
                python_package_name=python_package_name,
                name_prefix=self.name_prefix,
                extras=extras,
            )
        # Always normalize the package name (even if it was given to us by the caller).
        return normalize_package_name(debian_package_name)
Ejemplo n.º 2
0
    def test_conversion_of_package_with_dependencies(self):
        """
        Convert a non trivial Python package with several dependencies.

        Converts deb-pkg-tools_ to a Debian package archive and sanity checks the
        result. Performs static checks on the metadata (dependencies) of the
        resulting package archive.

        .. _deb-pkg-tools: https://pypi.org/project/deb-pkg-tools
        """
        # Use a temporary directory as py2deb's repository directory so that we
        # can easily find the *.deb archive generated by py2deb.
        with TemporaryDirectory() as directory:
            # Run the conversion command.
            exit_code, output = run_cli(main, '--repository=%s' % directory,
                                        'deb-pkg-tools==1.22')
            assert exit_code == 0
            # Find the generated Debian package archives.
            archives = glob.glob('%s/*.deb' % directory)
            logger.debug("Found generated archive(s): %s", archives)
            # Make sure the expected dependencies have been converted.
            converted_dependencies = set(
                parse_filename(a).name for a in archives)
            expected_dependencies = set(
                convert_package_name(n) for n in (
                    'cached-property',
                    'chardet',
                    'coloredlogs',
                    'deb-pkg-tools',
                    'executor',
                    'humanfriendly',
                    'python-debian',
                    'six',
                ))
            assert expected_dependencies.issubset(converted_dependencies)
            # Use deb-pkg-tools to inspect ... deb-pkg-tools :-)
            pathname = find_package_archive(
                archives, fix_name_prefix('python-deb-pkg-tools'))
            metadata, contents = inspect_package(pathname)
            logger.debug("Metadata of generated package: %s", dict(metadata))
            logger.debug("Contents of generated package: %s", dict(contents))
            # Make sure the dependencies defined in `stdeb.cfg' have been preserved.
            for configured_dependency in [
                    'apt', 'apt-utils', 'dpkg-dev', 'fakeroot', 'gnupg',
                    'lintian'
            ]:
                logger.debug("Checking configured dependency %s ..",
                             configured_dependency)
                assert metadata['Depends'].matches(
                    configured_dependency) is not None
            # Make sure the dependencies defined in `setup.py' have been preserved.
            expected_dependencies = [
                convert_package_name(n) for n in (
                    'chardet',
                    'coloredlogs',
                    'executor',
                    'humanfriendly',
                    'python-debian',
                )
            ]
            for python_dependency in expected_dependencies:
                logger.debug("Checking Python dependency %s ..",
                             python_dependency)
                assert metadata['Depends'].matches(
                    python_dependency) is not None