Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,31 @@ Environment ``FLOW360_APIKEY`` variable takes precedence before Flow360 configur
- You can also run examples without activating shell:
``poetry run python examples/case_results.py``

## check in
1. ``black .`` - performs auto-formatting
2. ``isort .`` - sorts imports
3. ``poetry run pylint $(git ls-files "flow360/*.py") --rcfile .pylintrc`` - checks code style
4. ``poetry run pytest -rA tests/simulation`` - run V2 related tests
5. ``poetry run pytest -rA --ignore tests/simulation`` - run V1 related tests (cannot be run altogether)
6. ``pytest -rA tests/simulation --cov-report=html --cov=flow360/component/simulation`` - see test coverage report for V2 client
7. ``pytest -rA --ignore tests/simulation --cov-report=html --cov=flow360 && open htmlcov/index.html`` - see test coverage report for V1+V2 client
## pre-commit hooks

This project uses [autohooks](https://github.com/greenbone/autohooks) to run formatting and linting checks automatically before each commit. To activate:

```bash
poetry run autohooks activate
```

This installs a git pre-commit hook that runs:
- **black** — auto-formatting
- **isort** — import sorting
- **pylint** — code style checking
- **sort_json** — sorts keys in `tests/**/*.json` reference files for clean diffs

The hooks only process staged files, so they are fast. If you skip activation, CI will still catch issues.

## check in (manual)
1. ``black .`` — auto-formatting
2. ``isort .`` — sorts imports
3. ``python tools/sort_ref_json.py`` — sorts keys in test reference JSON files
4. ``poetry run pylint $(git ls-files "flow360/*.py") --rcfile .pylintrc`` — checks code style
5. ``poetry run pytest -rA tests/simulation`` — run V2 related tests
6. ``poetry run pytest -rA --ignore tests/simulation`` — run V1 related tests (cannot be run altogether)
7. ``pytest -rA tests/simulation --cov-report=html --cov=flow360/component/simulation`` — see test coverage report for V2 client
8. ``pytest -rA --ignore tests/simulation --cov-report=html --cov=flow360 && open htmlcov/index.html`` — see test coverage report for V1+V2 client

## Documentation Requirements

Expand Down
Empty file added flow360/_autohooks/__init__.py
Empty file.
52 changes: 52 additions & 0 deletions flow360/_autohooks/sort_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Autohooks plugin: sort keys in staged JSON files under tests/."""

import importlib.util
from pathlib import Path

from autohooks.api import ok
from autohooks.api.git import (
get_staged_status,
stage_files_from_status_list,
stash_unstaged_changes,
)
from autohooks.api.path import match

_TOOLS_DIR = Path(__file__).resolve().parent.parent.parent / "tools"
_spec = importlib.util.spec_from_file_location("sort_ref_json", _TOOLS_DIR / "sort_ref_json.py")
_module = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_module)
process_file = _module.process_file

DEFAULT_INCLUDE = ("*.json",)
TESTS_DIR = Path(__file__).resolve().parent.parent.parent / "tests"


def precommit(config=None, report_progress=None, **kwargs): # pylint: disable=unused-argument
"""Sort JSON keys in staged test reference files."""
files = [
f
for f in get_staged_status()
if match(f.path, DEFAULT_INCLUDE) and TESTS_DIR in f.absolute_path().parents
Comment thread
benflexcompute marked this conversation as resolved.
]
Comment thread
benflexcompute marked this conversation as resolved.

if not files:
ok("No staged JSON files under tests/.")
return 0

if report_progress:
report_progress.init(len(files))

with stash_unstaged_changes(files):
for f in files:
already_sorted = process_file(f.absolute_path(), check=False)
Comment thread
benflexcompute marked this conversation as resolved.
if already_sorted:
ok(f"Already sorted: {f.path}")
else:
ok(f"Sorted keys in: {f.path}")

if report_progress:
report_progress.update()

stage_files_from_status_list(files)

return 0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ exclude = '''

[tool.autohooks]
mode = "poetry"
pre-commit = ["autohooks.plugins.black", "autohooks.plugins.isort", "autohooks.plugins.pylint"]
pre-commit = ["autohooks.plugins.black", "autohooks.plugins.isort", "autohooks.plugins.pylint", "flow360._autohooks.sort_json"]

[tool.autohooks.plugins.pylint]
arguments = ["--rcfile=.pylintrc"]
Expand Down
Loading