Skip to content

Commit

Permalink
build(lint): use ruff instead of isort and black (#2349)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle authored Feb 19, 2025
1 parent 7635337 commit c428a2a
Show file tree
Hide file tree
Showing 93 changed files with 225 additions and 369 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- uses: isort/[email protected]
with:
sort-paths: antarest, tests
requirementsFiles: "requirements-dev.txt"
- name: Check with black
uses: psf/black@stable
with:
# Version of Black should match the versions set in `requirements-dev.txt`
version: "~=25.1.0"
options: --check --diff
- name: Check format (ruff)
run: |
ruff check antarest/ tests/
ruff format --check antarest/ tests/
- name: Check Typing (mypy)
#continue-on-error: true
run: |
Expand Down
1 change: 1 addition & 0 deletions antarest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
This module contains the project metadata.
"""

from pathlib import Path

# Standard project metadata
Expand Down
1 change: 1 addition & 0 deletions antarest/core/filesystem_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""
Filesystem Blueprint
"""

import asyncio
import datetime
import os
Expand Down
4 changes: 2 additions & 2 deletions antarest/core/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
from io import StringIO
from pathlib import Path

from sqlalchemy.orm import declarative_base # type: ignore

from alembic import command
from alembic.config import Config
from alembic.util import CommandError
from sqlalchemy.orm import declarative_base # type: ignore

from antarest.core.utils.utils import get_local_path

logger = logging.getLogger(__name__)
Expand Down
1 change: 0 additions & 1 deletion antarest/core/serde/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
This modules hosts technical components related to serializing and deserializing,
for various formats: INI, JSON, ...
"""
import typing as t

import pydantic

Expand Down
2 changes: 1 addition & 1 deletion antarest/core/utils/fastapi_sqlalchemy/middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from contextvars import ContextVar, Token
from typing import Any, Dict, Optional, Type, Union

from sqlalchemy import create_engine, event # type: ignore
from sqlalchemy import create_engine # type: ignore
from sqlalchemy.engine import Engine # type: ignore
from sqlalchemy.engine.url import URL # type: ignore
from sqlalchemy.event import listen # type: ignore
Expand Down
1 change: 1 addition & 0 deletions antarest/core/version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""
Python module that is dedicated to printing application version and dependencies information
"""

import subprocess
import sys
from pathlib import Path
Expand Down
24 changes: 0 additions & 24 deletions antarest/dbmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,7 @@
#
# This file is part of the Antares project.

# noinspection PyUnresolvedReferences
from antarest.core.configdata import model as configdatamodel

# noinspection PyUnresolvedReferences
from antarest.core.filetransfer import model as filetransfermodel

# noinspection PyUnresolvedReferences
from antarest.core.persistence import Base as PersistenceBase

# noinspection PyUnresolvedReferences
from antarest.core.tasks import model as tasksmodel

# noinspection PyUnresolvedReferences
from antarest.launcher import model as launchermodel

# noinspection PyUnresolvedReferences
from antarest.login import model as loginmodel

# noinspection PyUnresolvedReferences
from antarest.matrixstore import model as matrixstoremodel

# noinspection PyUnresolvedReferences
from antarest.study import model as studymodel

# noinspection PyUnresolvedReferences
from antarest.study.storage.variantstudy.model import dbmodel as variantmodel

Base = PersistenceBase
1 change: 0 additions & 1 deletion antarest/eventbus/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import dataclasses
import logging
import pathlib
from enum import StrEnum
from http import HTTPStatus
from typing import List, Optional
Expand Down
7 changes: 1 addition & 6 deletions antarest/launcher/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,7 @@ def __str__(self) -> str:

@override
def __repr__(self) -> str:
return (
f"<JobLog(id={self.id!r},"
f" message={self.message!r},"
f" job_id={self.job_id!r},"
f" log_type={self.log_type!r})>"
)
return f"<JobLog(id={self.id!r}, message={self.message!r}, job_id={self.job_id!r}, log_type={self.log_type!r})>"


class JobResult(Base): # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion antarest/launcher/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_all(self, filter_orphan: bool = False, latest: Optional[int] = None) ->
return job_results

def get_running(self) -> List[JobResult]:
query = db.session.query(JobResult).where(JobResult.completion_date == None)
query = db.session.query(JobResult).where(JobResult.completion_date == None) # noqa: E711
job_results: List[JobResult] = query.all()
return job_results

Expand Down
5 changes: 1 addition & 4 deletions antarest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,7 @@ def home(request: Request) -> Any:
LOGGING_CONFIG["formatters"]["default"]["fmt"] = "[%(asctime)s] [%(process)s] %(levelprefix)s %(message)s"
# noinspection SpellCheckingInspection
LOGGING_CONFIG["formatters"]["access"]["fmt"] = (
"[%(asctime)s] [%(process)s] [%(name)s]"
" %(levelprefix)s"
' %(client_addr)s - "%(request_line)s"'
" %(status_code)s"
'[%(asctime)s] [%(process)s] [%(name)s] %(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s'
)


Expand Down
3 changes: 0 additions & 3 deletions antarest/service_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
from typing import Any, Dict, Mapping, Optional, Tuple

import redis
from ratelimit import RateLimitMiddleware # type: ignore
from ratelimit.backends.redis import RedisBackend # type: ignore
from ratelimit.backends.simple import MemoryBackend # type: ignore
from sqlalchemy import create_engine # type: ignore
from sqlalchemy.engine.base import Engine # type: ignore
from sqlalchemy.pool import NullPool # type: ignore
Expand Down
1 change: 0 additions & 1 deletion antarest/study/business/area_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ def update_area_metadata(
)

def update_area_ui(self, study: StudyInterface, area_id: str, area_ui: UpdateAreaUi, layer: str) -> None:

command = UpdateAreaUI(
area_id=area_id,
area_ui=area_ui,
Expand Down
1 change: 0 additions & 1 deletion antarest/study/business/areas/renewable_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
create_renewable_config,
create_renewable_properties,
)
from antarest.study.storage.storage_service import StudyStorageService
from antarest.study.storage.variantstudy.model.command.create_renewables_cluster import CreateRenewablesCluster
from antarest.study.storage.variantstudy.model.command.remove_renewables_cluster import RemoveRenewablesCluster
from antarest.study.storage.variantstudy.model.command.replace_matrix import ReplaceMatrix
Expand Down
5 changes: 3 additions & 2 deletions antarest/study/business/binding_constraint_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def _get_references_by_widths(
)
for matrix_name in matrices_name:
matrix_id = matrix_name.format(bc_id=bc.id)
logger.info(f"⏲ Validating BC '{bc.id}': {matrix_id=} [{_index+1}/{_total}]")
logger.info(f"⏲ Validating BC '{bc.id}': {matrix_id=} [{_index + 1}/{_total}]")
obj = file_study.tree.get(url=["input", "bindingconstraints", matrix_id])
matrix = np.array(obj["data"], dtype=float)
# We ignore empty matrices as there are default matrices for the simulator.
Expand Down Expand Up @@ -904,8 +904,9 @@ def update_binding_constraint(
updated_matrices = [term for term in [m.value for m in TermMatrices] if getattr(data, term)]
if updated_matrices:
time_step = data.time_step or existing_constraint.time_step
assert time_step is not None
command.validates_and_fills_matrices(
time_step=time_step, specific_matrices=updated_matrices, version=study.version, create=False # type: ignore
time_step=time_step, specific_matrices=updated_matrices, version=study.version, create=False
)

study.add_commands([command])
Expand Down
1 change: 1 addition & 0 deletions antarest/study/business/correlation_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Management of spatial correlations between the different generators.
The generators are of the same category and can be hydraulic, wind, load or solar.
"""

import collections
from typing import Dict, List, Sequence, Union

Expand Down
1 change: 0 additions & 1 deletion antarest/study/business/scenario_builder_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def get_config(self, study: StudyInterface) -> Rulesets:
return rulesets

def update_config(self, study: StudyInterface, rulesets: Rulesets) -> None:

sections: _Sections = {}
for ruleset_name, ruleset in rulesets.items():
section = sections[ruleset_name] = {}
Expand Down
1 change: 0 additions & 1 deletion antarest/study/business/study_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#
# This file is part of the Antares project.
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Sequence

from antares.study.version import StudyVersion
Expand Down
4 changes: 2 additions & 2 deletions antarest/study/business/thematic_trimming_field_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class ThematicTrimmingFormFields(FormFieldsBaseModel):
_SHORT_TERM_STORAGES = "Short-Term Storages"
_SHORT_TERM_STORAGES_GROUP = "Short-Term Storages - Group"

# fmt: off
FIELDS_INFO: Mapping[str, Mapping[str, Any]] = {
# fmt: off
"ov_cost": {"topic": _GENERAL, "path": "OV. COST", "default_value": True},
"op_cost": {"topic": _GENERAL, "path": "OP. COST", "default_value": True},
"mrg_price": {"topic": _GENERAL, "path": "MRG. PRICE", "default_value": True},
Expand Down Expand Up @@ -237,8 +237,8 @@ class ThematicTrimmingFormFields(FormFieldsBaseModel):
"other5_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_injection", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other5_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other5_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_level", "default_value": True, "start_version": STUDY_VERSION_8_6},
# fmt: on
}
# fmt: on


def get_fields_info(study_version: StudyVersion) -> Mapping[str, Mapping[str, Any]]:
Expand Down
3 changes: 1 addition & 2 deletions antarest/study/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
PrimaryKeyConstraint,
String,
)
from sqlalchemy.orm import relationship # type: ignore
from sqlalchemy.orm import validates
from sqlalchemy.orm import relationship, validates # type: ignore
from typing_extensions import override

from antarest.core.exceptions import ShouldNotHappenException
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import time
from datetime import datetime, timedelta
from pathlib import Path, PurePosixPath
from typing import Any, BinaryIO, Callable, Dict, List, MutableSequence, Optional, Sequence, Tuple, Type, cast
from typing import Any, BinaryIO, Callable, Dict, List, Optional, Sequence, Tuple, Type, cast
from uuid import uuid4

import numpy as np
Expand Down
6 changes: 6 additions & 0 deletions antarest/study/storage/df_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
from antarest.core.jwt import JWTUser
from antarest.study.business.enum_ignore_case import EnumIgnoreCase

try:
import tables # type: ignore # noqa: F401
import xlsxwriter # type: ignore # noqa: F401
except ImportError:
raise ImportError("The 'xlsxwriter' and 'tables' packages are required") from None


class TableExportFormat(EnumIgnoreCase):
"""Export format for tables."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
import re
from typing import Annotated, Any, List, Mapping, MutableMapping

from pydantic import BeforeValidator, Field
Expand Down
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 Any, Dict, Type, Union
from typing import Any, Dict, Type

from antares.study.version import StudyVersion
from pydantic import Field
Expand Down
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 Any, Dict, Optional, Type, Union, cast
from typing import Any, Dict, Optional, Type, cast

from antares.study.version import StudyVersion
from pydantic import Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import numpy as np
import pandas as pd
from numpy import typing as npt
from typing_extensions import override

from antarest.core.model import JSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get(
lines = extract_lines_from_archive(self.config.archive_path, AREAS_LIST_RELATIVE_PATH)
else:
lines = self.config.path.read_text().split("\n")
return [l.strip() for l in lines if l.strip()]
return [line.strip() for line in lines if line.strip()]

@override
def save(self, data: List[str], url: Optional[List[str]] = None) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _populate_thermal_rules(self, rules: _Rules) -> None:

def _populate_renewable_rules(self, rules: _Rules) -> None:
for area_id in self.config.areas:
for cl_id in (re.lower() for re in self.config.get_renewable_ids(area_id)):
for cl_id in (renew.lower() for renew in self.config.get_renewable_ids(area_id)):
rules[f"r,{area_id},0,{cl_id}"] = _TSNumber

def _populate_binding_constraints_rules(self, rules: _Rules) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
# This file is part of the Antares project.

from . import binding_constraint, hydro, link, prepro, st_storage, thermals

__all__ = ("binding_constraint", "hydro", "link", "prepro", "st_storage", "thermals")
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
# This file is part of the Antares project.

from . import v6, v7

__all__ = ("v6", "v7")
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
# This file is part of the Antares project.

from . import v7, v8

__all__ = ("v7", "v8")
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
#
# This file is part of the Antares project.

from . import series
from . import series # noqa: F401
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
#
# This file is part of the Antares project.

from . import prepro
from . import prepro # noqa: F401
1 change: 0 additions & 1 deletion antarest/study/storage/variantstudy/command_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from antarest.core.model import JSON
from antarest.matrixstore.service import ISimpleMatrixService
from antarest.study.storage.patch_service import PatchService
from antarest.study.storage.variantstudy.business.matrix_constants_generator import GeneratorMatrixConstants
from antarest.study.storage.variantstudy.model.command.common import CommandName
from antarest.study.storage.variantstudy.model.command.create_area import CreateArea
Expand Down
12 changes: 6 additions & 6 deletions antarest/study/storage/variantstudy/model/command/create_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ def _apply(self, study_data: FileStudy, listener: Optional[ICommandListener] = N
hydro_config.setdefault("leeway up", {})[area_id] = 1
hydro_config.setdefault("pumping efficiency", {})[area_id] = 1

new_area_data["input"]["hydro"]["common"]["capacity"][
f"creditmodulations_{area_id}"
] = self.command_context.generator_matrix_constants.get_hydro_credit_modulations()
new_area_data["input"]["hydro"]["common"]["capacity"][
f"inflowPattern_{area_id}"
] = self.command_context.generator_matrix_constants.get_hydro_inflow_pattern()
new_area_data["input"]["hydro"]["common"]["capacity"][f"creditmodulations_{area_id}"] = (
self.command_context.generator_matrix_constants.get_hydro_credit_modulations()
)
new_area_data["input"]["hydro"]["common"]["capacity"][f"inflowPattern_{area_id}"] = (
self.command_context.generator_matrix_constants.get_hydro_inflow_pattern()
)
new_area_data["input"]["hydro"]["common"]["capacity"][f"waterValues_{area_id}"] = null_matrix

has_renewables = version >= STUDY_VERSION_8_1 and EnrModelling(config.enr_modelling) == EnrModelling.CLUSTERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# This file is part of the Antares project.
import typing as t
from typing import Any, ClassVar, Dict, Final, List, Optional, Tuple
from typing import Any, Dict, Final, List, Optional, Tuple

from pydantic import Field, model_validator
from pydantic_core.core_schema import ValidationInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig
from antarest.study.storage.rawstudy.model.filesystem.factory import FileStudy
from antarest.study.storage.variantstudy.model.command.common import CommandName, CommandOutput
from antarest.study.storage.variantstudy.model.command.icommand import MATCH_SIGNATURE_SEPARATOR, ICommand
from antarest.study.storage.variantstudy.model.command.icommand import ICommand
from antarest.study.storage.variantstudy.model.command_listener.command_listener import ICommandListener
from antarest.study.storage.variantstudy.model.model import CommandDTO

Expand Down
Loading

0 comments on commit c428a2a

Please sign in to comment.