Skip to main content

kinda like grep but not quite

Project description

Latest Version Supported Python Versions Code style: black Documentation Status

not-grep is kind of like grep, but different.

WAT?

If you have ever needed to inspect a file for particular patterns, you probably used grep.

grep FooClassName file.py

If you needed to do that for a lot of files, you might have combined it with find.

find . -type f -name "*.py" -exec grep -n FooClassName {} /dev/null \;

This works great for one-off checks but less great if you need to do those checks repeatedly, if you need to do lots of such checks, if you need to do those checks somewhere that you don’t have access to grep, or if you need to do things that grep cannot do.

Not Grep?

not-grep is designed for static use, not ad-hoc use. For example, as part of a continuous integration test suite. This is why it gets its configuration from a config file, not the CLI. Because of this, the not-grep CLI is very simple: the only things you can specify are the config file and verbosity.

not-grep --config config.toml -vv

Inside the config file, things start to get interesting.

not-grep is built around checker plugins. Each plugin takes a map as input: the file glob pattern for the files you want to check and a value that tells the plugin what to do with that file.

The config file is a collection of TOML tables. The table name identifies the plugin and the table members are the input to that plugin.

# The "include" checker will error unless the specified value is include.
[include]
"src/**/*.py" = "__all__"

# The "exclude" checker will error if the specified value is include.
[exclude]
"src/**/*.py" = "FooClassName"

The output shows you, for each plugin, whether each matched file met or failed the plugin requirements. In lower verbosity levels, not-grep only shows failed checks.

$ not-grep --config config.toml -vv
================Running include checks================
-----------Checking src/**/*.py for pattern-----------
__all__
******************************************************
src/foo/__init__.py.............................. PASS
src/foo/bar.py................................... FAIL

================Running exclude checks================
-----------Checking src/**/*.py for pattern-----------
FooClassName
******************************************************
src/foo/__init__.py.............................. PASS
src/foo/bar.py................................... PASS

Awesome! Can I use it in GitHub Actions?

Yes. Yes you can.

- uses: mattsb42/not-grep@master
  with:
    # If you don't set config-file the action uses ".github/not-grep.toml".
    config-file: ./github/config/check-things.toml
    # If you don't set debug, passing checks will be hidden.
    debug: true

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

not_grep-1.0.1-py2.py3-none-any.whl (17.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file not_grep-1.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: not_grep-1.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for not_grep-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c133aef0011b7a9b7d85f132f0d166541279d2dbcff0f53b93107c1b162dc3e8
MD5 dc8c7db0e6f4c0bb1c2e077022ef0f47
BLAKE2b-256 1f88962d8aa368a8d871f11b0e7a87a664e3361ef6aaa9e5b4d49de296d8d04c

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