|
| 1 | +# rero-invenio-base Claude guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +rero-invenio-base is a Python library providing generic backend utilities for RERO Invenio instances. It ships SEARCH CLI management commands, a streaming data export framework, and shared Celery tasks. |
| 6 | + |
| 7 | +**Stack**: Python 3.12–3.14, Flask (Invenio), ElasticSearch 7, Celery |
| 8 | +**Package manager**: `uv` with `poethepoet` for task running |
| 9 | + |
| 10 | +## Commands |
| 11 | + |
| 12 | +All commands are run through uv's virtual env with `uv run`. |
| 13 | + |
| 14 | +### Linting and formatting |
| 15 | + |
| 16 | +**IMPORTANT:** After editing files, make sure that there are no errors in the formatting and linting. |
| 17 | + |
| 18 | +```bash |
| 19 | +uv run poe lint # ruff check |
| 20 | +uv run poe format # ruff format |
| 21 | +``` |
| 22 | + |
| 23 | +### Setup (done by humans) |
| 24 | + |
| 25 | +Human developers will start the required containers and services on their own terms. Tests require SEARCH to be running. |
| 26 | + |
| 27 | +## Architecture |
| 28 | + |
| 29 | +### Package structure |
| 30 | + |
| 31 | +```text |
| 32 | +rero_invenio_base/ |
| 33 | +├── ext.py # Flask extension (REROInvenioBase) |
| 34 | +├── config.py # Default configuration keys |
| 35 | +├── cli/ |
| 36 | +│ ├── shared.py # Shared CLI helpers (abort_if_false) |
| 37 | +│ ├── utils.py # check_license, check_json commands |
| 38 | +│ └── es/ |
| 39 | +│ ├── alias.py # `rero es alias` commands |
| 40 | +│ ├── index.py # `rero es index` commands (reindex, move, update-mapping, …) |
| 41 | +│ ├── task.py # `rero es task` commands |
| 42 | +│ ├── snapshot/ # `rero es snapshot` commands |
| 43 | +│ └── slm/ # `rero es slm` snapshot-management commands |
| 44 | +└── modules/ |
| 45 | + ├── tasks.py # run_on_worker Celery task |
| 46 | + ├── utils.py # chunk() utility |
| 47 | + └── export/ |
| 48 | + ├── ext.py # ReroInvenioBaseExportApp Flask extension |
| 49 | + ├── views.py # ExportResource view + create_blueprint_from_app |
| 50 | + └── config.py # Export REST endpoint configuration |
| 51 | +``` |
| 52 | + |
| 53 | +### Entry points |
| 54 | + |
| 55 | +Registered in `pyproject.toml`: |
| 56 | + |
| 57 | +| Entry point group | Name | Target | |
| 58 | +|---|---|---| |
| 59 | +| `flask.commands` | `rero` | `rero_invenio_base.cli:rero` | |
| 60 | +| `invenio_base.apps` | `rero-invenio-base-export` | `ReroInvenioBaseExportApp` | |
| 61 | +| `invenio_base.api_blueprints` | `rero_ils_exports` | `create_blueprint_from_app` | |
| 62 | +| `invenio_celery.tasks` | `rero` | `rero_invenio_base.modules.tasks` | |
| 63 | + |
| 64 | +### Export module |
| 65 | + |
| 66 | +`ExportResource` is a `ContentNegotiatedMethodView` that streams record search results. Routes are registered dynamically from the `RERO_INVENIO_BASE_EXPORT_REST_ENDPOINTS` config key via `create_blueprint_from_app`. Each endpoint maps MIME types to serializers and prepends `/export` to the list route. |
| 67 | + |
| 68 | +## Code style |
| 69 | + |
| 70 | +- Be clear and concise in docstrings; do not over-comment the code. |
| 71 | +- Do not use Python type annotations (no `-> str`, `: str`, etc. in signatures). |
| 72 | +- Use **Sphinx-style** docstrings (`:param x:`, `:returns:`, `:rtype:`). |
| 73 | +- Commit messages follow [Conventional Commits](https://www.conventionalcommits.org). |
| 74 | + |
| 75 | +## Testing |
| 76 | + |
| 77 | +- Tests use function-based style (no class-based tests). |
| 78 | +- Test fixtures are in `tests/conftest.py`; sample data in `tests/data/`. |
| 79 | +- `--doctest-modules` is active — doctests in module files are run by default. |
| 80 | + |
| 81 | +### Running the tests (done by humans) |
| 82 | + |
| 83 | +Human developers run tests from their consoles after starting the SEARCH container: |
| 84 | + |
| 85 | +```bash |
| 86 | +uv run ./scripts/test # full suite (lint + pip-audit + pytest with SEARCH) |
| 87 | +uv run pytest # pytest only (SEARCH must already be running) |
| 88 | +``` |
0 commit comments