A Python wrapper to create Ansys-tailored pre-commit hooks
Project description
This Ansys repository contains pre-commit hooks for different purposes. Currently, these hooks are available:
add-license-headers: Add missing license headers to files by using REUSE . To use this hook, you must have REUSE implemented in your repository.
If you are using any custom templates or licenses, copy the .reuse and LICENSES directories from this repository into the target repository. If you are using the default Ansys template and MIT.txt license, skip this step. By default, the hook will copy the LICENSES/MIT.txt, .reuse/templates/ansys.jinja2, and .reuse/dep5 into the target repository when the hook runs.
Configure the .reuse/dep5 file.
Set custom arguments for the pre-commit hook if necessary.
- repo: https://github.com/ansys/pre-commit-hooks rev: v0.2.0 hooks: - id: add-license-headers args: ["--custom_copyright", "custom copyright phrase", "--custom_template", "template_name", "--custom_license", "license_name", "--ignore_license_check"]
args can also be formatted as follows:
args: - --custom_copyright=custom copyright phrase - --custom_template=template_name - --custom_license=license_name - --ignore_license_check
Specify directories to run the hook on
- repo: https://github.com/ansys/pre-commit-hooks rev: v0.2.0 hooks: - id: add-license-headers files: '(src|examples|tests|newFolder)/.*\.(py|newExtension)|\.(proto|newExtension)'
Ignore specific files or file types
In .pre-commit-config.yaml
- repo: https://github.com/ansys/pre-commit-hooks rev: v0.2.0 hooks: - id: add-license-headers exclude: | (?x)^( path/to/file1.py | path/to/.*\.(ts|cpp) | (.folder1|folder2)/.* | .*\.js | \..* | )$
In .reuse/dep5
Files: path/to/file1.py Copyright: 2023 ANSYS, Inc. and/or its affiliates. License: MIT Files: path/to/*.py Copyright: 2023 ANSYS, Inc. and/or its affiliates. License: MIT
How to install
The following sections provide instructions for installing the ansys-pre-commit-hooks package in two installation modes: user and developer.
For users
Before installing the package, to ensure that you have the latest version of pip, run this command:
python -m pip install -U pip
Then, to install the package, run this command:
python -m pip install ansys-pre-commit-hooks
For developers
Installing the package in developer mode allows you to modify and enhance the source code.
Before contributing to the project, ensure that you are familiar with the PyAnsys Developer’s Guide.
For a developer installation, you must follow these steps:
Clone the repository with this command:
git clone https://github.com/ansys/pre-commit-hooks
Create a fresh-clean Python environment and activate it with these commands:
# Create a virtual environment python -m venv .venv # Activate it in a POSIX system source .venv/bin/activate # Activate it in Windows CMD environment .venv\Scripts\activate.bat # Activate it in Windows Powershell .venv\Scripts\Activate.ps1
Ensure that you have the latest required build system tools by running this command:
python -m pip install -U pip flit tox twine
Install the project in editable mode by running one of these commands:
# Install the minimum requirements python -m pip install -e . # Install the minimum + tests requirements python -m pip install -e .[tests] # Install the minimum + doc requirements python -m pip install -e .[doc] # Install all requirements python -m pip install -e .[tests,doc]
Verify your development installation by running this command:
tox
How to test it
This project takes advantage of tox. This tool automates common development tasks (similar to Makefile), but it is oriented towards Python development.
Using tox
While Makefile has rules, tox has environments. In fact, tox creates its own virtual environment so that anything being tested is isolated from the project to guarantee the project’s integrity.
These environment commands are provided:
tox -e style: Checks for coding style quality.
tox -e py: Checks for unit tests.
tox -e py-coverage: Checks for unit testing and code coverage.
tox -e doc: Checks for successfully building the documentation.
Raw testing
If required, you can always call style commands, such as black, isort, and flake8, or unit testing commands, such as pytest, from the command line. However, calling these commands does not guarantee that your project is being tested in an isolated environment, which is the reason why tools like tox exist.
A note on pre-commit
The style checks take advantage of pre-commit. Developers are not forced but encouraged to install this tool by running this command:
python -m pip install pre-commit && pre-commit install
Documentation
For building documentation, you can run the usual rules provided in the Sphinx Makefile with a command that is formatted like this:
make -C doc/ html && your_browser_name doc/html/index.html
However, the recommended way of checking documentation integrity is by running tox with a command that is formatted like this:
tox -e doc && your_browser_name .tox/doc_out/index.html
Distributing
If you would like to create either source or wheel files, install the building requirements and then execute the build module with these commands:
python -m pip install .
python -m build
python -m twine check dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ansys_pre_commit_hooks-0.2.0.tar.gz
.
File metadata
- Download URL: ansys_pre_commit_hooks-0.2.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 423a0cb0f20c536f9ef13a3264699888e5cc55a3148974766c41d941e628537f |
|
MD5 | ee9c9feddd41540b7b625f6255a77589 |
|
BLAKE2b-256 | cd2c7fe3064001cfb93daf8f2a82c5d2508720bba64284b1202f0cba57eddaed |
File details
Details for the file ansys_pre_commit_hooks-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: ansys_pre_commit_hooks-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15f382de249d9adf3e23c7a29478735d5a4f8d6a00e59a699dc533fc04a6fc71 |
|
MD5 | 85fa72603a3ac1e49a52f240b883a8c0 |
|
BLAKE2b-256 | d1f1225c215f19f5c64edc688086e466a8d8556d8a06b9e61fe6641bb9191ea0 |