Skip to content

Commit 00b7aa7

Browse files
glatterf42meksor
andauthored
Update CI tools and dependencies (#24)
* Adapt to pydantic v2.4, fastapi 0.103 * Let pydantic return a SchemaError instead of InconsistentIamcType * Use pandera.DataFrameModel instead of pandera.SchemaModel * Clean up changes in API layer * Make creation information optional in iamc/variable * Make id and name required for unit * Revert bulk_* changes to use json_encoder of api.DataFrame again * NOTE: this option will be deprecated in the future, * pydantic serialization decorators should be used instead * Clean up changes in data/db to enable tests again * Revert use of Annotated in iamc/datapoint/filter * Make sqla_model a proper ClassVar (rather than private attr) * Set field.alias only when it does not equal field.name * Update version of ruff * Set field alias in Field directly * Use httpx-preferred content to send bytes/raw content/json st * Use alias for model_ fields that conflict with pydantic protected namespace * Use variable rather than unmapped class reference to resolve SAwarning * Delete unused import * Bump mypy and poetry versions * Use pre-commit over lint-GHA * Runs mypy, black, ruff * NOTE: needs to be run in the repo s.t. poetry detects the correct venv * Remove separate lint.yaml action * Bump sphinx version * Update docstrings according to new sphinx version * Delete duplicate docs files * TEMPORARY Use own fork for sphinxcontrib-openapi workaround * Bump dask,sqlalchemy,pre-commit versions * restore filter framework api * fix union types with filter subojects * fix code style * fix formatting error * Remove outdated comments * Update various things: * Bump fastapi,black,ruff,mypy versions * Update pre-commit-config accordingly * Update doc/source/openapi-v1.json * Include pre-commit, ruff, etc in DEVELOPING.md --------- Co-authored-by: Max Wolschlager <[email protected]>
1 parent 1fa7efb commit 00b7aa7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1760
-1701
lines changed

.github/workflows/lint.yaml

-68
This file was deleted.

.github/workflows/pytest.yaml

+43-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ jobs:
4646
virtualenvs-create: true
4747
virtualenvs-in-project: true
4848
installer-parallel: true
49-
5049
#----------------------------------------------
5150
# load cached venv if cache exists
5251
#----------------------------------------------
@@ -74,3 +73,46 @@ jobs:
7473
run: |
7574
source .venv/bin/activate
7675
pytest --cov-report xml:.coverage.xml --cov-report term --cov=ixmp4 -rsx --benchmark-skip
76+
77+
pre-commit:
78+
name: Code quality
79+
runs-on: ubuntu-latest
80+
steps:
81+
#----------------------------------------------
82+
# check-out repo and set-up python
83+
#----------------------------------------------
84+
- uses: actions/checkout@v3
85+
- uses: actions/setup-python@v4
86+
#----------------------------------------------
87+
# ----- install & configure poetry -----
88+
#----------------------------------------------
89+
- name: Install Poetry
90+
uses: snok/install-poetry@v1
91+
with:
92+
virtualenvs-create: true
93+
virtualenvs-in-project: true
94+
installer-parallel: true
95+
#----------------------------------------------
96+
# load cached venv if cache exists
97+
#----------------------------------------------
98+
- name: Load cached venv
99+
id: cached-poetry-dependencies
100+
uses: actions/cache@v2
101+
with:
102+
path: .venv
103+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
104+
#----------------------------------------------
105+
# install dependencies if cache does not exist
106+
#----------------------------------------------
107+
- name: Install dependencies
108+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
109+
run: poetry install --no-interaction --no-root --with dev,server
110+
#----------------------------------------------
111+
# install your root project, if required
112+
#----------------------------------------------
113+
- name: Install library
114+
run: poetry install --no-interaction
115+
#----------------------------------------------
116+
# run pre-commit/(mypy, black, ruff)
117+
#----------------------------------------------
118+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-mypy
3+
rev: v1.6.1
4+
hooks:
5+
- id: mypy
6+
entry: bash -c "poetry run mypy ."
7+
language: system
8+
- repo: https://github.com/psf/black
9+
rev: 23.10.0
10+
hooks:
11+
- id: black
12+
- repo: https://github.com/astral-sh/ruff-pre-commit
13+
rev: v0.1.0
14+
hooks:
15+
- id: ruff

DEVELOPING.md

+50
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,53 @@ It is overwritten on the fly by the poetry-dynamic-versioning plugin.
317317
(without the rc<N>).
318318
1. Check that the "Publish to PyPI and TestPyPI" GitHub action passed and that the
319319
distributions are published on https://pypi.org/project/ixmp4/ .
320+
321+
## Contributing
322+
323+
Contributions to the code are always welcome! Please make sure your code follows our
324+
code style so that the style is consistent. Each PR will be checked by a Code Quality
325+
test that examines compliance with black, ruff, and mypy.
326+
327+
### Running pre-commit locally
328+
329+
We use [pre-commit](https://pre-commit.com/) to check the code style. You can install
330+
pre-commit locally by installing ixmp4 with the optional `dev` group. Running
331+
332+
```bash
333+
pre-commit install
334+
```
335+
336+
will set pre-commit up to run on every `git commit`. Per default, pre-commit will run
337+
on changed files, but if you want to run it on all files, you can run
338+
339+
```bash
340+
pre-commit run --all-files
341+
```
342+
343+
If you only want certain hooks to run, choose from `ruff`, `black`, and `mypy` as
344+
`hook-ids` and run
345+
346+
```bash
347+
pre-commit run <hook-ids> --all-files
348+
```
349+
350+
### Ensuring compliance
351+
352+
Whether you run pre-commit locally or see it on your PR for the first time, the checks
353+
are the same. You can, of course, run the code style tools manually. From within the
354+
ixmp4 directory, this would look similar to this:
355+
356+
```bash
357+
black .
358+
mypy .
359+
ruff check .
360+
361+
# Or to enable ruff's automic fixes
362+
ruff check --fix .
363+
```
364+
365+
However, it is easy to forget running these commands manually. Therefore, we recommend
366+
setting your editor up to run at least
367+
[black](https://black.readthedocs.io/en/stable/integrations/editors.html) and
368+
[ruff](https://docs.astral.sh/ruff/usage/#vs-code) automatically whenever you hit
369+
`save`. A few minutes of configuration will save you time and nerves later on.

doc/source/devs/ixmp4.core/iamc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ IAMC Data
1010
:members:
1111
:undoc-members:
1212
:show-inheritance:
13+
:noindex:
1314

1415

1516
.. automodule:: ixmp4.core.iamc.repository

doc/source/devs/ixmp4.core/modules.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ Core API (ixmp4.core)
66

77
platform
88
run
9+
model
10+
scenario
911
iamc
1012
meta
1113
region
1214
unit
1315
exceptions
14-

doc/source/devs/ixmp4.core/scenario.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
Scenarios
3-
=======
3+
=========
44

55
.. toctree::
66
:maxdepth: 1

doc/source/modules.rst

-70
This file was deleted.

doc/source/openapi-v1.json

+1-1
Large diffs are not rendered by default.

doc/source/tests.rst

-82
This file was deleted.

ixmp4/cli/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def login(
4444
),
4545
):
4646
try:
47-
auth = ManagerAuth(username, password, settings.manager_url)
47+
auth = ManagerAuth(username, password, str(settings.manager_url))
4848
user = auth.get_user()
4949
utils.good(f"Successfully authenticated as user '{user.username}'.")
5050
if typer.confirm(

0 commit comments

Comments
 (0)