Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/readfiles
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/antares/model/area.py
#	src/antares/model/binding_constraint.py
#	src/antares/model/cluster.py
#	src/antares/model/hydro.py
#	src/antares/model/link.py
#	src/antares/model/renewable.py
#	src/antares/model/settings/__init__.py
#	src/antares/model/solar.py
#	src/antares/model/st_storage.py
#	src/antares/model/study.py
#	src/antares/model/thermal.py
#	src/antares/model/wind.py
#	src/antares/service/api_services/area_api.py
#	src/antares/service/api_services/binding_constraint_api.py
#	src/antares/service/api_services/link_api.py
#	src/antares/service/api_services/renewable_api.py
#	src/antares/service/api_services/st_storage_api.py
#	src/antares/service/api_services/study_api.py
#	src/antares/service/api_services/thermal_api.py
#	src/antares/service/base_services.py
#	src/antares/service/local_services/area_local.py
#	src/antares/service/local_services/binding_constraint_local.py
#	src/antares/service/local_services/link_local.py
#	src/antares/service/local_services/renewable_local.py
#	src/antares/service/local_services/st_storage_local.py
#	src/antares/service/local_services/study_local.py
#	src/antares/service/local_services/thermal_local.py
#	src/antares/tools/contents_tool.py
#	src/antares/tools/ini_tool.py
#	src/antares/tools/time_series_tool.py
#	tests/antares/services/api_services/test_area_api.py
#	tests/antares/services/api_services/test_binding_constraint_api.py
#	tests/antares/services/api_services/test_link_api.py
#	tests/antares/services/api_services/test_renewable_api.py
#	tests/antares/services/api_services/test_st_storage_api.py
#	tests/antares/services/api_services/test_study_api.py
#	tests/antares/services/api_services/test_thermal_api.py
#	tests/antares/services/local_services/conftest.py
#	tests/antares/services/local_services/test_area.py
#	tests/antares/services/local_services/test_study.py
#	tests/antares/tools/conftest.py
#	tests/antares/tools/test_time_series_tool.py

merge master
  • Loading branch information
killian-scalian committed Oct 14, 2024
2 parents cc8d783 + 3643b47 commit 36069c9
Show file tree
Hide file tree
Showing 62 changed files with 3,466 additions and 2,384 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/license_header.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: check license headers
on:
push:
branches:
- "**"

jobs:
check-license-headers:
runs-on: ubuntu-20.04
steps:
- name: Checkout github repo (+ download lfs dependencies)
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install click
- name: Check licenses header
run: |
python license_checker_and_adder.py --path=../src/ --action=check-strict
python license_checker_and_adder.py --path=../tests/ --action=check-strict
working-directory: scripts
4 changes: 3 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
-r requirements.txt
mypy~=1.10.0
ruff==0.4.7
ruff~=0.4.7
pytest-cov~=5.0.0
requests-mock~=1.12.1
types-requests~=2.27.1
tox~=4.18.1
tox-uv~=1.11.3
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
absl-py==1.4.0
numpy==1.24.4
protobuf==4.23.3
absl-py~=1.4.0
numpy~=1.26.4
requests~=2.31.0
pandas ~=2.2.2
pandas-stubs ~=2.2.2
pandas~=2.2.2
pandas-stubs~=2.2.2
pytest~=7.2.1
python-dateutil~=2.9.0
pydantic==2.7.1
configparser~=5.0.2
pydantic~=2.7.1
configparser~=5.0.2
click~=8.1.7
115 changes: 115 additions & 0 deletions scripts/license_checker_and_adder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import os
import re
from pathlib import Path
from typing import List

import click

# Use to skip subtrees that have their own licenses (forks)
LICENSE_FILE_PATTERN = re.compile("LICENSE.*")

LICENSE_HEADER = """# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
"""


def is_license_file(filename: str) -> bool:
return LICENSE_FILE_PATTERN.match(filename) is not None


def check_file(file_path: Path, action: str) -> bool:
file_content = file_path.read_text().splitlines()
license_as_list = LICENSE_HEADER.splitlines()
license_to_save = [header + "\n" for header in license_as_list] + ["\n"]
n = len(license_as_list)
if len(file_content) >= n and file_content[:n] == license_as_list:
return True
click.echo(f"{file_path} has no valid header.")
new_lines = []
if action == "fix":
with open(file_path, "r") as f: # doesn't seem really optimal as I read the file twice.
already_licensed = False
lines = f.readlines()
first_line = lines[0].lower() if len(lines) > 0 else []
if "copyright" in first_line or "license" in first_line: # assumes license follows this
already_licensed = True
if already_licensed: # I don't really know what to do here
raise ValueError(f"File {file_path} already licensed.")
else:
new_lines = license_to_save + lines
if new_lines:
with open(file_path, "w") as f:
f.writelines(new_lines)


def check_dir(cwd: Path, dir_path: Path, action: str, invalid_files: List[Path]) -> None:
_, dirnames, filenames = next(os.walk(dir_path))
for f in filenames:
if dir_path != cwd and is_license_file(f):
click.echo(f"Found third party license file, skipping folder: {dir_path / f}")
return

for f in filenames:
file_path = dir_path / f

if file_path.suffix not in [".py"]:
continue

if not check_file(file_path, action):
invalid_files.append(file_path)

for d in dirnames:
check_dir(cwd, dir_path / d, action, invalid_files)


@click.command("license_checker_and_adder")
@click.option(
"--path",
nargs=1,
required=True,
type=click.Path(exists=True, path_type=Path),
help="Path to check",
)
@click.option(
"--action",
nargs=1,
required=False,
default="check",
type=str,
help="Action to realise. Can either be check or fix",
)
def cli(path: Path, action: str) -> None:
if action not in ["check", "check-strict", "fix"]:
raise ValueError(f"Parameter --action should be 'check', 'check-strict' or 'fix' and was '{action}'")

invalid_files = []
cwd = Path.cwd()
check_dir(cwd, path, action, invalid_files)
file_count = len(invalid_files)
if file_count > 0:
if action == "fix":
click.echo(f"{file_count} files have been fixed")
else:
click.echo(f"{file_count} files have an invalid header. Use --action=fix to fix them")
if action == "check-strict":
raise ValueError("Some files have invalid headers")

else:
click.echo("All good !")


def main():
cli(prog_name="cli")


if __name__ == "__main__":
main()
12 changes: 12 additions & 0 deletions src/antares/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

12 changes: 12 additions & 0 deletions src/antares/api_conf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

12 changes: 12 additions & 0 deletions src/antares/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

12 changes: 12 additions & 0 deletions src/antares/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

12 changes: 12 additions & 0 deletions src/antares/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

Loading

0 comments on commit 36069c9

Please sign in to comment.