Skip to main content

Command-line utility, as well as a hook usable by the Python pre-commit framework and a GitHub Action, to ensure that selected files are empty.

Project description

check-empty

A simple, dependency-free and intuitive pre-commit / prek hook, CLI, library, uv tool and GitHub Action conglomerate written in Python that 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. Supports CPython 3.6+, PyPy 7.0+, GraalPy 19.0+ out-of-the-box, and most likely every Python 3.6 runtime you can think of.

Quickstart

Without installation (just trying out the capabilities):

uvx check-empty -Q src/mylib/py.typed docs/.nojekyll static/.gitkeep some_directory
# 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 version with:

check-empty --version # or check-empty -v

Run the CLI:

check-empty -Q src/mylib/py.typed docs/.nojekyll static/.gitkeep some_directory

As a pre-commit hook:

# .pre-commit-config.yaml
repos:
- repo: https://github.com/jonathandung/check-empty
  rev: v0.7.0 # repository version
  hooks:
    - id: check-empty # the hook
      args: # example list of arguments
        - -Q # flag to decrease output, applicable twice (shorthand for --quiet)
        # below: paths to files/directories to clear or keep empty, relative to project
        # root (absolute paths are possible but not recommended)
        - src/mylib/py.typed
        - docs/.nojekyll
        - static/.gitkeep
        - some_directory

equivalent in prek.toml format:

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

[[repos.hooks]]
id = "check-empty"
args = [
  "-Q",
  "src/mylib/py.typed",
  "docs/.nojekyll",
  "static/.gitkeep",
  "some_directory"
]

or a more terse format (TOML 1.1+):

[[repos]]
repo = "https://github.com/jonathandung/check-empty"
rev = "v0.7.0"
hooks = [{
  id = "check-empty",
  args = [
    "-Q", "src/mylib/py.typed", "docs/.nojekyll", "static/.gitkeep", "some_directory"
  ]
}]

As a GitHub action step:

steps:
- uses: jonathandung/check-empty@v0.7.0 # 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.14' # run the script on the latest stable Python version
    # Python down to 3.6 is supported but not recommended due to end-of-life
    quiet: true
    filenames: |
      src/mylib/py.typed
      docs/.nojekyll
      static/.gitkeep
      some_directory

Notes

  1. If your file name starts with a hyphen, to avoid having it misinterpreted as a flag, use a command of the form check-empty -- -this_is_actually_a_file.txt. Thus, for a file literally named "--", you have little choice but to call the underlying library function (check) directly.
  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. The program does not recurse into archives, since identification of compressed archives would require reading the first few bytes of each file seen, which is error-prone and inefficient.

Development

If you wish to contribute to this project, you are more than welcome, but please remember to read the contributing guide. Tests are run with:

python -m test_check_empty # explicit
python -m unittest discover # alternative

at the project root.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

check_empty-0.7.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

check_empty-0.7.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file check_empty-0.7.0.tar.gz.

File metadata

  • Download URL: check_empty-0.7.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for check_empty-0.7.0.tar.gz
Algorithm Hash digest
SHA256 8c4743aa56c3b2a4b1cb98cdea6531542e64a94a770373b88799fc7842c5d407
MD5 2220517ecff863a5ae5761adca0ca8b6
BLAKE2b-256 4501488fafe190db04972f8061f61e1dc5914015f671b232e653ff9f00de3410

See more details on using hashes here.

File details

Details for the file check_empty-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: check_empty-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for check_empty-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5503aad5df7ce93023d1fafc1e69659ff90cbc3d58f19cb0c01895b2e7593ecf
MD5 7cc05df0268c122f1f420d429d7ac9a7
BLAKE2b-256 1a7c5ab4385ad86589cd8808f643c97fb5053bf488c968d6cf9fdcb749ea7505

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page