This Ansys repository contains pre-commit hooks for different purposes. The following hooks are currently available:
add-license-headers
: Add missing license headers to files by using REUSE . To use this hook, you must haveREUSE
implemented in your repository.tech-review
: Do a technical review of your repository according to Ansys repository requirements
The following sections provide instructions for installing the ansys-pre-commit-hooks
package in two installation modes: user and developer.
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
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
This project takes advantage of tox. This tool automates common development tasks (similar to Makefile), but it is oriented towards Python development.
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.
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.
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
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
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/*