A custom builder to build zipped directories
Project description
hatch-zipped-directory
This is a Hatch plugin that provides a custom builder to support building zip archives for quasi-manual installation into various foreign package installation systems. (Specifically, I use this for packaging Inkscape extensions and symbols libraries, but it may be useful in other contexts, such as deploying to cloud compute platforms.)
The builder creates a zip archive. All the contents of the zip
archive will be included under a single specific top-level directory.
The default name of the top-level directory is a file-name-safe
version of the project name, however the name of the directory may be
configured by setting the install-name key in the target-specific
configuration section.
This behavior may be disabled by setting install-name = ''.
In addition to whatever files are selected for inclusion in the archive via Hatch’s regular build configuration settings, any configured project README and license files will be included in the top level of the install directory within the zip archive.
As well, a METADATA.json file containing the project metadata in
JSON format (as described in
PEP 566)
will be included in the top level of the install directory within the
zip archive.
Example
Assume a project source directory looking something like:
.
├── pyproject.toml
├── LICENSE.txt
├── README.md
├── src
│ ├── subdir
│ │ ├── data.txt
│ │ └── more-code.py
│ └── my-code.py
└── tests
└── test_foo.py
Where pyproject.toml looks like:
[build-system]
requires = [
"hatchling",
"hatch-zipped-directory",
]
build-backend = "hatchling.build"
[project]
name = "test-project"
version = "0.42"
[tool.hatch.build.targets.zipped-directory]
install-name = "org.example.test"
sources = [
"/src",
]
Then, running
hatch build --target zipped-directory
will build a zip archive named dist/test_project-0.42.zip with the following
structure:
.
└── org.example.test
├── LICENSE.txt
├── METADATA.json
├── README.md
├── my-code.py
└── subdir
├── data.txt
└── more-code.py
Reproducible Builds
By default, this plugin attempts to build reproducible archives by setting the timestamps of the zip entries to a fixed value. When building in reproducible mode, the UNIX file modes of the archive entries is also normalized (to either 0644 or 0755 depending on whether the file is executable.)
The timestamp used for reproducible builds may be configured by
setting the SOURCE_DATE_EPOCH environment variable.
Reproducible builds may be disabled by setting reproducible = false
in an appropriate section of pyproject.toml or hatch.toml. See
Hatch’s documentation on Build Configuration for details.
Author
Jeff Dairiki dairiki@dairiki.org
License
hatch-zipped-directory is distributed under the terms of the
MIT license.
Changes
0.2.1 (2025-06-06)
Bugs Fixed
- Timestamps of parent directory entries are now set to the correct magic value with reproducible builds are enabled. (#5, #6)
Tests Fixed
-
The functional test (
test_functional.py) was testing the latest version of our plugin from PyPI rather than from local source. -
The CI tests appear to have been running whatever version of python was compiled into the installed
hatchbinary, rather than the system default python.
0.2.0 (2025-03-11)
Features
- Write parent directory entries to zip archive. Python requires this when importing modules directly from a zip archive. (#4 — thank you @PolyPik)
Breaking Changes
- Drop support for Python 3.7 & 3.8.
Bugs Fixed
- (typing)
atomic_openreturnsio.BufferedRandom(notio.BufferedWriter).
Tests
- Test under python 3.14.
- Test under windows.
0.1.0 (2023-12-12)
Bitrot
- Fix for hatchling 1.19 (hatch 1.8).
BuilderInterface.buildarguments are now all kw-only. ([hatch/6c252f8])
[hatch/6c252f8]: https://github.com/pypa/hatch/commit/6c252f8b8a65711846a6060c3d54f02936da2aa0)
0.1.0b4 (2023-09-10)
Features
- Add support for reproducible builds which are now enabled by
default. When enabled, timestamps in the zip archive are set to a
fixed value (configurable via the
SOURCE_DATE_EPOCHenvironment variable) and the UNIX access modes of archive members are normalized to either 0644 or 0755 depending on whether the file is executable or not.
0.1.0b3 (2023-05-10)
Features
- Refactor JSON metadata code. Now we use
hatchlingto generate conventionall RFC 822-formatted distribution metadata, then convert that to JSON, explicitly following the steps outline in PEP 566. Among other things, this allows configuration of the Metadata-Version by settingtool.hatch.build.targets.zipped-directory.core-metadata-version.
Tests
- We now have 100% test coverage.
0.1.0b2 (2023-01-10)
Features
- The prefixing of file names under a top-level directory in the zip
archive can now be disabled by setting
install-name = "". Thank you @gwerbin(#1)
Bugs
- Use explicit encoding in hatch metadata hook (for Windows).
0.1.0b1 (2022-10-07)
Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hatch_zipped_directory-0.2.1.tar.gz.
File metadata
- Download URL: hatch_zipped_directory-0.2.1.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72e8dbac48027adeb2f566f15e8a426d8802a225bdde2a740a7fb7df0130e57b
|
|
| MD5 |
862a403f16097de63024c8b1bf76210b
|
|
| BLAKE2b-256 |
dc1b154ce5390aa71b137a02b63d1546d76671f69f351b9b2b6283ecf56af137
|
Provenance
The following attestation bundles were made for hatch_zipped_directory-0.2.1.tar.gz:
Publisher:
ci.yml on dairiki/hatch-zipped-directory
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hatch_zipped_directory-0.2.1.tar.gz -
Subject digest:
72e8dbac48027adeb2f566f15e8a426d8802a225bdde2a740a7fb7df0130e57b - Sigstore transparency entry: 231950959
- Sigstore integration time:
-
Permalink:
dairiki/hatch-zipped-directory@9159e1a824ec04b008b50aece806c1dc2da1c16e -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/dairiki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@9159e1a824ec04b008b50aece806c1dc2da1c16e -
Trigger Event:
push
-
Statement type:
File details
Details for the file hatch_zipped_directory-0.2.1-py3-none-any.whl.
File metadata
- Download URL: hatch_zipped_directory-0.2.1-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e7a32c2cb1a284d44262dd72d629c94e9c674296c4ba65348cab4da4b368771
|
|
| MD5 |
136c4359a1395372663083112c9c1b50
|
|
| BLAKE2b-256 |
81ccaca01538a2653b6e6ebb5c329995ce1b14012a804a80de970908463ee1a9
|
Provenance
The following attestation bundles were made for hatch_zipped_directory-0.2.1-py3-none-any.whl:
Publisher:
ci.yml on dairiki/hatch-zipped-directory
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hatch_zipped_directory-0.2.1-py3-none-any.whl -
Subject digest:
4e7a32c2cb1a284d44262dd72d629c94e9c674296c4ba65348cab4da4b368771 - Sigstore transparency entry: 231950962
- Sigstore integration time:
-
Permalink:
dairiki/hatch-zipped-directory@9159e1a824ec04b008b50aece806c1dc2da1c16e -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/dairiki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@9159e1a824ec04b008b50aece806c1dc2da1c16e -
Trigger Event:
push
-
Statement type: