Skip to content

Commit

Permalink
feat(ci): use tox (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle authored Nov 26, 2024
1 parent 5342a2c commit 46ad93c
Show file tree
Hide file tree
Showing 18 changed files with 250 additions and 789 deletions.
53 changes: 16 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,31 @@ on:

jobs:
ci:
runs-on: ubuntu-20.04
runs-on: ${{ matrix.os }}

strategy:
max-parallel: 9
matrix:
os: [ windows-latest, ubuntu-20.04, ubuntu-22.04 ]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
cache: pip
cache-dependency-path: |
requirements.txt
requirements-dev.txt
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-dev.txt
- name: Check formatting
run: ruff format --check src tests

- name: Check typing
run: |
python -m mypy
- name: Test
run: |
pytest --cov src --cov-report xml tests/antares
pip install tox~=4.21.2
pip install tox-uv~=1.11.3
- name: Archive code coverage results
uses: actions/upload-artifact@v4
with:
name: python-code-coverage-report
path: coverage.xml
- name: Performs Ubuntu tests
if: matrix.os != 'windows-latest'
run: tox -p

sonarcloud:
runs-on: ubuntu-20.04
needs: [ci]
steps:
- uses: actions/checkout@v4
- name: Download python coverage report
uses: actions/download-artifact@v4
with:
name: python-code-coverage-report
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v2.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Performs Windows tests
if: matrix.os == 'windows-latest'
run: tox -e 3.9-test
48 changes: 48 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Coverage
on:
push:
branches:
- "**"

jobs:
coverage:
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox~=4.21.2
pip install tox-uv~=1.11.3
- name: Performs coverage
run: tox -e coverage

- name: Archive code coverage results
uses: actions/upload-artifact@v4
with:
name: python-code-coverage-report
path: coverage.xml

sonarcloud:
runs-on: ubuntu-22.04
needs: [coverage]

steps:
- uses: actions/checkout@v4
- name: Download python coverage report
uses: actions/download-artifact@v4
with:
name: python-code-coverage-report
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v2.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
25 changes: 0 additions & 25 deletions .github/workflows/license_header.yml

This file was deleted.

28 changes: 3 additions & 25 deletions src/antares/model/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,10 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
from pathlib import Path
from typing import Optional

import pandas as pd

from antares.tools.prepro_folder import PreproFolder
from antares.tools.time_series_tool import TimeSeries, TimeSeriesFile
from antares.tools.time_series_tool import TimeSeries


class Load:
def __init__(
self,
time_series: pd.DataFrame = pd.DataFrame([]),
local_file: Optional[TimeSeriesFile] = None,
study_path: Optional[Path] = None,
area_id: Optional[str] = None,
) -> None:
self._time_series = TimeSeries(time_series, local_file)
self._prepro = (
PreproFolder(folder="load", study_path=study_path, area_id=area_id) if study_path and area_id else None
)

@property
def time_series(self) -> TimeSeries:
return self._time_series

@property
def prepro(self) -> Optional[PreproFolder]:
return self._prepro
class Load(TimeSeries):
pass
28 changes: 3 additions & 25 deletions src/antares/model/solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,10 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
from pathlib import Path
from typing import Optional

import pandas as pd

from antares.tools.prepro_folder import PreproFolder
from antares.tools.time_series_tool import TimeSeries, TimeSeriesFile
from antares.tools.time_series_tool import TimeSeries


class Solar:
def __init__(
self,
time_series: pd.DataFrame = pd.DataFrame([]),
local_file: Optional[TimeSeriesFile] = None,
study_path: Optional[Path] = None,
area_id: Optional[str] = None,
) -> None:
self._time_series = TimeSeries(time_series, local_file)
self._prepro = (
PreproFolder(folder="solar", study_path=study_path, area_id=area_id) if study_path and area_id else None
)

@property
def time_series(self) -> TimeSeries:
return self._time_series

@property
def prepro(self) -> Optional[PreproFolder]:
return self._prepro
class Solar(TimeSeries):
pass
4 changes: 2 additions & 2 deletions src/antares/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ def delete(self, children: bool = False) -> None:


def _verify_study_already_exists(study_directory: Path) -> None:
if os.path.exists(study_directory):
raise FileExistsError(f"Study {study_directory} already exists.")
if study_directory.exists():
raise FileExistsError(f"Study {study_directory.name} already exists.")


def _create_directory_structure(study_path: Path) -> None:
Expand Down
28 changes: 3 additions & 25 deletions src/antares/model/wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,10 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
from pathlib import Path
from typing import Optional

import pandas as pd

from antares.tools.prepro_folder import PreproFolder
from antares.tools.time_series_tool import TimeSeries, TimeSeriesFile
from antares.tools.time_series_tool import TimeSeries


class Wind:
def __init__(
self,
time_series: pd.DataFrame = pd.DataFrame([]),
local_file: Optional[TimeSeriesFile] = None,
study_path: Optional[Path] = None,
area_id: Optional[str] = None,
) -> None:
self._time_series = TimeSeries(time_series, local_file)
self._prepro = (
PreproFolder(folder="wind", study_path=study_path, area_id=area_id) if study_path and area_id else None
)

@property
def time_series(self) -> TimeSeries:
return self._time_series

@property
def prepro(self) -> Optional[PreproFolder]:
return self._prepro
class Wind(TimeSeries):
pass
40 changes: 19 additions & 21 deletions src/antares/service/local_services/area_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
BaseThermalService,
)
from antares.tools.ini_tool import IniFile, IniFileTypes
from antares.tools.time_series_tool import TimeSeriesFile, TimeSeriesFileType
from antares.tools.prepro_folder import PreproFolder
from antares.tools.time_series_tool import TimeSeriesFileType


def _sets_ini_content() -> ConfigParser:
Expand Down Expand Up @@ -124,10 +125,13 @@ def create_renewable_cluster(

def create_load(self, area: Area, series: Optional[pd.DataFrame]) -> Load:
series = series if series is not None else pd.DataFrame([])
local_file = TimeSeriesFile(
TimeSeriesFileType.LOAD, self.config.study_path, area_id=area.id, time_series=series
)
return Load(time_series=series, local_file=local_file, study_path=self.config.study_path, area_id=area.id)
self._write_timeseries(series, TimeSeriesFileType.LOAD, area.id)
PreproFolder.LOAD.save(self.config.study_path, area.id)
return Load(time_series=series)

def _write_timeseries(self, series: pd.DataFrame, ts_file_type: TimeSeriesFileType, area_id: str) -> None:
file_path = self.config.study_path.joinpath(ts_file_type.value.format(area_id=area_id))
series.to_csv(file_path, sep="\t", header=False, index=False, encoding="utf-8")

def create_st_storage(
self, area_id: str, st_storage_name: str, properties: Optional[STStorageProperties] = None
Expand All @@ -149,31 +153,25 @@ def create_st_storage(

def create_wind(self, area: Area, series: Optional[pd.DataFrame]) -> Wind:
series = series if series is not None else pd.DataFrame([])
local_file = TimeSeriesFile(
TimeSeriesFileType.WIND, self.config.study_path, area_id=area.id, time_series=series
)
return Wind(time_series=series, local_file=local_file, study_path=self.config.study_path, area_id=area.id)
self._write_timeseries(series, TimeSeriesFileType.WIND, area.id)
PreproFolder.WIND.save(self.config.study_path, area.id)
return Wind(time_series=series)

def create_reserves(self, area: Area, series: Optional[pd.DataFrame]) -> Reserves:
series = series if series is not None else pd.DataFrame([])
local_file = TimeSeriesFile(
TimeSeriesFileType.RESERVES, self.config.study_path, area_id=area.id, time_series=series
)
return Reserves(series, local_file)
self._write_timeseries(series, TimeSeriesFileType.RESERVES, area.id)
return Reserves(series)

def create_solar(self, area: Area, series: Optional[pd.DataFrame]) -> Solar:
series = series if series is not None else pd.DataFrame([])
local_file = TimeSeriesFile(
TimeSeriesFileType.SOLAR, self.config.study_path, area_id=area.id, time_series=series
)
return Solar(time_series=series, local_file=local_file, study_path=self.config.study_path, area_id=area.id)
self._write_timeseries(series, TimeSeriesFileType.SOLAR, area.id)
PreproFolder.SOLAR.save(self.config.study_path, area.id)
return Solar(time_series=series)

def create_misc_gen(self, area: Area, series: Optional[pd.DataFrame]) -> MiscGen:
series = series if series is not None else pd.DataFrame([])
local_file = TimeSeriesFile(
TimeSeriesFileType.MISC_GEN, self.config.study_path, area_id=area.id, time_series=series
)
return MiscGen(series, local_file)
self._write_timeseries(series, TimeSeriesFileType.MISC_GEN, area.id)
return MiscGen(series)

def create_hydro(
self,
Expand Down
14 changes: 4 additions & 10 deletions src/antares/service/local_services/binding_constraint_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
)
from antares.service.base_services import BaseBindingConstraintService
from antares.tools.ini_tool import IniFile, IniFileTypes
from antares.tools.time_series_tool import TimeSeries, TimeSeriesFile, TimeSeriesFileType
from antares.tools.matrix_tool import df_save
from antares.tools.time_series_tool import TimeSeriesFileType


class BindingConstraintLocalService(BaseBindingConstraintService):
Expand All @@ -35,7 +36,6 @@ def __init__(self, config: LocalConfiguration, study_name: str, **kwargs: Any) -
self.config = config
self.study_name = study_name
self.ini_file = IniFile(self.config.study_path, IniFileTypes.BINDING_CONSTRAINTS_INI)
self._time_series: dict[str, TimeSeries] = {}
self.binding_constraints = {}

def create_binding_constraint(
Expand Down Expand Up @@ -90,10 +90,8 @@ def _store_time_series(
file_types = [TimeSeriesFileType.BINDING_CONSTRAINT_EQUAL]

for ts, ts_id, file_type in zip(time_series, time_series_ids, file_types):
self._time_series[ts_id] = TimeSeries(
ts,
TimeSeriesFile(file_type, self.config.study_path, constraint_id=constraint.id.lower(), time_series=ts),
)
matrix_path = self.config.study_path.joinpath(file_type.value.format(constraint_id=constraint.id))
df_save(ts, matrix_path)

@staticmethod
def _check_if_empty_ts(time_step: BindingConstraintFrequency, time_series: Optional[pd.DataFrame]) -> pd.DataFrame:
Expand All @@ -108,10 +106,6 @@ def _write_binding_constraint_ini(self) -> None:
self.ini_file.ini_dict = binding_constraints_ini_content
self.ini_file.write_ini_file()

@property
def time_series(self) -> dict[str, TimeSeries]:
return self._time_series

def add_constraint_terms(self, constraint: BindingConstraint, terms: list[ConstraintTerm]) -> list[ConstraintTerm]:
new_terms = constraint.local_properties.terms | {
term.id: term for term in terms if term.id not in constraint.get_terms()
Expand Down
Loading

0 comments on commit 46ad93c

Please sign in to comment.