コード例 #1
0
 def test_write_default_compress_type_is_from_init(self, buf, tmp_file):
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    compression=ZIP_BZIP2)
     wf.write(tmp_file)
     assert wf.infolist()[0].compress_type == ZIP_BZIP2
コード例 #2
0
 def test_writestr_distinfo_default_compress_type_is_from_init(self, buf):
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    compression=ZIP_BZIP2)
     wf.writestr_distinfo('file', b'data')
     assert wf.infolist()[0].compress_type == ZIP_BZIP2
コード例 #3
0
 def wf(self, buf):
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    compression=ZIP_STORED,
                    compresslevel=1)
     yield wf
     wf.close()
コード例 #4
0
 def test_passes_strict_timestamps_arg_to_zipfile(self, buf, tmp_file):
     wf = WheelFile(buf,
                    mode='w',
                    distname='_',
                    version='0',
                    strict_timestamps=False)
     # strict_timestamps will be propagated into ZipInfo objects created by
     # ZipFile.
     # Given very old timestamp, ZipInfo will set itself to 01-01-1980
     os.utime(tmp_file, (10000000, 100000000))
     wf.write(tmp_file, resolve=False)
     zinfo = wf.zipfile.getinfo(str(tmp_file).lstrip('/'))
     assert zinfo.date_time == (1980, 1, 1, 0, 0, 0)
コード例 #5
0
    def test_on_bufs_x_mode_behaves_same_as_w(self):
        f1, f2 = BytesIO(), BytesIO()
        wf1 = WheelFile(f1, 'w', distname='_', version='0')
        wf1.close()
        wf2 = WheelFile(f2, 'w', distname='_', version='0')
        wf2.close()

        assert f1.getvalue() == f2.getvalue()
コード例 #6
0
def empty_wheel(tmp_path) -> Path:
    with WheelFile(tmp_path,
                   'w',
                   distname='wheelfile_test_wheel',
                   version='0.0.0') as wf:
        pass
    return wf
コード例 #7
0
 def test_passes_compression_arg_to_zipfile(self, buf):
     wf = WheelFile(buf,
                    mode='w',
                    distname='_',
                    version='0',
                    compression=ZIP_BZIP2)
     assert wf.zipfile.compression == ZIP_BZIP2
コード例 #8
0
 def test_passes_compresslevel_arg_to_zipfile(self, buf):
     wf = WheelFile(buf,
                    mode='w',
                    distname='_',
                    version='0',
                    compresslevel=7)
     assert wf.zipfile.compresslevel == 7
コード例 #9
0
def build_wheel(wheel_directory,
                config_settings=None, metadata_directory=None):
    config = get_config()

    maintainers = config['maintainers']
    if isinstance(maintainers, list):
        maintainers = ', '.join(maintainers)

    maintainers_emails = config['maintainers_emails']
    if isinstance(maintainers_emails, list):
        maintainers_emails = ', '.join(config['maintainers_emails'])

    requirements = Path('requirements.txt').read_text().splitlines()

    spec = {
        'distname': config['name'],
        'version': config['version'],
    }

    with WheelFile(wheel_directory, 'w', **spec) as wf:
        wf.metadata.maintainer = maintainers
        wf.metadata.maintainer_email = maintainers_emails
        wf.metadata.requires_dists = requirements

        wf.write('src/')

    return wf.filename  # 🧀
コード例 #10
0
 def test_given_directory_and_all_args__sets_filename(self, tmp_path):
     with WheelFile(tmp_path, 'w', distname='my_dist',
                    version='1.0.0') as wf:
         expected_name = '-'.join(
             (wf.distname, str(wf.version), wf.language_tag, wf.abi_tag,
              wf.platform_tag)) + '.whl'
         assert wf.filename == str(tmp_path / expected_name)
コード例 #11
0
 def test_passes_zipfile_kwargs_to_zipfile(self, buf, zfarg):
     argument_to_pass_to_zipfile = zfarg
     WheelFile(buf,
               mode='w',
               distname='_',
               version='0',
               **argument_to_pass_to_zipfile)
コード例 #12
0
 def test_given_language_tag_is_stored_in_language_tag_attr(self, buf):
     language_tag = 'cp3'
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    language_tag=language_tag)
     assert wf.language_tag == language_tag
コード例 #13
0
 def test_if_given_build_number_passes_it_to_wheeldata(self, buf):
     build_tag = 123
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    build_tag=build_tag)
     assert wf.wheeldata.build == build_tag
コード例 #14
0
 def test_build_number_can_be_str(self, buf):
     build_tag = '123'
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    build_tag=build_tag)
     assert wf.wheeldata.build == int(build_tag)
コード例 #15
0
 def test_if_given_language_tag_passes_it_to_wheeldata_tags(self, buf):
     language_tag = 'ip2'
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    language_tag=language_tag)
     assert wf.wheeldata.tags == ['ip2-none-any']
コード例 #16
0
 def test_infers_from_given_path(self, tmp_path, target_type):
     path = target_type(
         tmp_path / "my_awesome.wheel-4.2.0-py38-cp38d-linux_x84_64.whl")
     wf = WheelFile(path, 'w')
     assert (wf.distname == "my_awesome.wheel"
             and str(wf.version) == '4.2.0' and wf.language_tag == 'py38'
             and wf.abi_tag == 'cp38d'
             and wf.platform_tag == 'linux_x84_64')
コード例 #17
0
 def test_given_platform_tag_is_stored_in_abi_tag_attr(self, buf):
     platform_tag = 'win32'
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    platform_tag=platform_tag)
     assert wf.platform_tag == platform_tag
コード例 #18
0
 def test_given_str_build_tag_stores_int_in_build_tag_attr(self, buf):
     build_tag = '123'
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    build_tag=build_tag)
     assert wf.build_tag == int(build_tag)
コード例 #19
0
 def test_given_build_tag_is_stored_in_build_tag_attr(self, buf):
     build_tag = 123
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    build_tag=build_tag)
     assert wf.build_tag == build_tag
コード例 #20
0
 def test_if_given_platform_tag_passes_it_to_wheeldata_tags(self, buf):
     platform_tag = 'linux_x84_64'
     wf = WheelFile(buf,
                    'w',
                    distname='_',
                    version='0',
                    platform_tag=platform_tag)
     assert wf.wheeldata.tags == ['py3-none-linux_x84_64']
コード例 #21
0
 def test_infers_from_given_path_with_build_tag(self, tmp_path,
                                                target_type):
     path = target_type(
         tmp_path / "my_awesome.wheel-1.2.3.dev0-5-ip37-cp38d-win32.whl")
     wf = WheelFile(path, 'w')
     assert (wf.distname == "my_awesome.wheel"
             and str(wf.version) == '1.2.3.dev0' and wf.build_tag == 5
             and wf.language_tag == 'ip37' and wf.abi_tag == 'cp38d'
             and wf.platform_tag == 'win32')
コード例 #22
0
 def test_given_no_target_assumes_curdir(self, tmp_path):
     old_path = Path.cwd()
     os.chdir(tmp_path)
     with WheelFile(mode='w', distname='my_dist', version='1.0.0') as wf:
         expected_name = '-'.join(
             (wf.distname, str(wf.version), wf.language_tag, wf.abi_tag,
              wf.platform_tag)) + '.whl'
         assert wf.filename == str(Path('./') / expected_name)
     os.chdir(old_path)
コード例 #23
0
    def test_recursive_writes_dont_misformat_record(self, tmp_path, buf):
        (tmp_path / "dir1").mkdir()
        written_dir = (tmp_path / "dir1" / "dir2")
        written_dir.mkdir()

        wf = WheelFile(buf, 'w', distname='mywheel', version='1')
        wf.write(tmp_path / "dir1", recursive=True)
        wf.close()

        wf = WheelFile(buf, 'r', distname='mywheel', version='1')
        assert str(written_dir) not in str(wf.record)
コード例 #24
0
 def test_given_no_target_creates_file_from_args(self, tmp_path):
     old_path = Path.cwd()
     os.chdir(tmp_path)
     with WheelFile(mode='w',
                    distname='my_dist',
                    version='1.2.alpha1',
                    build_tag=123,
                    language_tag='jp2',
                    abi_tag='jre8',
                    platform_tag='win32') as wf:
         expected_name = 'my_dist-1.2a1-123-jp2-jre8-win32.whl'
         assert wf.filename == str(Path('./') / expected_name)
     os.chdir(old_path)
コード例 #25
0
 def test_passes_allowZip64_arg_to_zipfile(self, buf):
     wf = WheelFile(buf,
                    mode='w',
                    distname='_',
                    version='0',
                    allowZip64=False)
     # ZipFile.open trips when allowZip64 is forced in a zipfile that does
     # not allow it.
     #
     # Exception message:
     # "force_zip64 is True, but allowZip64 was False when opening the ZIP
     # file."
     with pytest.raises(ValueError, match="allowZip64 was False"):
         assert wf.zipfile.open('file', mode='w', force_zip64=True)
コード例 #26
0
ファイル: __build__.py プロジェクト: e2thenegpii/wheelfile
from wheelfile import WheelFile, __version__
from pathlib import Path
from typing import Dict, Any

# For WheelFile.__init__
# Platform, abi, and language tags stay as defaults: "py3-none-any"
spec: Dict[str, Any] = {'distname': 'wheelfile', 'version': __version__}

# Fetch requirements into a list of strings
requirements = Path('./requirements.txt').read_text().splitlines()

# Open a new wheel file
with WheelFile(mode='w', **spec) as wf:
    # Add requirements to the metadata
    wf.metadata.requires_dists = requirements
    # We target Python 3.6+ only
    wf.metadata.requires_python = '>=3.6'

    # Make sure PyPI page renders nicely
    wf.metadata.summary = "API for inspecting and creating .whl files"
    wf.metadata.description = Path('./README.md').read_text()
    wf.metadata.description_content_type = 'text/markdown'

    # Keywords and trove classifiers, for better searchability
    wf.metadata.keywords = ['wheel', 'packaging', 'pip', 'build', 'distutils']
    wf.metadata.classifiers = [
        'Development Status :: 2 - Pre-Alpha',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Topic :: Software Development :: Build Tools',
        'Topic :: Software Development :: Libraries',
コード例 #27
0
def test_lazy_mode_is_available(buf):
    WheelFile(buf, mode='wl', distname="dist", version='0')
コード例 #28
0
def test_build_reproducibility(tmp_path):
    """Two wheels made from the same set of files should be the same"""
    (tmp_path / "package").mkdir()
    (tmp_path / "package" / "file").touch()

    wf1 = WheelFile(tmp_path / "1.whl", 'w', distname="mywheel", version='1')
    wf1.write(tmp_path / "package")
    wf1.close()

    wf2 = WheelFile(tmp_path / "2.whl", 'w', distname='mywheel', version='1')
    wf2.write(tmp_path / "package")
    wf2.close()

    with open(tmp_path / "1.whl", 'rb') as f:
        contents_wf1 = f.read()

    with open(tmp_path / "2.whl", 'rb') as f:
        contents_wf2 = f.read()

    assert contents_wf1 == contents_wf2
コード例 #29
0
 def wheelfile(self, buf):
     wf = WheelFile(buf, 'w', distname=self.distname, version=self.version)
     wf.metadata.requires_dists = [self.long_requirement]
     wf.close()
     return wf
コード例 #30
0
 def wheelfile(self, buf):
     wf = WheelFile(buf, 'w', distname=self.distname, version=self.version)
     wf.close()
     return wf