Skip to content

Commit

Permalink
Merge branch 'main' into feature/docker-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
meksor committed Feb 13, 2024
2 parents 908ee0d + bff2c8c commit ea9740f
Show file tree
Hide file tree
Showing 50 changed files with 906 additions and 910 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up python
id: setup-python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
Expand All @@ -35,7 +35,7 @@ jobs:
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up python
id: setup-python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
matrix:
python-version:
- "3.10" # Earliest version supported by ixmp4
- "3.11" # Latest version supported by ixmp4
- "3.11"
- "3.12" # Latest version supported by ixmp4

runs-on: ubuntu-latest
services:
Expand All @@ -34,7 +35,7 @@ jobs:
uses: actions/checkout@v4
- name: Set up python
id: setup-python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
#----------------------------------------------
Expand All @@ -51,7 +52,7 @@ jobs:
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
Expand Down Expand Up @@ -81,8 +82,8 @@ jobs:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
Expand All @@ -97,7 +98,7 @@ jobs:
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
Expand Down
12 changes: 5 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.8.0
hooks:
- id: mypy
entry: bash -c "poetry run mypy ."
language: system
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
rev: v0.2.1
hooks:
- id: ruff
- id: ruff
- id: ruff-format
args: [ --check ]
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.10"
python: "3.12"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
Expand Down
15 changes: 7 additions & 8 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ alembic revision -m "<message>" --autogenerate
```

You will have to run all migrations before being able to create new ones in the development database.
Be sure to run `black` and `isort` on newly created migrations!
Be sure to run `ruff` on newly created migrations!

## Tests

Expand Down Expand Up @@ -322,7 +322,7 @@ It is overwritten on the fly by the poetry-dynamic-versioning plugin.

Contributions to the code are always welcome! Please make sure your code follows our
code style so that the style is consistent. Each PR will be checked by a Code Quality
test that examines compliance with black, ruff, and mypy.
test that examines compliance with ruff and mypy.

### Running pre-commit locally

Expand All @@ -340,7 +340,7 @@ on changed files, but if you want to run it on all files, you can run
pre-commit run --all-files
```

If you only want certain hooks to run, choose from `ruff`, `black`, and `mypy` as
If you only want certain hooks to run, choose from `ruff` and `mypy` as
`hook-ids` and run

```bash
Expand All @@ -354,16 +354,15 @@ are the same. You can, of course, run the code style tools manually. From within
ixmp4 directory, this would look similar to this:

```bash
black .
mypy .
ruff check .
ruff format .

# Or to enable ruff's automic fixes
ruff check --fix .
```

However, it is easy to forget running these commands manually. Therefore, we recommend
setting your editor up to run at least
[black](https://black.readthedocs.io/en/stable/integrations/editors.html) and
[ruff](https://docs.astral.sh/ruff/usage/#vs-code) automatically whenever you hit
`save`. A few minutes of configuration will save you time and nerves later on.
setting your editor up to run at least [ruff](https://docs.astral.sh/ruff/usage/#vs-code)
automatically whenever you hit `save`. A few minutes of configuration will save you time
and nerves later on.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Copyright (c) 2023-2024 IIASA - Energy, Climate, and Environment Program (ECE)

[![license: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/iiasa/ixmp4/blob/main/LICENSE)
[![python](https://img.shields.io/badge/python-3.10_|_3.11-blue?logo=python&logoColor=white)](https://github.com/iiasa/ixmp4)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![python](https://img.shields.io/badge/python-3.10_|_3.11_|_3.12-blue?logo=python&logoColor=white)](https://github.com/iiasa/ixmp4)
[![Code style: ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

## Overview

Expand Down
8 changes: 4 additions & 4 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ The ixmp4 package for scenario data management

Copyright © 2023-2024 IIASA - Energy, Climate, and Environment Program (ECE)

|license| |black| |python|
|license| |ruff| |python|

.. |license| image:: https://img.shields.io/badge/license-MIT-brightgreen
:target: https://github.com/iiasa/ixmp4/blob/main/LICENSE

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
.. |ruff| image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff

.. |python| image:: https://img.shields.io/badge/python-3.10_|_3.11-blue?logo=python&logoColor=white
.. |python| image:: https://img.shields.io/badge/python-3.10_|_3.11_|_3.12-blue?logo=python&logoColor=white
:target: https://github.com/iiasa/ixmp4

Overview
Expand Down
5 changes: 2 additions & 3 deletions ixmp4/cli/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def prompt_sqlite_removal(dsn: str):
path = Path(dsn.replace("sqlite://", ""))
path_str = typer.style(path, fg=typer.colors.CYAN)
if typer.confirm(
"Do you want to remove the associated database file at "
f"{path_str} aswell?" # type: ignore
"Do you want to remove the associated database file at " f"{path_str} as well?" # type: ignore
):
path.unlink()
utils.echo("\nDatabase file deleted.")
Expand All @@ -110,7 +109,7 @@ def prompt_sqlite_removal(dsn: str):
def remove(
name: str = typer.Argument(
..., help="The string identifier of the platform to remove."
)
),
):
try:
platform = settings.toml.get_platform(name)
Expand Down
4 changes: 2 additions & 2 deletions ixmp4/data/api/iamc/datapoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def list(
self,
join_parameters: bool | None = None,
join_runs: bool | None = None,
**kwargs
**kwargs,
) -> list[DataPoint]:
return super()._list(
json=kwargs,
Expand All @@ -53,7 +53,7 @@ def tabulate(
self,
join_parameters: bool | None = None,
join_runs: bool | None = None,
**kwargs
**kwargs,
) -> pd.DataFrame:
return super()._tabulate(
json=kwargs,
Expand Down
4 changes: 4 additions & 0 deletions ixmp4/data/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ def __init__(self, info: PlatformInfo) -> None:
self.info = info
self.iamc = IamcSubobject()
self.optimization = OptimizationSubobject()

def close(self) -> None:
"""Closes the connection to the database."""
...
11 changes: 6 additions & 5 deletions ixmp4/data/db/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import sqlite3
from datetime import datetime
from datetime import datetime, timezone
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -116,7 +116,10 @@ def get(self, *args, **kwargs) -> ModelType:

class Creator(BaseRepository[ModelType], abstract.Creator):
def get_creation_info(self) -> dict:
info = {"created_at": datetime.utcnow(), "created_by": "@unknown"}
info = {
"created_at": datetime.now(tz=timezone.utc),
"created_by": "@unknown",
}
if self.backend.auth_context is not None:
info["created_by"] = self.backend.auth_context.user.username
return info
Expand Down Expand Up @@ -236,9 +239,7 @@ def tabulate(

if self.session.bind is not None:
with self.engine.connect() as con:
return (
pd.read_sql(_exc, con=con).fillna(np.nan).replace([np.nan], [None])
)
return pd.read_sql(_exc, con=con).replace([np.nan], [None])
else:
raise ProgrammingError("Database session is closed.")

Expand Down
2 changes: 1 addition & 1 deletion ixmp4/data/db/iamc/datapoint/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def select(
join_runs: bool = False,
_filter: DataPointFilter | None = None,
_exc: db.sql.Select | None = None,
**kwargs: Any
**kwargs: Any,
) -> db.sql.Select:
if _exc is not None:
exc = _exc
Expand Down
2 changes: 1 addition & 1 deletion ixmp4/data/db/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def select(
*,
_exc: db.sql.Select | None = None,
join_parameters: bool | None = False,
**kwargs
**kwargs,
) -> db.sql.Select:
if _exc is not None:
exc = _exc
Expand Down
4 changes: 2 additions & 2 deletions ixmp4/db/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ def process_field(cls, namespace: dict, field_name: str, field_type: type):
)
else:
override_lookups = None
if override_lookups:
if isinstance(override_lookups, list):
lookups = {k: v for k, v in lookups.items() if k in override_lookups}
elif override_lookups is None:
pass
else:
else: # TODO (How) do we ensure the type of override_lookups?
lookups = {}
base_field_alias = str(field.alias) if field.alias else field_name

Expand Down
4 changes: 2 additions & 2 deletions ixmp4/server/rest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from fastapi import Depends, FastAPI, Path, Request
from fastapi.encoders import jsonable_encoder
Expand Down Expand Up @@ -69,7 +69,7 @@ def root(
version=version,
is_managed=settings.managed,
manager_url=str(settings.manager_url),
utcnow=datetime.utcnow(),
utcnow=datetime.now(tz=timezone.utc),
)


Expand Down
2 changes: 1 addition & 1 deletion ixmp4/server/rest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
__pydantic_self__,
*args,
results: pd.DataFrame | api.DataFrame | list[EnumeratedT],
**kwargs
**kwargs,
):
if isinstance(results, pd.DataFrame):
kwargs["results"] = api.DataFrame.model_validate(results)
Expand Down
Loading

0 comments on commit ea9740f

Please sign in to comment.