How to use the wheel.wheelfile.WheelFile function in wheel

To help you get started, we’ve selected a few wheel 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 / wheel / tests / test_bdist_wheel.py View on Github external
def test_licenses_deprecated(dummy_dist, monkeypatch, tmpdir):
    dummy_dist.join('setup.cfg').write('[metadata]\nlicense_file=licenses/DUMMYFILE')
    monkeypatch.chdir(dummy_dist)
    subprocess.check_call([sys.executable, 'setup.py', 'bdist_wheel', '-b', str(tmpdir),
                           '--universal'])
    with WheelFile('dist/dummy_dist-1.0-py2.py3-none-any.whl') as wf:
        license_files = {'dummy_dist-1.0.dist-info/DUMMYFILE'}
        assert set(wf.namelist()) == DEFAULT_FILES | license_files
github pypa / wheel / tests / test_wheelfile.py View on Github external
def test_testzip_missing_hash(wheel_path):
    with ZipFile(wheel_path, 'w') as zf:
        zf.writestr(native('hello/héllö.py'), as_bytes('print("Héllö, world!")\n'))
        zf.writestr('test-1.0.dist-info/RECORD', '')

    with WheelFile(wheel_path) as wf:
        exc = pytest.raises(WheelError, wf.testzip)
        exc.match(native("^No hash found for file 'hello/héllö.py'$"))
github pypa / wheel / tests / test_wheelfile.py View on Github external
def test_attributes(tmpdir_factory, wheel_path):
    # With the change from ZipFile.write() to .writestr(), we need to manually
    # set member attributes.
    build_dir = tmpdir_factory.mktemp('build')
    files = (('foo', 0o644), ('bar', 0o755))
    for filename, mode in files:
        path = build_dir.join(filename)
        path.write(filename + '\n')
        path.chmod(mode)

    with WheelFile(wheel_path, 'w') as wf:
        wf.write_files(str(build_dir))

    with ZipFile(wheel_path, 'r') as zf:
        for filename, mode in files:
            info = zf.getinfo(filename)
            assert info.external_attr == (mode | 0o100000) << 16
            assert info.compress_type == ZIP_DEFLATED

        info = zf.getinfo('test-1.0.dist-info/RECORD')
        permissions = (info.external_attr >> 16) & 0o777
        assert permissions == 0o664
github pypa / wheel / tests / test_wheelfile.py View on Github external
def test_timestamp(tmpdir_factory, wheel_path, monkeypatch):
    # An environment variable can be used to influence the timestamp on
    # TarInfo objects inside the zip.  See issue #143.
    build_dir = tmpdir_factory.mktemp('build')
    for filename in ('one', 'two', 'three'):
        build_dir.join(filename).write(filename + '\n')

    # The earliest date representable in TarInfos, 1980-01-01
    monkeypatch.setenv(native('SOURCE_DATE_EPOCH'), native('315576060'))

    with WheelFile(wheel_path, 'w') as wf:
        wf.write_files(str(build_dir))

    with ZipFile(wheel_path, 'r') as zf:
        for info in zf.infolist():
            assert info.date_time[:3] == (1980, 1, 1)
            assert info.compress_type == ZIP_DEFLATED
github pypa / wheel / tests / test_wheelfile.py View on Github external
def test_testzip(wheel_path, algorithm, digest):
    hash_string = '{}={}'.format(algorithm, digest)
    with ZipFile(wheel_path, 'w') as zf:
        zf.writestr(native('hello/héllö.py'), as_bytes('print("Héllö, world!")\n'))
        zf.writestr('test-1.0.dist-info/RECORD',
                    as_bytes('hello/héllö.py,{},25'.format(hash_string)))

    with WheelFile(wheel_path) as wf:
        wf.testzip()
github pypa / wheel / tests / test_bdist_wheel.py View on Github external
def test_licenses_default(dummy_dist, monkeypatch, tmpdir):
    monkeypatch.chdir(dummy_dist)
    subprocess.check_call([sys.executable, 'setup.py', 'bdist_wheel', '-b', str(tmpdir),
                           '--universal'])
    with WheelFile('dist/dummy_dist-1.0-py2.py3-none-any.whl') as wf:
        license_files = {'dummy_dist-1.0.dist-info/' + fname for fname in DEFAULT_LICENSE_FILES}
        assert set(wf.namelist()) == DEFAULT_FILES | license_files
github pypa / wheel / tests / test_wheelfile.py View on Github external
def test_wheelfile_re(tmpdir):
    # Regression test for #208
    path = tmpdir.join('foo-2-py3-none-any.whl')
    with WheelFile(str(path), 'w') as wf:
        assert wf.parsed_filename.group('namever') == 'foo-2'
github NoOne-hub / v2ray_client / venv / lib / python3.7 / site-packages / wheel / cli / pack.py View on Github external
# Read the tags from .dist-info/WHEEL
    with open(os.path.join(directory, dist_info_dir, 'WHEEL')) as f:
        tags = [line.split(' ')[1].rstrip() for line in f if line.startswith('Tag: ')]
        if not tags:
            raise WheelError('No tags present in {}/WHEEL; cannot determine target wheel filename'
                             .format(dist_info_dir))

    # Reassemble the tags for the wheel file
    impls = sorted({tag.split('-')[0] for tag in tags})
    abivers = sorted({tag.split('-')[1] for tag in tags})
    platforms = sorted({tag.split('-')[2] for tag in tags})
    tagline = '-'.join(['.'.join(impls), '.'.join(abivers), '.'.join(platforms)])

    # Repack the wheel
    wheel_path = os.path.join(dest_dir, '{}-{}.whl'.format(name_version, tagline))
    with WheelFile(wheel_path, 'w') as wf:
        print("Repacking wheel as {}...".format(wheel_path), end='')
        sys.stdout.flush()
        wf.write_files(directory)

    print('OK')
github apt-itude / rules_pip / download / create_wheels_repo.py View on Github external
def unpack_wheel(wheel_path, repository_directory):
    # TODO(): don't use unsupported wheel library
    with wheelfile.WheelFile(wheel_path) as wheel_file:
        distribution_name = wheel_file.parsed_filename.group("name")
        library_name = normalize_distribution_name(distribution_name)
        package_directory = os.path.join(repository_directory, library_name)
        wheel_file.extractall(package_directory)

    try:
        return next(pkg_resources.find_distributions(package_directory))
    except StopIteration:
        raise DistributionNotFoundError(package_directory)
github scikit-build / scikit-build / skbuild / command / bdist_wheel.py View on Github external
def run(self, *args, **kwargs):
        """Handle --hide-listing option."""

        if _USE_WHEELFILE:
            old_write_files = WheelFile.write_files

            def update_write_files(wheelfile_self, base_dir):
                with distribution_hide_listing(self.distribution) as hide_listing:
                    if hide_listing:
                        zip_filename = wheelfile_self.filename
                        print("creating '%s' and adding '%s' to it"
                              % (zip_filename, base_dir))
                    old_write_files(wheelfile_self, base_dir)

            WheelFile.distribution = self.distribution
            WheelFile.write_files = update_write_files

            try:
                super(bdist_wheel, self).run(*args, **kwargs)
            finally:
                WheelFile.write_files = old_write_files