Skip to content

Commit

Permalink
Refactor tests (#5)
Browse files Browse the repository at this point in the history
* Refactor tests

* Remove old tests file

* Add conda-forge badges

* Add test for mkdir

---------

Co-authored-by: Jay Qi <jayqi@users.noreply.github.com>
  • Loading branch information
jayqi and jayqi authored Jan 6, 2024
1 parent 12e8065 commit 6d04a4e
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 318 deletions.
19 changes: 19 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 1
round: down
range: "70...100"
status:
project: # Coverage of whole project
default:
target: auto # Coverage target to pass; auto is base commit
threshold: 5% # Allow coverage to drop by this much vs. base and still pass
patch: # Coverage of lines in this change
default:
target: 80% # Coverage target to pass
threshold: 20% # Allow coverage to drop by this much vs. base and still pass

comment:
layout: "diff,flags,tree"
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# repro-zipfile

[![PyPI](https://img.shields.io/pypi/v/repro-zipfile.svg)](https://pypi.org/project/repro-zipfile/)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/repro-zipfile.svg)](https://anaconda.org/conda-forge/repro-zipfile)
[![conda-forge feedstock](https://img.shields.io/badge/conda--forge-feedstock-yellowgreen)](https://github.com/conda-forge/repro-zipfile-feedstock)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/repro-zipfile)](https://pypi.org/project/repro-zipfile/)
[![tests](https://github.com/drivendataorg/repro-zipfile/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/drivendataorg/repro-zipfile/actions/workflows/tests.yml?query=branch%3Amain)
[![codecov](https://codecov.io/gh/drivendataorg/repro-zipfile/branch/main/graph/badge.svg)](https://codecov.io/gh/drivendataorg/repro-zipfile)

**A tiny, zero-dependency replacement for Python's `zipfile.ZipFile` for creating reproducible/deterministic ZIP archives.**

"Reproducible" or "deterministic" in this context means that the binary content of the ZIP archive is identical if you add files with identical binary content in the same order. This Python package provides a `ReproducibleZipFile` class that works exactly like [`zipfile.ZipFile`](https://docs.python.org/3/library/zipfile.html#zipfile-objects) from the Python standard library, except that all files written to the archive have their last-modified timestamps set to a fixed value.
"Reproducible" or "deterministic" in this context means that the binary content of the ZIP archive is identical if you add files with identical binary content in the same order. It means you can reliably check equality of the contents of two ZIP archives by simply comparing checksums of the archive using a hash function like MD5 or SHA-256.

This Python package provides a `ReproducibleZipFile` class that works exactly like [`zipfile.ZipFile`](https://docs.python.org/3/library/zipfile.html#zipfile-objects) from the Python standard library, except that all files written to the archive have their last-modified timestamps set to a fixed value.

## Installation

Expand All @@ -17,6 +21,12 @@ repro-zipfile is available from PyPI. To install, run:
pip install repro-zipfile
```

It is also available from conda-forge. To install, run:

```bash
conda install repro-zipfile -c conda-forge
```

## Usage

Simply import `ReproducibleZipFile` and use it in the same way you would use [`zipfile.ZipFile`](https://docs.python.org/3/library/zipfile.html#zipfile-objects) from the Python standard library.
Expand All @@ -37,7 +47,7 @@ See [`examples/usage.py`](./examples/usage.py) for an example script that you ca

### Set timestamp value with SOURCE_DATE_EPOCH

repro_zipfile supports setting the fixed timestamp value using the `SOURCE_DATE_EPOCH` environment variable. This should be an integer corresponding to the [Unix epoch time](https://en.wikipedia.org/wiki/Unix_time) of the timestamp you want to set. `SOURCE_DATE_EPOCH` is a [standard](https://reproducible-builds.org/docs/source-date-epoch/) created by the [Reproducible Builds project](https://reproducible-builds.org/).
repro_zipfile supports the `SOURCE_DATE_EPOCH` environment variable. If set, it will be used as a fixed value for the modified timestamps of files added to an archive. This should be an integer corresponding to the [Unix epoch time](https://en.wikipedia.org/wiki/Unix_time) of the timestamp you want to set. `SOURCE_DATE_EPOCH` is a [standard](https://reproducible-builds.org/docs/source-date-epoch/) created by the [Reproducible Builds project](https://reproducible-builds.org/) for software distributions.

## How does repro-zipfile work?

Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: System :: Archiving",
"Topic :: System :: Archiving :: Compression",
"Topic :: System :: Archiving :: Packaging",
Expand Down Expand Up @@ -57,10 +58,10 @@ dependencies = ["coverage>=6.5", "pytest-cov"]
template = "tests"

[[tool.hatch.envs.tests.matrix]]
python = ["3.8", "3.9", "3.10", "3.11"]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.tests.scripts]
test = "pytest {args:tests.py} -v --cov=repro_zipfile --cov-report=term --cov-report=html --cov-report=xml"
test = "pytest {args:tests} -v --cov=. --cov-report=term --cov-report=html --cov-report=xml"

## TOOLS ##

Expand All @@ -74,12 +75,12 @@ select = [
"F", # Pycodestyle
"I", # isort
]
src = ["repro_zipfile.py", "tests.py"]
src = ["*.py", "tests/*.py"]
unfixable = ["F"]

[tool.ruff.isort]
known-first-party = ["repro_zipfile"]
force-sort-within-sections = true

[tool.coverage.run]
source = ["repro_zipfile.py"]
omit = ["tests/*"]
Loading

0 comments on commit 6d04a4e

Please sign in to comment.