Skip to content

Commit

Permalink
Merge branch 'dev' into feature/2547-normalize-study-path
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis SMAIL committed Jan 23, 2025
2 parents 8220f66 + a7dd4ab commit 99a5b82
Show file tree
Hide file tree
Showing 494 changed files with 7,465 additions and 11,482 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Lint Commit Messages
name: commitlint
on: [pull_request]

permissions:
contents: read
pull-requests: read

jobs:
commitlint:
commit-messages-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: 💚 Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18.16.1
node-version: 22.13.0

- name: 💚 Install dependencies
run: npm install
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: check license headers
name: license-header
on:
push:
branches:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18.16.1
node-version: 22.13.0
- name: Cache node modules
uses: actions/cache@v4
with:
Expand All @@ -92,7 +92,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18.16.1
node-version: 22.13.0
- name: Restore node modules
uses: actions/cache@v4
with:
Expand All @@ -112,7 +112,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18.16.1
node-version: 22.13.0
- name: Restore node modules
uses: actions/cache@v4
with:
Expand All @@ -132,7 +132,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18.16.1
node-version: 22.13.0
- name: Restore node modules
uses: actions/cache@v4
with:
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: pr-title
on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']

jobs:
pr-title-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: npm install @commitlint/[email protected]
- uses: JulienKode/[email protected]
5 changes: 5 additions & 0 deletions antarest/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ def __init__(self, message: str) -> None:
super().__init__(HTTPStatus.UNPROCESSABLE_ENTITY, message)


class MatrixImportFailed(HTTPException):
def __init__(self, message: str) -> None:
super().__init__(HTTPStatus.UNPROCESSABLE_ENTITY, message)


class ConstraintTermNotFound(HTTPException):
"""
Exception raised when a constraint term is not found.
Expand Down
31 changes: 17 additions & 14 deletions antarest/study/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import base64
import collections
import contextlib
import csv
import http
import io
import logging
Expand All @@ -25,6 +24,7 @@
from uuid import uuid4

import numpy as np
import numpy.typing as npt
import pandas as pd
from antares.study.version import StudyVersion
from fastapi import HTTPException, UploadFile
Expand All @@ -39,6 +39,7 @@
CommandApplicationError,
FolderCreationNotAllowed,
IncorrectPathError,
MatrixImportFailed,
NotAManagedStudyException,
OutputAlreadyArchived,
OutputAlreadyUnarchived,
Expand Down Expand Up @@ -197,6 +198,20 @@ def get_disk_usage(path: t.Union[str, Path]) -> int:
return total_size


def _imports_matrix_from_bytes(data: bytes) -> npt.NDArray[np.float64]:
"""Tries to convert bytes to a numpy array when importing a matrix"""
str_data = data.decode("utf-8")
if not str_data:
return np.zeros(shape=(0, 0))
for delimiter in [",", ";", "\t"]:
with contextlib.suppress(Exception):
df = pd.read_csv(io.BytesIO(data), delimiter=delimiter, header=None).replace(",", ".", regex=True)
df = df.dropna(axis=1, how="all") # We want to remove columns full of NaN at the import
matrix = df.to_numpy(dtype=np.float64)
return matrix
raise MatrixImportFailed("Could not parse the given matrix")


def _get_path_inside_user_folder(
path: str, exception_class: t.Type[t.Union[FolderCreationNotAllowed, ResourceDeletionNotAllowed]]
) -> str:
Expand Down Expand Up @@ -1591,19 +1606,7 @@ def _create_edit_study_command(
elif isinstance(tree_node, InputSeriesMatrix):
if isinstance(data, bytes):
# noinspection PyTypeChecker
str_data = data.decode("utf-8")
if not str_data:
matrix = np.zeros(shape=(0, 0))
else:
size_to_check = min(len(str_data), 64) # sniff a chunk only to speed up the code
try:
delimiter = csv.Sniffer().sniff(str_data[:size_to_check], delimiters=r"[,;\t]").delimiter
except csv.Error:
# Can happen with data with only one column. In this case, we don't care about the delimiter.
delimiter = "\t"
df = pd.read_csv(io.BytesIO(data), delimiter=delimiter, header=None).replace(",", ".", regex=True)
df = df.dropna(axis=1, how="all") # We want to remove columns full of NaN at the import
matrix = df.to_numpy(dtype=np.float64)
matrix = _imports_matrix_from_bytes(data)
matrix = matrix.reshape((1, 0)) if matrix.size == 0 else matrix
return ReplaceMatrix(
target=url, matrix=matrix.tolist(), command_context=context, study_version=study_version
Expand Down
11 changes: 8 additions & 3 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { RuleConfigSeverity } from "@commitlint/types";
// Config used by 'commitlint' and 'pr-title' GitHub Actions

// Config used by 'commitlint' GitHub action.
export default {
const RuleConfigSeverity = {
Disabled: 0,
Warning: 1,
Error: 2,
}

module.exports = {
extends: ["@commitlint/config-conventional"],
// Rules: https://commitlint.js.org/reference/rules.html
rules: {
Expand Down
2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ v2.15.0 (2023-09-30)

### Chore

* **github-actions:** update Node.js version to 18.16.1 [`b9988f6`](https://github.com/AntaresSimulatorTeam/AntaREST/commit/b9988f6dedc5a653de00bf5becc917487ce589e6)
* **github-actions:** update Node.js version to 22.13.0 [`b9988f6`](https://github.com/AntaresSimulatorTeam/AntaREST/commit/b9988f6dedc5a653de00bf5becc917487ce589e6)
* correct handling of base class with no `__annotations__` in `AllOptionalMetaclass` [`d9ed61f`](https://github.com/AntaresSimulatorTeam/AntaREST/commit/d9ed61fdaaa32974431b41e9cce44be09bb92e79)
* correct indentation [`4af01b4`](https://github.com/AntaresSimulatorTeam/AntaREST/commit/4af01b4023cb828093f8fd9b139f76429806c7b8)
* increase line length limit to 120 characters for Black and iSort [`586fb43`](https://github.com/AntaresSimulatorTeam/AntaREST/commit/586fb438607824899c66db66f183451fbe4a88e4)
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-guide/install/0-INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A local build allows using Antares Web as a desktop application.
Requirements:

- python : 3.11.x
- node : 18.16.1
- node : 22.13.0

Then perform the following steps:

Expand Down
Loading

0 comments on commit 99a5b82

Please sign in to comment.