Skip to content

Commit

Permalink
merge with dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Sep 30, 2024
2 parents 4ef2cb4 + 0bbfde5 commit d566a2d
Show file tree
Hide file tree
Showing 1,153 changed files with 27,779 additions and 8,957 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/license_header.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: check license headers
on:
push:
branches:
- "**"

jobs:
check-license-headers:
runs-on: ubuntu-20.04
steps:
- name: Checkout github repo (+ download lfs dependencies)
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install click
- name: Check licenses header
run: |
python license_checker_and_adder.py --path=../antarest/ --action=check-strict
python license_checker_and_adder.py --path=../tests/ --action=check-strict
python license_checker_and_adder.py --path=../webapp/src --action=check-strict
working-directory: scripts
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
pip install -r requirements-dev.txt
- name: Test with pytest
run: |
pytest --cov antarest --cov-report xml
pytest --cov antarest --cov-report xml -n auto --dist=worksteal
- name: Archive code coverage results
if: matrix.os == 'ubuntu-20.04'
uses: actions/upload-artifact@v4
Expand Down
25 changes: 25 additions & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Github identifiers of authors, in alphabetical order:

3lbanna
a-zakir
cbion
flomnes
FrancoisJ
GPivette
hdinia
Hyralc
insatomcat
laurent-laporte-pro
mabw-rte
makdeuneuv
MartinBelthle
maugde
olfamizen
pl-buiquang
qdesmedt
romeoadanhounme
sgatto
skamril
sylvlecl
TLAIDI
Wintxer
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""
import collections
import itertools
import json
import secrets
import typing as t

Expand All @@ -16,6 +15,7 @@
from sqlalchemy.engine import Connection # type: ignore

from antarest.study.css4_colors import COLOR_NAMES
from antarest.core.serialization import from_json, to_json

# revision identifiers, used by Alembic.
revision = "dae93f1d9110"
Expand All @@ -34,7 +34,7 @@ def _avoid_duplicates(tags: t.Iterable[str]) -> t.Sequence[str]:
def _load_patch_obj(patch: t.Optional[str]) -> t.MutableMapping[str, t.Any]:
"""Load the patch object from the `patch` field in the `study_additional_data` table."""

obj: t.MutableMapping[str, t.Any] = json.loads(patch or "{}")
obj: t.MutableMapping[str, t.Any] = from_json(patch or "{}")
obj["study"] = obj.get("study") or {}
obj["study"]["tags"] = _avoid_duplicates(obj["study"].get("tags") or [])
return obj
Expand Down Expand Up @@ -113,7 +113,7 @@ def downgrade() -> None:
objects_by_ids[study_id] = obj

# Updating objects in the `study_additional_data` table
bulk_patches = [{"study_id": id_, "patch": json.dumps(obj)} for id_, obj in objects_by_ids.items()]
bulk_patches = [{"study_id": id_, "patch": to_json(obj)} for id_, obj in objects_by_ids.items()]
if bulk_patches:
sql = sa.text("UPDATE study_additional_data SET patch = :patch WHERE study_id = :study_id")
connexion.execute(sql, *bulk_patches)
Expand Down
16 changes: 14 additions & 2 deletions antarest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

"""
Antares Web
Expand All @@ -7,9 +19,9 @@

# Standard project metadata

__version__ = "2.17.5"
__version__ = "2.17.6"
__author__ = "RTE, Antares Web Team"
__date__ = "2024-08-02"
__date__ = "2024-09-25"
# noinspection SpellCheckingInspection
__credits__ = "(c) Réseau de Transport de l’Électricité (RTE)"

Expand Down
11 changes: 11 additions & 0 deletions antarest/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
48 changes: 48 additions & 0 deletions antarest/core/application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

from dataclasses import dataclass
from typing import Optional

from fastapi import APIRouter, FastAPI


@dataclass(frozen=True)
class AppBuildContext:
"""
Base elements of the application, for use at construction time:
- app: the actual fastapi application, where middlewares, exception handlers, etc. may be added
- api_root: the route under which all API and WS endpoints must be registered
API routes should not be added straight to app, but under api_root instead,
so that they are correctly prefixed if needed (/api for standalone mode).
Warning: the inclusion of api_root must happen AFTER all subroutes
have been registered, hence the build method.
"""

app: FastAPI
api_root: APIRouter

def build(self) -> FastAPI:
"""
Finalizes the app construction by including the API route.
Must be performed AFTER all subroutes have been added.
"""
self.app.include_router(self.api_root)
return self.app


def create_app_ctxt(app: FastAPI, api_root: Optional[APIRouter] = None) -> AppBuildContext:
if not api_root:
api_root = APIRouter()
return AppBuildContext(app, api_root)
11 changes: 11 additions & 0 deletions antarest/core/cache/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
11 changes: 11 additions & 0 deletions antarest/core/cache/business/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
12 changes: 12 additions & 0 deletions antarest/core/cache/business/local_chache.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

import logging
import threading
import time
Expand Down
18 changes: 15 additions & 3 deletions antarest/core/cache/business/redis_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import json
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

import logging
from typing import List, Optional

Expand All @@ -7,6 +18,7 @@

from antarest.core.interfaces.cache import ICache
from antarest.core.model import JSON
from antarest.core.serialization import from_json

logger = logging.getLogger(__name__)

Expand All @@ -28,7 +40,7 @@ def put(self, id: str, data: JSON, duration: int = 3600) -> None:
redis_element = RedisCacheElement(duration=duration, data=data)
redis_key = f"cache:{id}"
logger.info(f"Adding cache key {id}")
self.redis.set(redis_key, redis_element.json())
self.redis.set(redis_key, redis_element.model_dump_json())
self.redis.expire(redis_key, duration)

def get(self, id: str, refresh_timeout: Optional[int] = None) -> Optional[JSON]:
Expand All @@ -37,7 +49,7 @@ def get(self, id: str, refresh_timeout: Optional[int] = None) -> Optional[JSON]:
logger.info(f"Trying to retrieve cache key {id}")
if result is not None:
logger.info(f"Cache key {id} found")
json_result = json.loads(result)
json_result = from_json(result)
redis_element = RedisCacheElement(duration=json_result["duration"], data=json_result["data"])
self.redis.expire(
redis_key,
Expand Down
12 changes: 12 additions & 0 deletions antarest/core/cache/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

import logging
from typing import Optional

Expand Down
31 changes: 26 additions & 5 deletions antarest/core/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

import multiprocessing
import tempfile
from dataclasses import asdict, dataclass, field
from enum import Enum
from pathlib import Path
from typing import Dict, List, Optional

Expand All @@ -12,6 +25,12 @@
DEFAULT_WORKSPACE_NAME = "default"


class Launcher(str, Enum):
SLURM = "slurm"
LOCAL = "local"
DEFAULT = "default"


@dataclass(frozen=True)
class ExternalAuthConfig:
"""
Expand Down Expand Up @@ -387,7 +406,7 @@ def __post_init__(self) -> None:
msg = f"Invalid configuration: {self.default=} must be one of {possible!r}"
raise ValueError(msg)

def get_nb_cores(self, launcher: str) -> "NbCoresConfig":
def get_nb_cores(self, launcher: Launcher) -> "NbCoresConfig":
"""
Retrieve the number of cores configuration for a given launcher: "local" or "slurm".
If "default" is specified, retrieve the configuration of the default launcher.
Expand All @@ -404,12 +423,12 @@ def get_nb_cores(self, launcher: str) -> "NbCoresConfig":
"""
config_map = {"local": self.local, "slurm": self.slurm}
config_map["default"] = config_map[self.default]
launcher_config = config_map.get(launcher)
launcher_config = config_map.get(launcher.value)
if launcher_config is None:
raise InvalidConfigurationError(launcher)
raise InvalidConfigurationError(launcher.value)
return launcher_config.nb_cores

def get_time_limit(self, launcher: str) -> TimeLimitConfig:
def get_time_limit(self, launcher: Launcher) -> TimeLimitConfig:
"""
Retrieve the time limit for a job of the given launcher: "local" or "slurm".
If "default" is specified, retrieve the configuration of the default launcher.
Expand All @@ -426,7 +445,7 @@ def get_time_limit(self, launcher: str) -> TimeLimitConfig:
"""
config_map = {"local": self.local, "slurm": self.slurm}
config_map["default"] = config_map[self.default]
launcher_config = config_map.get(launcher)
launcher_config = config_map.get(launcher.value)
if launcher_config is None:
raise InvalidConfigurationError(launcher)
return launcher_config.time_limit
Expand Down Expand Up @@ -574,6 +593,7 @@ class Config:
cache: CacheConfig = CacheConfig()
tasks: TaskConfig = TaskConfig()
root_path: str = ""
api_prefix: str = ""

@classmethod
def from_dict(cls, data: JSON) -> "Config":
Expand All @@ -592,6 +612,7 @@ def from_dict(cls, data: JSON) -> "Config":
cache=CacheConfig.from_dict(data["cache"]) if "cache" in data else defaults.cache,
tasks=TaskConfig.from_dict(data["tasks"]) if "tasks" in data else defaults.tasks,
root_path=data.get("root_path", defaults.root_path),
api_prefix=data.get("api_prefix", defaults.api_prefix),
)

@classmethod
Expand Down
11 changes: 11 additions & 0 deletions antarest/core/configdata/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
12 changes: 12 additions & 0 deletions antarest/core/configdata/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

from enum import Enum
from typing import Any, Optional

Expand Down
Loading

0 comments on commit d566a2d

Please sign in to comment.