def convert(self, pip_install_arguments): """ Convert one or more Python packages to Debian packages. :param pip_install_arguments: The command line arguments to the ``pip install`` command. :returns: A tuple with two lists: 1. A list of strings containing the pathname(s) of the generated Debian package package archive(s). 2. A list of strings containing the Debian package relationship(s) required to depend on the converted package(s). :raises: :exc:`~deb_pkg_tools.checks.DuplicateFilesFound` if two converted package archives contain the same files (certainly not what you want within a set of dependencies). Here's an example of what's returned: >>> from py2deb.converter import PackageConverter >>> converter = PackageConverter() >>> archives, relationships = converter.convert(['py2deb']) >>> print(archives) ['/tmp/python-py2deb_0.18_all.deb'] >>> print(relationships) ['python-py2deb (=0.18)'] """ try: generated_archives = [] dependencies_to_report = [] # Download and unpack the requirement set and store the complete # set as an instance variable because transform_version() will need # it later on. self.packages_to_convert = list(self.get_source_distributions(pip_install_arguments)) # Convert packages that haven't been converted already. for package in self.packages_to_convert: # If the requirement is a 'direct' (non-transitive) requirement # it means the caller explicitly asked for this package to be # converted, so we add it to the list of converted dependencies # that we report to the caller once we've finished converting. if package.requirement.is_direct: dependencies_to_report.append('%s (= %s)' % (package.debian_name, package.debian_version)) if package.existing_archive: # If the same version of this package was converted in a # previous run we can save a lot of time by skipping it. logger.info("Package %s (%s) already converted: %s", package.python_name, package.python_version, package.existing_archive.filename) generated_archives.append(package.existing_archive) else: archive = package.convert() if not os.path.samefile(os.path.dirname(archive), self.repository.directory): shutil.move(archive, self.repository.directory) archive = os.path.join(self.repository.directory, os.path.basename(archive)) generated_archives.append(archive) # Use deb-pkg-tools to sanity check the generated package archives # for duplicate files. This should never occur but unfortunately # can happen because Python's packaging infrastructure is a lot # more `forgiving' in the sense of blindly overwriting files # installed by other packages ;-). if len(generated_archives) > 1: check_duplicate_files(generated_archives, cache=get_default_cache()) # Let the caller know which archives were generated (whether # previously or now) and how to depend on the converted packages. return generated_archives, sorted(dependencies_to_report) finally: # Always clean up temporary directories created by pip and pip-accel. self.pip_accel.cleanup_temporary_directories()
def convert(self, pip_install_arguments): """ Convert one or more Python packages to Debian packages. :param pip_install_arguments: The command line arguments to the ``pip install`` command. :returns: A tuple with two lists: 1. A list of strings containing the pathname(s) of the generated Debian package package archive(s). 2. A list of strings containing the Debian package relationship(s) required to depend on the converted package(s). :raises: :py:exc:`~deb_pkg_tools.checks.DuplicateFilesFound` if two converted package archives contain the same files (certainly not what you want within a set of dependencies). Here's an example of what's returned: >>> from py2deb import PackageConverter >>> converter = PackageConverter() >>> archives, relationships = converter.convert(['py2deb']) >>> print(archives) ['/tmp/python-py2deb_0.18_all.deb'] >>> print(relationships) ['python-py2deb (=0.18)'] """ try: generated_archives = [] dependencies_to_report = [] # Download and unpack the requirement set and store the complete # set as an instance variable because transform_version() will need # it later on. self.packages_to_convert = list(self.get_source_distributions(pip_install_arguments)) # Convert packages that haven't been converted already. for package in self.packages_to_convert: # If the requirement is a 'direct' (non-transitive) requirement # it means the caller explicitly asked for this package to be # converted, so we add it to the list of converted dependencies # that we report to the caller once we've finished converting. if package.requirement.is_direct: dependencies_to_report.append('%s (= %s)' % (package.debian_name, package.debian_version)) if package.existing_archive: # If the same version of this package was converted in a # previous run we can save a lot of time by skipping it. logger.info("Package %s (%s) already converted: %s", package.python_name, package.python_version, package.existing_archive.filename) generated_archives.append(package.existing_archive) else: archive = package.convert() if not os.path.samefile(os.path.dirname(archive), self.repository.directory): shutil.move(archive, self.repository.directory) archive = os.path.join(self.repository.directory, os.path.basename(archive)) generated_archives.append(archive) # Use deb-pkg-tools to sanity check the generated package archives # for duplicate files. This should never occur but unfortunately # can happen because Python's packaging infrastructure is a lot # more `forgiving' in the sense of blindly overwriting files # installed by other packages ;-). if len(generated_archives) > 1: check_duplicate_files(generated_archives, cache=get_default_cache()) # Let the caller know which archives were generated (whether # previously or now) and how to depend on the converted packages. return generated_archives, sorted(dependencies_to_report) finally: # Always clean up temporary directories created by pip and pip-accel. self.pip_accel.cleanup_temporary_directories()