How to use the twine.package.PackageFile function in twine

To help you get started, we’ve selected a few twine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pypa / twine / tests / test_package.py View on Github external
download_url=pretend.stub(),
        supported_platforms=pretend.stub(),
        provides=pretend.stub(),
        requires=pretend.stub(),
        obsoletes=pretend.stub(),
        project_urls=pretend.stub(),
        provides_dist=pretend.stub(),
        obsoletes_dist=pretend.stub(),
        requires_dist=pretend.stub(),
        requires_external=pretend.stub(),
        requires_python=pretend.stub(),
        provides_extras=pretend.stub(),
        description_content_type=pretend.stub(),
    )

    package = package_file.PackageFile(
        filename="tests/fixtures/twine-1.5.0-py2.py3-none-any.whl",
        comment=pretend.stub(),
        metadata=meta,
        python_version=pretend.stub(),
        filetype=pretend.stub(),
    )
    package.gpg_signature = gpg_signature

    result = package.metadata_dictionary()

    # identify release
    assert result["name"] == package.safe_name
    assert result["version"] == meta.version

    # file content
    assert result["filetype"] == package.filetype
github sdispater / poet / poet / publisher.py View on Github external
:type poet: poet.poet.Poet
        """
        skip_existing = False
        dists = find_dists(
            [
                os.path.join(
                    os.path.join(poet.base_dir, 'dist'),
                    '{}-{}*'.format(poet.name, poet.version)
                )
            ]
        )

        uploads = [i for i in dists if not i.endswith(".asc")]

        for filename in uploads:
            package = PackageFile.from_filename(filename, None)
            skip_message = (
                " - Skipping {0} because it appears to already exist"
                .format(
                    package.basefilename
                )
            )

            # Note: The skip_existing check *needs* to be first, because otherwise
            #       we're going to generate extra HTTP requests against a hardcoded
            #       URL for no reason.
            if skip_existing and self._repository.package_is_uploaded(package):
                self._output.writeln(skip_message)
                continue

            resp = self._repository.upload(package)
github sdispater / poet / poet / publisher.py View on Github external
def register(self, poet):
        """
        Register a package represented by a Poet instance.
        
        :param poet: The Poet instance representing the package.
        :type poet: poet.poet.Poet
        """
        package = os.path.join(poet.base_dir, 'dist', poet.archive)

        if not os.path.exists(package):
            raise PackageNotFound(
                '"{0}" does not exist on the file system.'.format(package)
            )

        resp = self._repository.register(PackageFile.from_filename(package, None))
        self._repository.close()

        if resp.is_redirect:
            raise RedirectDetected(
                ('"{0}" attempted to redirect to "{1}" during registration.'
                 ' Aborting...').format(self._repository.url,
                                        resp.headers["location"]))

        resp.raise_for_status()