Assert Contains Regex is a tool that checks to see if files contain specific regular expressions. If a file doesn’t, then the tool can optionally look for the regular expressions in a file with a similar name. I use it to make sure that files contain copying information.
I mainly use Assert Contains Regex as a pre-commit hook. For an example of what to add to your pre-commit configuration, take a look at .pre-commit-config.yaml.
For more detailed usage information, install Assert Contains Regex and run
assert_contains_regex --help
The Markdown files in this repo may not appear correctly in Pagure due to this bug.
I would like for Assert Contains Regex to work anywhere that Python does. I developed it on Linux exclusively and am unfortunately finding out that I made some poor assumptions that cause problems on Windows. Assert Contains Regex does work on Windows, but it’s a little bit rough around the edges.
Other versions and alternatives (like PyPy) probably work, but they haven’t been tested. Additionally, you’ll have to make sure that your system is using a UTF-8 locale. Run:
python -c "import codecs, locale; print(codecs.lookup(locale.getpreferredencoding(False)).name)"
If it says utf-8, then you’re good to go. If not, then you’ll have to change
your system’s locale. Configuring locales is very OS specific, so start looking
for documentation. If you can’t figure out how to switch to a Unicode locale or
if one isn’t available, then you can try setting the
PYTHONUTF8
environment variable to 1. Using PYTHONUTF8 might increase your chances of
seeing garbled text, so it’s not recommended. (Source for that locale encoding
command: https://docs.python.org/3/glossary.html#term-locale-encoding)
Using a virtual environment is optional and recommended. Doing so prevents unnecessary changes to the system and makes it easier to restart if something goes wrong.
Create a virtual environment. In this example, I named the virtual environment “env”. You can name it anything. I would recommend calling it “env” or “venv”.
python -m venv env
Activate the environment:
source env/bin/activateenv\Scripts\activate.bat(Optional) Install wheel. I think that this will speed things up later, but
I haven’t verified it.
pip install wheel
(Optional) Update pre-installed packages:
Update pip:
python -m pip install --upgrade pip
Update Setuptools:
pip install --upgrade setuptools
The virtual environment will only be active in your current terminal. If you switch to a different one, then you’ll need to activate the virtual environment again.
If you haven’t already, install the build package:
pip install build
Build Assert Contains Regex:
python -m build
Install Assert Contains Regex:
pip install --force-reinstall dist/assert_contains_regex-[…].whl
Run assert_contains_regex
.pre-commit-config.yaml file).COPYING.md for an example.packages directory should only contain plain-ASCII
characters. This is done to help support systems that aren’t using a Unicode
locale.As an experiment, this repo uses git-bug for tracking issues.
See COPYING.md.