MCPcopy
hub / github.com/pypa/twine / build_archive

Function build_archive

tests/helpers.py:31–53  ·  view source on GitHub ↗
(path, name, archive_format, files)

Source from the content-addressed store, hash-verified

29
30
31def build_archive(path, name, archive_format, files):
32 filepath = path / f"{name}.{archive_format}"
33
34 if archive_format == "tar.gz":
35 with tarfile.open(filepath, "x:gz") as archive:
36 for mname, content in files.items():
37 if isinstance(content, tarfile.TarInfo):
38 content.name = mname
39 archive.addfile(content)
40 else:
41 data = textwrap.dedent(content).encode("utf8")
42 member = tarfile.TarInfo(mname)
43 member.size = len(data)
44 archive.addfile(member, io.BytesIO(data))
45 return filepath
46
47 if archive_format == "zip":
48 with zipfile.ZipFile(filepath, mode="w") as archive:
49 for mname, content in files.items():
50 archive.writestr(mname, textwrap.dedent(content))
51 return filepath
52
53 raise ValueError(format)

Callers 6

test_readFunction · 0.85
test_missing_pkg_infoFunction · 0.85
test_invalid_pkg_infoFunction · 0.85
test_pkg_info_directoryFunction · 0.85
test_multiple_top_levelFunction · 0.85

Calls

no outgoing calls

Tested by 6

test_readFunction · 0.68
test_missing_pkg_infoFunction · 0.68
test_invalid_pkg_infoFunction · 0.68
test_pkg_info_directoryFunction · 0.68
test_multiple_top_levelFunction · 0.68