Skip to content

Commit

Permalink
Feat/update project management (#7)
Browse files Browse the repository at this point in the history
* Added default properties to binding constraints

* Added bindingconstraints.ini file

* Added default value 0 for constraint weight

* Added the weight and offset combination in the ini file, as well as disabled interpolation in the ini tool

* Refactored binding constraints to be tracked in the service instead of the study to allow correct handling of ini file

* Make types-requests match requests version to as they're meant to be aligned, also updated for the new DATA definition in types-requests

* Added authors and linting rules to pyproject.toml. The rules chosen are the ruff defaults + sorting imports

* Cleaned up imports to match the new linting rule

* Moved pytest and mypy options into pyproject.toml

* Added isort options to pyproject.toml and updated imports again

* Added __init__.py to integration to correct import behavior

* Added a first tox.ini as tox for now doesn't have proper pyproject.toml support, also updated README.md with a bit of information about how to use tox

* Moved coverage configuration into pyproject.toml and sorted requirements.txt and requirements-dev.txt plus made sure coverage can read toml

* Fixed missing header and added header fixes to tox.ini

* Updated .gitignore to remove some build caching and organize a bit better

* Added more information to pyproject.toml and organized it better. Some cleanup after rebase.

* Bumped tox version to allow tox configuration in pyproject.toml and deleted tox.ini.

* First tiny step of documentation added using mkdocs and the template from Antares Simulator. Included possibility to parse documentation from docstrings.

* Reverting to individual configuration files as per discussion
  • Loading branch information
Sigurd-Borge authored Oct 14, 2024
1 parent 3643b47 commit cd4a6f0
Show file tree
Hide file tree
Showing 54 changed files with 440 additions and 185 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
12 changes: 9 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
-r requirements.txt
coverage[toml]~=7.6.1
mkdocs~=1.6.1
mkdocstrings[python]~=0.26.1
mkdocs-material~=9.5.40
mypy~=1.10.0
ruff~=0.4.7
pytest-cov~=5.0.0
requests-mock~=1.12.1
types-requests~=2.27.1
tox~=4.18.1
ruff~=0.4.7
setuptools~=75.1.0
setuptools-scm[toml]~=8.1.0
tox~=4.21.2
tox-uv~=1.11.3
types-requests~=2.31.0
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
20 changes: 20 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
line-length = 120

[lint]
## E4, E7, E9 and F are the default configuration of ruff, "I" is added to handle imports
select = ["E4", "E7", "E9", "F", "I"]

[lint.isort]
## Use a single line between direct import and from import.
lines-between-types = 1
section-order = [
"testing",
"future",
"standard-library",
"third-party",
"first-party",
"local-folder",
]

[lint.isort.sections]
testing = ["pytest*", "*mock*"]
12 changes: 10 additions & 2 deletions src/antares/api_conf/request_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
# This file is part of the Antares project.

import json
from typing import IO, Any, Iterable, Mapping, Optional, Tuple, Union

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

import requests

from antares.exceptions.exceptions import APIError

DATA_TYPE = Union[str, bytes, Mapping[str, Any], Iterable[Tuple[str, Optional[str]]], IO]
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
7 changes: 4 additions & 3 deletions src/antares/model/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
"""

from types import MappingProxyType
from typing import Optional, Dict, List, Any, Mapping, Set
from typing import Any, Dict, List, Mapping, Optional, Set

import pandas as pd

from pydantic import BaseModel, computed_field
from pydantic.alias_generators import to_camel

from antares.model.commons import FilterOption, sort_filter_values
from antares.model.hydro import HydroProperties, HydroMatrixName, Hydro
from antares.model.hydro import Hydro, HydroMatrixName, HydroProperties
from antares.model.load import Load
from antares.model.misc_gen import MiscGen
from antares.model.renewable import RenewableCluster, RenewableClusterProperties
Expand All @@ -34,7 +35,7 @@
from antares.model.thermal import ThermalCluster, ThermalClusterProperties
from antares.model.wind import Wind
from antares.tools.all_optional_meta import all_optional_model
from antares.tools.contents_tool import transform_name_to_id, EnumIgnoreCase
from antares.tools.contents_tool import EnumIgnoreCase, transform_name_to_id


class AdequacyPatchMode(EnumIgnoreCase):
Expand Down
3 changes: 2 additions & 1 deletion src/antares/model/binding_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
# This file is part of the Antares project.

from enum import Enum
from typing import Optional, Union, List, Any, Dict
from typing import Any, Dict, List, Optional, Union

import pandas as pd

from pydantic import BaseModel, Field, model_validator
from pydantic.alias_generators import to_camel

Expand Down
3 changes: 2 additions & 1 deletion src/antares/model/hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
# This file is part of the Antares project.

from enum import Enum
from typing import Optional, Dict
from typing import Dict, Optional

import pandas as pd

from pydantic import BaseModel
from pydantic.alias_generators import to_camel

Expand Down
2 changes: 1 addition & 1 deletion src/antares/model/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# This file is part of the Antares project.

from enum import Enum
from typing import Optional, Set, Mapping
from typing import Mapping, Optional, Set

from pydantic import BaseModel

Expand Down
2 changes: 1 addition & 1 deletion src/antares/model/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# This file is part of the Antares project.

from typing import Optional, Dict
from typing import Dict, Optional

from pydantic import BaseModel

Expand Down
1 change: 1 addition & 0 deletions src/antares/model/st_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import Optional

import pandas as pd

from pydantic import BaseModel
from pydantic.alias_generators import to_camel

Expand Down
Loading

0 comments on commit cd4a6f0

Please sign in to comment.