-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit, create services defined
- Loading branch information
Showing
75 changed files
with
8,895 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Github identifiers of authors, in alphabetical order: | ||
|
||
berthetclement | ||
killian-scalian | ||
MartinBelthle | ||
Sigurd-Borge | ||
sylvlecl | ||
vargastat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Antares Craft python library is currently under construction. When completed it will allow to create, update and read antares studies. | ||
|
||
This project only supports antares studies with a version v8.8 or higher. | ||
|
||
To reformat your code, use this command line : `ruff check src/ tests/ --fix && ruff format src/ tests/` | ||
|
||
To launch integration tests you'll need an AntaresWebDesktop instance on your local env (at least the v.2.17.3, **currently running in 2.17.5**). | ||
To install it, download it from the last [Antares Web release](https://github.com/AntaresSimulatorTeam/AntaREST/releases) (inside the assets list). | ||
Then, unzip it at the root of this repository and rename the folder `AntaresWebDesktop`. | ||
*NB*: The expected folder structure is the following: `antares_craft/AntaresWebDesktop/config.yaml` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[mypy] | ||
mypy_path = src | ||
packages= antares | ||
disallow_untyped_defs = true | ||
disallow_untyped_calls = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "antares_craft" | ||
version = "0.0.1" | ||
dependencies = [ | ||
|
||
] | ||
|
||
[tool.setuptools.packages.find] | ||
# All the following settings are optional: | ||
where = ["src"] | ||
|
||
[tool.ruff] | ||
line-length = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[pytest] | ||
pythonpath = src | ||
testpaths = tests | ||
log_cli = true | ||
junit_family=xunit2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-r requirements.txt | ||
mypy~=1.10.0 | ||
ruff==0.4.7 | ||
pytest-cov~=5.0.0 | ||
requests-mock~=1.12.1 | ||
types-requests~=2.27.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
absl-py==1.4.0 | ||
numpy==1.24.4 | ||
protobuf==4.23.3 | ||
requests~=2.31.0 | ||
pandas ~=2.2.2 | ||
pandas-stubs ~=2.2.2 | ||
pytest~=7.2.1 | ||
python-dateutil~=2.9.0 | ||
pydantic==2.7.1 | ||
configparser~=5.0.2 |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# 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 requests | ||
|
||
from antares.config.base_configuration import BaseConfiguration | ||
from antares.exceptions.exceptions import MissingTokenError | ||
|
||
|
||
class APIconf(BaseConfiguration): | ||
""" | ||
APIconf defines host and token to be used for API mode | ||
""" | ||
|
||
def __init__(self, api_host: str, token: str, verify: bool = True) -> None: | ||
self._api_host: str = api_host | ||
self._token: str = token | ||
self._verify: bool = verify | ||
|
||
@property | ||
def token(self) -> str: | ||
return self._token | ||
|
||
@token.setter | ||
def token(self, value: str) -> None: | ||
self._token = value | ||
|
||
@property | ||
def verify(self) -> bool: | ||
return self._verify | ||
|
||
@property | ||
def api_host(self) -> str: | ||
return self._api_host | ||
|
||
@api_host.setter | ||
def api_host(self, value: str) -> None: | ||
self._api_host = value | ||
|
||
def get_host(self) -> str: | ||
return self._api_host | ||
|
||
def get_token(self) -> str: | ||
return self._token | ||
|
||
def checks_token(self) -> None: | ||
if self._api_host not in ["localhost", "127.0.0.1"] and self._token is None: | ||
raise MissingTokenError() | ||
|
||
def set_up_api_conf(self) -> requests.Session: | ||
self.checks_token() | ||
session = requests.Session() | ||
if self._token: | ||
token_bearer = f"Bearer {self._token}" | ||
session.headers.update({"Authorization": token_bearer}) | ||
return session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# 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 json | ||
from typing import IO, Any, Iterable, Mapping, Optional, Tuple, Union | ||
|
||
import requests | ||
|
||
from antares.exceptions.exceptions import APIError | ||
|
||
DATA_TYPE = Union[str, bytes, Mapping[str, Any], Iterable[Tuple[str, Optional[str]]], IO] | ||
|
||
|
||
def _handle_exceptions(response: requests.Response) -> requests.Response: | ||
""" | ||
If an exception occurred, returns APIError exception containing the AntaresWeb error message. | ||
""" | ||
if response.status_code - 200 < 100: | ||
return response | ||
try: | ||
msg = response.json()["description"] | ||
except (json.decoder.JSONDecodeError, KeyError): | ||
msg = response.reason | ||
raise APIError(msg) | ||
|
||
|
||
class RequestWrapper: | ||
""" | ||
A wrapper around the requests library | ||
""" | ||
|
||
def __init__(self, session: requests.Session): | ||
self.session = session | ||
|
||
def get(self, url: str, **kwargs: Any) -> requests.Response: | ||
response = self.session.get(url, **kwargs) | ||
return _handle_exceptions(response) | ||
|
||
def post( | ||
self, url: str, data: Optional[DATA_TYPE] = None, json: Optional[Any] = None, **kwargs: Any | ||
) -> requests.Response: | ||
response = self.session.post(url, data, json, **kwargs) | ||
return _handle_exceptions(response) | ||
|
||
def put(self, url: str, data: Optional[DATA_TYPE] = None, **kwargs: Any) -> requests.Response: | ||
response = self.session.put(url, data, **kwargs) | ||
return _handle_exceptions(response) | ||
|
||
def patch(self, url: str, data: Optional[DATA_TYPE] = None, **kwargs: Any) -> requests.Response: | ||
response = self.session.patch(url, data, **kwargs) | ||
return _handle_exceptions(response) | ||
|
||
def delete(self, url: str, **kwargs: Any) -> requests.Response: | ||
response = self.session.delete(url, **kwargs) | ||
return _handle_exceptions(response) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 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 abc import ABC | ||
|
||
|
||
class BaseConfiguration(ABC): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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 pathlib import Path | ||
|
||
from antares.config.base_configuration import BaseConfiguration | ||
|
||
|
||
class LocalConfiguration(BaseConfiguration): | ||
def __init__(self, local_path: Path, study_name: str): | ||
self._local_path = local_path | ||
self._study_name = study_name | ||
|
||
@property | ||
def local_path(self) -> Path: | ||
return self._local_path | ||
|
||
@property | ||
def study_path(self) -> Path: | ||
return self._local_path / self._study_name |
Empty file.
Oops, something went wrong.