Skip to content

Commit

Permalink
Merge again
Browse files Browse the repository at this point in the history
Resolve conflicts
  • Loading branch information
killian-scalian committed Oct 17, 2024
2 parents 61bb3ff + cd4a6f0 commit c98f527
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 143 deletions.
33 changes: 27 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
.vscode
# Some categories and items copied from https://github.com/github/gitignore/blob/main/Python.gitignore

# Byte-compiled / optimized / DLL files
__pycache__
**.ipynb

.idea
venv
.env
# Distribution / packaging
.Python
build/
dist/
sdist/
*.egg-info/
site/

# Unit test / coverage reports
.coverage
coverage.xml
AntaresWebDesktop
.tox/

# Environments
.env
.venv
env/
venv/

# Jupyter notebooks
**.ipynb

# Other
.vscode
.idea
AntaresWebDesktop/
44 changes: 40 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
Antares Craft python library is currently under construction. When completed it will allow to create, update and read antares studies.
# antares_craft
[![github ci](https://github.com/AntaresSimulatorTeam/antares_craft/actions/workflows/ci.yml/badge.svg)](https://github.com/AntaresSimulatorTeam/antares_craft/actions/workflows/ci.yml)

## about

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/`
## developers
### install dev requirements

Install dev requirements with `pip install -r requirements-dev.txt`

### linting and formatting

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).
### typechecking

To typecheck your code, use this command line: `mypy`

### integration testing

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`

### tox
To use [tox](https://tox.wiki/) to run unit tests in multiple python versions at the same time as linting and formatting
with ruff and typing with mypy:
1) As the dev requirements include [uv](https://docs.astral.sh/uv/) and `tox-uv` there is no need to install python
versions, `uv` will do this for you.
2) Use `tox -p` to run the environments in parallel to save time, this will create virtual environment with the
necessary python versions the first time you run tox.

### mkdocs
Smallest beginning of `mkdocs` included more as proof of concept than anything, theme and logo copied from [Antares
Simulator](https://github.com/AntaresSimulatorTeam/Antares_Simulator).
1) To preview the docs on your local machine run `mkdocs serve`.
2) To build the static site for publishing for example on [Read the Docs](https://readthedocs.io) use `mkdocs build`.
3) To flesh out the documentation see [mkdoc guides](https://www.mkdocs.org/user-guide/).
Binary file added docs/assets/Icone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/antares.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# antares_craft
[![github ci](https://github.com/AntaresSimulatorTeam/antares_craft/actions/workflows/ci.yml/badge.svg)](https://github.com/AntaresSimulatorTeam/antares_craft/actions/workflows/ci.yml)

## about

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.

## developers
### install dev requirements

Install dev requirements with `pip install -r requirements-dev.txt`

### linting and formatting

To reformat your code, use this command line: `ruff check src/ tests/ --fix && ruff format src/ tests/`

### typechecking

To typecheck your code, use this command line: `mypy`

### integration testing

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`

### tox
To use [tox](https://tox.wiki/) to run unit tests in multiple python versions at the same time as linting and formatting
with ruff and typing with mypy:
1) As the dev requirements include [uv](https://docs.astral.sh/uv/) and `tox-uv` there is no need to install python
versions, `uv` will do this for you.
2) Use `tox -p` to run the environments in parallel to save time, this will create virtual environment with the
necessary python versions the first time you run tox.

### mkdocs
Smallest beginning of `mkdocs` included more as proof of concept than anything, theme and logo copied from [Antares
Simulator](https://github.com/AntaresSimulatorTeam/Antares_Simulator).
1) To preview the docs on your local machine run `mkdocs serve`.
2) To build the static site for publishing for example on [Read the Docs](https://readthedocs.io) use `mkdocs build`.
3) To flesh out the documentation see [mkdoc guides](https://www.mkdocs.org/user-guide/).
10 changes: 10 additions & 0 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Reference

To start using Antares Craft create a study using either the API or local modes, you can then build on the created object to add study elements as you go:

Exemple:

study = create_study_local("test_study", 880, {"local_path": "test_study", "study_name": "test_study"})


::: src.antares.model.study
34 changes: 34 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
site_name: Antares Craft
repo_url: https://github.com/AntaresSimulatorTeam/antares_craft
nav:
- Home: index.md
- Quickstart: quickstart.md
theme:
name: material
logo: assets/logo.png
favicon: assets/Icone.png
prev_next_buttons_location: none
# custom_dir: docs/overrides
features:
- navigation.instant
- navigation.top
- content.tabs.link
# - navigation.expand
# - navigation.sections
# - header.autohide
# - toc.separate
palette:
- media: "(prefers-color-scheme: light)"
scheme: antares
toggle:
icon: material/toggle-switch-off-outline
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/toggle-switch
name: Switch to light mode

plugins:
- search
- mkdocstrings
30 changes: 26 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,35 @@ build-backend = "setuptools.build_meta"
[project]
name = "antares_craft"
version = "0.0.1"
description = """Antares Craft python library is currently under construction. When completed it will allow to \
create, update and read antares studies."""
readme = "README.md"
license = {file = "LICENSE"}
authors = [
{name="Sylvain Leclerc"},
{name="Tatiana Vargas"},
{name="Martin Behlthle"},
{name="Sigurd Borge"}
]
requires-python = ">=3.9"
dependencies = [

]
classifiers = [
# Classifiers here: https://pypi.org/classifiers/
"Development Status :: 2 - Pre-Alpha",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[project.urls]
Repository = "https://github.com/AntaresSimulatorTeam/antares_craft"
"Bug Tracker" = "https://github.com/AntaresSimulatorTeam/antares_craft/issues"

# Setuptools
[tool.setuptools.packages.find]
# All the following settings are optional:
## All the following settings are optional:
where = ["src"]

[tool.ruff]
line-length = 120
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
absl-py~=1.4.0
click~=8.1.7
configparser~=5.0.2
numpy~=1.26.4
requests~=2.31.0
pandas~=2.2.2
pandas-stubs~=2.2.2
pydantic~=2.7.1
pytest~=7.2.1
python-dateutil~=2.9.0
pydantic~=2.7.1
configparser~=5.0.2
click~=8.1.7
requests~=2.31.0
11 changes: 9 additions & 2 deletions src/antares/api_conf/request_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@

import json

from typing import Any, Dict, Optional, Union
from typing import Any, Iterable, Mapping, Optional, Union

import requests

from antares.exceptions.exceptions import APIError

DATA_TYPE = Union[str, bytes, Dict[str, Any], None]
DATA_TYPE = Union[
Iterable[bytes],
str,
bytes,
list[tuple[Any, Any]],
tuple[tuple[Any, Any], ...],
Mapping[Any, Any],
]


def _handle_exceptions(response: requests.Response) -> requests.Response:
Expand Down
11 changes: 2 additions & 9 deletions src/antares/service/api_services/renewable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

from antares.api_conf.api_conf import APIconf
from antares.api_conf.request_wrapper import RequestWrapper
from antares.exceptions.exceptions import (
APIError,
RenewableMatrixDownloadError,
RenewablePropertiesUpdateError,
)
from antares.exceptions.exceptions import APIError, RenewableMatrixDownloadError, RenewablePropertiesUpdateError
from antares.model.renewable import RenewableCluster, RenewableClusterProperties
from antares.service.api_services.utils import get_matrix
from antares.service.base_services import BaseRenewableService
Expand Down Expand Up @@ -64,9 +60,6 @@ def get_renewable_matrix(self, renewable: RenewableCluster) -> pd.DataFrame:
/ f"{renewable.name}"
/ "series"
)
return get_matrix(
f"{self._base_url}/studies/{self.study_id}/raw?path={path}",
self._wrapper,
)
return get_matrix(f"{self._base_url}/studies/{self.study_id}/raw?path={path}", self._wrapper)
except APIError as e:
raise RenewableMatrixDownloadError(renewable.area_id, renewable.name, e.message) from e
5 changes: 1 addition & 4 deletions src/antares/service/base_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ def create_load(self, area: Area, series: Optional[pd.DataFrame]) -> Load:

@abstractmethod
def create_st_storage(
self,
area_id: str,
st_storage_name: str,
properties: Optional[STStorageProperties] = None,
self, area_id: str, st_storage_name: str, properties: Optional[STStorageProperties] = None
) -> STStorage:
"""
Args:
Expand Down
46 changes: 8 additions & 38 deletions tests/antares/delete/test_delete_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
from antares.model.st_storage import STStorage
from antares.model.thermal import ThermalCluster
from antares.service.api_services.area_api import AreaApiService
from antares.service.api_services.binding_constraint_api import (
BindingConstraintApiService,
)
from antares.service.api_services.binding_constraint_api import BindingConstraintApiService
from antares.service.api_services.link_api import LinkApiService
from antares.service.api_services.renewable_api import RenewableApiService
from antares.service.api_services.st_storage_api import ShortTermStorageApiService
Expand Down Expand Up @@ -63,11 +61,7 @@ def test_delete_area_success(self):
def test_delete_area_fails(self):
with requests_mock.Mocker() as mocker:
url = f"https://antares.com/api/v1/studies/{self.study_id}/areas/{self.area_fr.id}"
mocker.delete(
url,
json={"description": self.antares_web_description_msg},
status_code=404,
)
mocker.delete(url, json={"description": self.antares_web_description_msg}, status_code=404)
with pytest.raises(
AreaDeletionError,
match=f"Could not delete the area {self.area_fr.id}: {self.antares_web_description_msg}",
Expand All @@ -85,11 +79,7 @@ def test_delete_link_fails(self):
with requests_mock.Mocker() as mocker:
link = Link(self.area_fr, self.area_be, self.link_service)
url = f"https://antares.com/api/v1/studies/{self.study_id}/links/{self.area_fr.id}/{self.area_be.id}"
mocker.delete(
url,
json={"description": self.antares_web_description_msg},
status_code=404,
)
mocker.delete(url, json={"description": self.antares_web_description_msg}, status_code=404)
with pytest.raises(
LinkDeletionError,
match=f"Could not delete the link {self.area_fr.id} / {self.area_be.id}: {self.antares_web_description_msg}",
Expand All @@ -108,11 +98,7 @@ def test_delete_thermal_fails(self):
cluster1 = ThermalCluster(self.thermal_service, self.area_fr.id, "gaz_cluster")
cluster2 = ThermalCluster(self.thermal_service, self.area_fr.id, "gaz_cluster_2")
url = f"https://antares.com/api/v1/studies/{self.study_id}/areas/{self.area_fr.id}/clusters/thermal"
mocker.delete(
url,
json={"description": self.antares_web_description_msg},
status_code=404,
)
mocker.delete(url, json={"description": self.antares_web_description_msg}, status_code=404)
with pytest.raises(
ThermalDeletionError,
match=f"Could not delete the following thermal clusters: gaz_cluster, gaz_cluster_2 inside area fr: {self.antares_web_description_msg}",
Expand All @@ -130,11 +116,7 @@ def test_delete_renewable_fails(self):
with requests_mock.Mocker() as mocker:
cluster = RenewableCluster(self.renewable_service, self.area_fr.id, "gaz_cluster")
url = f"https://antares.com/api/v1/studies/{self.study_id}/areas/{self.area_fr.id}/clusters/renewable"
mocker.delete(
url,
json={"description": self.antares_web_description_msg},
status_code=404,
)
mocker.delete(url, json={"description": self.antares_web_description_msg}, status_code=404)
with pytest.raises(
RenewableDeletionError,
match=f"Could not delete the following renewable clusters: gaz_cluster inside area fr: {self.antares_web_description_msg}",
Expand All @@ -152,11 +134,7 @@ def test_delete_st_storage_fails(self):
with requests_mock.Mocker() as mocker:
storage = STStorage(self.st_storage_service, self.area_fr.id, "battery_fr")
url = f"https://antares.com/api/v1/studies/{self.study_id}/areas/{self.area_fr.id}/storages"
mocker.delete(
url,
json={"description": self.antares_web_description_msg},
status_code=404,
)
mocker.delete(url, json={"description": self.antares_web_description_msg}, status_code=404)
with pytest.raises(
STStorageDeletionError,
match=f"Could not delete the following short term storages: battery_fr inside area fr: {self.antares_web_description_msg}",
Expand All @@ -176,11 +154,7 @@ def test_delete_binding_constraint_fails(self):
constraint_id = "bc_1"
constraint = BindingConstraint(constraint_id, self.constraint_service)
url = f"https://antares.com/api/v1/studies/{self.study_id}/bindingconstraints/{constraint_id}"
mocker.delete(
url,
json={"description": self.antares_web_description_msg},
status_code=404,
)
mocker.delete(url, json={"description": self.antares_web_description_msg}, status_code=404)
with pytest.raises(
BindingConstraintDeletionError,
match=f"Could not delete the binding constraint {constraint_id}: {self.antares_web_description_msg}",
Expand All @@ -204,11 +178,7 @@ def test_delete_constraint_terms_fails(self):
url = (
f"https://antares.com/api/v1/studies/{self.study_id}/bindingconstraints/{constraint_id}/term/{term_id}"
)
mocker.delete(
url,
json={"description": self.antares_web_description_msg},
status_code=404,
)
mocker.delete(url, json={"description": self.antares_web_description_msg}, status_code=404)
with pytest.raises(
ConstraintTermDeletionError,
match=f"Could not delete the term {term_id} of the binding constraint {constraint_id}: {self.antares_web_description_msg}",
Expand Down
Loading

0 comments on commit c98f527

Please sign in to comment.