Skip to main content

check-empty

#StandWithPalestine

A simple, dependency-free pre-commit / prek hook, CLI, library and GitHub Action conglomerate written in Python.

Makes sure selected files, even within directories, are empty according to as little filesystem stat calls as possible, and clears them effectively with minimal I/O if specified.

Prerequisites

Supports every Python 3.11+ runtime. There are no other requirements unless you want to check if files in certain types of (compressed) archives are empty.

Quickstart

If using double-asterisk globbing in the CLI, make sure it is enabled:

shopt -s globstar

similarly for extglob:

shopt -s extglob

Without installation (just trying out the capabilities):

uvx check-empty -Q src/mylib/py.typed docs/.nojekyll static/.gitkeep some_dir **/*.lock

Installation

# uv
uv tool install check-empty # bare executable on PATH
uv pip install check-empty # if you want to import check_empty for programmatic usage

pip install check-empty # pip

Show the help with:

check-empty --help # or check-empty -?

Usage

All the snippets below are equivalent, assuming globstar is on.

Run the CLI:

check-empty -Q src/mylib/py.typed docs/.nojekyll static/.gitkeep some_dir **/*.lock

In Python:

from check_empty import check
import glob

a = ['src/mylib/py.typed', 'docs/.nojekyll', 'static/.gitkeep', 'some_dir']
a.extend(glob.iglob('**/*.lock', recursive=True))
# build a list of paths to files or directories by manual globbing
check(a, verbosity=1)
# default verbosity is 2; in the command line, each -Q decreases it by 1 and
# each -V increases it by 1

As a pre-commit hook:

# .pre-commit-config.yaml
repos:
- repo: https://github.com/jonathandung/check-empty
  rev: v4.1.2 # repository version
  hooks:
  - id: check-empty # the hook
    args: # example list of arguments
    - -Q # flag to decrease output, applicable twice (shorthand for --quiet)
    files: ^src/mylib/py\.typed|docs/\.nojekyll|static/\.gitkeep|some_dir/.*|.*\.lock$
    # paths to files/directories to clear or keep empty as a single regular
    # expression (as per the somewhat restrictive pre-commit config schema),
    # relative to project root

equivalent in prek.toml format:

[[repos]]
repo = "https://github.com/jonathandung/check-empty"
rev = "v4.1.2"

[[repos.hooks]]
id = "check-empty"
args = ["-Q"]

[[repos.hooks.files]]
glob = [ # globset reference: https://docs.rs/globset/latest/globset/#syntax
  # this form is only supported by prek; see
  # https://prek.j178.dev/reference/configuration/?h=globs#files
  "src/mylib/py.typed",
  "docs/.nojekyll",
  "static/.gitkeep",
  "some_dir/**", # since directories cannot be passed directly, glob the files within
  "**/*.lock"
]

or (TOML 1.1+):

# using multiline inline tables
[[repos]]
repo = "https://github.com/jonathandung/check-empty"
rev = "v4.1.2"
hooks = [{
  id = "check-empty",
  args = ["-Q"],
  files = {
    glob = [
      "src/mylib/py.typed",
      "docs/.nojekyll",
      "static/.gitkeep",
      "some_dir/**",
      "**/*.lock"
    ]
  },
}]

As a GitHub Actions workflow step:

steps:
- uses: jonathandung/check-empty@v4.1.2 # the latest version on the GitHub Actions
  # marketplace; this step will fail and subsequent jobs will not run if any file is
  # not empty
  with:
    python-version: '3.15' # run the script on the latest stable Python version
    filenames: |
      src/mylib/py.typed
      docs/.nojekyll
      static/.gitkeep
      some_dir
    globs: '**/*.lock'
    # must use single quotes to escape asterisks, which refer to YAML aliases
    # can also be an array of globs joined into a newline-delimited multiline string,
    # as in filenames

Also see the GitHub Action manifest, which contains the accepted action inputs, action outputs produced and their respective descriptions.

Notes

  1. If your file name starts with a hyphen, use a command of the form check-empty -- -this_is_actually_a_file.txt to avoid having the filename misinterpreted as a flag.
  2. Forward slashes can be used even on Windows, so there is no need to escape anything.
  3. Glob patterns are supported on *nix only. If on Windows, use a shell like Git Bash.
  4. To pass an argfile, use the @ prefix, and escape files whose names actually start with @ using the double-hyphen syntax.
  5. It may be unintuitive that a directory or archive being "empty" means all its files are empty, but this project explicitly targets files, since version control systems track files rather than directories.
  6. The program can recurse into some archives if specified, but it requires certain libraries to be installed to do so for certain formats. .7z (corresponding to the 7z extra) needs py7zr, .rar (the rar extra) needs rarfile, .lha / .lzh (the lzh extra) needs lhafile, .a / .ar / .lib (the ar extra) needs arpy, .ace (the ace extra) needs acefile. These may also slow down the checking significantly for large directories, since magic numbers must be read for every file and the I/O overhead accumulates. All the above extras are included in the all extra.
  7. Keep weird characters in your filenames to a minimum. They may become a problem in GitHub Actions usage.

Development

If you wish to contribute to this project, you are more than welcome. Please remember to read the AI use policy and the contributing guide.

To build the docs locally (needs Python 3.13+ because of Sphinx), install the package with the docs group using a package manager that supports it (e.g. pip 25.1+ or uv 0.4.27+), preferably into a virtual environment.

Tests are run with:

python -m test_check_empty

at the project root.

Metadata

Release files for check-empty 4.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for check-empty 4.1.2
File Size Uploaded Provenance Actions
check_empty-4.1.2.tar.gz 16.9 kB Without provenance Details for check_empty-4.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for check-empty 4.1.2
File Interpreter ABI Platform Actions
check_empty-4.1.2-py3-none-any.whl Python 3 none any Details for check_empty-4.1.2-py3-none-any.whl

Total release size: 41.0 kB

Release files / check_empty-4.1.2.tar.gz

Download URL check_empty-4.1.2.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
aa73e83f9636315862f837bd2233e232ea1174a3761a47bba311a70ce002cd0f
BLAKE2b-256 checksum
How to use checksums
09e1ac4b78e0d14456d40bc91837aa8bbdc1c9fba533c0df6debd7ff1e523a65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / check_empty-4.1.2-py3-none-any.whl

Download URL check_empty-4.1.2-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccda328420bfd2e4d760d6bb6d21b811af0fcbd0888fdeae8ab8a0be08fcb095
BLAKE2b-256 checksum
How to use checksums
bf620f1b4cfbe52ab203e0386bf9fdeb50763d25a55af5122f15ef7a5eaad78a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for check-empty 4.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page