Fix pytest call from pre-commit hook
This commit is contained in:
parent
b9f720d785
commit
28b0583919
|
@ -19,7 +19,7 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: pytest
|
- id: pytest
|
||||||
name: pytest
|
name: pytest
|
||||||
entry: pytest software/tests
|
entry: python run_pytest.py
|
||||||
language: system
|
language: system
|
||||||
types: [python]
|
types: [python]
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
|
|
|
@ -55,14 +55,16 @@ Then run `poetry install` again. If this doesn't work, please join our [Discord
|
||||||
|
|
||||||
## Code Formatting and Linting
|
## Code Formatting and Linting
|
||||||
|
|
||||||
Our project uses `black` for code formatting and `isort` for import sorting. To ensure consistency across contributions, please adhere to the following guidelines:
|
Our project uses `ruff` for code formatting and `isort` for import sorting. To ensure consistency across contributions, please adhere to the following guidelines:
|
||||||
|
|
||||||
1. **Install Pre-commit Hooks**:
|
1. **Install Pre-commit Hooks**:
|
||||||
|
|
||||||
If you want to automatically format your code every time you make a commit, install the pre-commit hooks.
|
To automatically format your code every time you make a commit, install the pre-commit hooks.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install pre-commit
|
cd software # Change into `software` directory if not there already.
|
||||||
|
poetry shell # /!\ You MUST do it the virtual environment of your project
|
||||||
|
poetry add --dev pre-commit # Install pre-commit as a dev dependency
|
||||||
pre-commit install
|
pre-commit install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -73,7 +75,7 @@ Our project uses `black` for code formatting and `isort` for import sorting. To
|
||||||
If you choose not to use the pre-commit hooks, you can manually format your code using:
|
If you choose not to use the pre-commit hooks, you can manually format your code using:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
black .
|
ruff .
|
||||||
isort .
|
isort .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import ctypes
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Run pytest in the software directory.
|
||||||
|
|
||||||
|
This script is intended to be used as a pre-commit hook to run the tests from the root of the repository.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Additional setup for Windows (10 at least) to prevent issues with Unicode characters in the console.
|
||||||
|
# see https://www.reddit.com/r/learnpython/comments/350c8c/unicode_python_3_and_the_windows_console/
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
# Force UTF-8 encoding in Python
|
||||||
|
os.environ["PYTHONUTF8"] = "1"
|
||||||
|
|
||||||
|
# Change Windows console code page to UTF-8
|
||||||
|
ctypes.windll.kernel32.SetConsoleCP(65001)
|
||||||
|
ctypes.windll.kernel32.SetConsoleOutputCP(65001)
|
||||||
|
|
||||||
|
# Define the target directory relative to this script location.
|
||||||
|
target_directory = os.path.join(os.path.dirname(__file__), "software")
|
||||||
|
|
||||||
|
os.chdir(target_directory)
|
||||||
|
|
||||||
|
# Run pytest with any additional arguments passed to this script.
|
||||||
|
result = subprocess.run(["pytest"] + sys.argv[1:])
|
||||||
|
|
||||||
|
# Exit with pytest's exit code to reflect the test outcome in the pre-commit hook.
|
||||||
|
sys.exit(result.returncode)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue