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
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
def wf(self, buf): wf = WheelFile(buf, 'w', distname='_', version='0', compression=ZIP_STORED, compresslevel=1) yield wf wf.close()
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)
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()
def empty_wheel(tmp_path) -> Path: with WheelFile(tmp_path, 'w', distname='wheelfile_test_wheel', version='0.0.0') as wf: pass return wf
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
def test_passes_compresslevel_arg_to_zipfile(self, buf): wf = WheelFile(buf, mode='w', distname='_', version='0', compresslevel=7) assert wf.zipfile.compresslevel == 7
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 # 🧀
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)
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)
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
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
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)
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']
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')
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
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)
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
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']
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')
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)
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)
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)
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)
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',
def test_lazy_mode_is_available(buf): WheelFile(buf, mode='wl', distname="dist", version='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
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
def wheelfile(self, buf): wf = WheelFile(buf, 'w', distname=self.distname, version=self.version) wf.close() return wf