Skip to content

Commit e830baf

Browse files
authored
Merge pull request #2 from interTwin-eu/cleanup-plugin
Fix issue with installation of plugin subpackages
2 parents 8e98c80 + d8da3b8 commit e830baf

25 files changed

+311
-219
lines changed

.github/linters/.ruff.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
line-length = 95
2+
3+
[lint]
4+
select = ["E", "F", "I"]
5+
ignore = ["E203"]
6+
7+
[format]
8+
quote-style = "double"
9+
indent-style = "space"
10+
skip-magic-trailing-comma = false
11+
line-ending = "auto"

.github/workflows/lint.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ jobs:
1010
name: Lint with Super-Linter
1111
runs-on: ubuntu-latest
1212

13+
############################################
14+
# Grant status permission for MULTI_STATUS #
15+
############################################
16+
permissions:
17+
contents: read
18+
packages: read
19+
statuses: write
20+
1321
steps:
1422
# Checks out a copy of your repository on the ubuntu-latest machine
1523
- name: Checkout code
@@ -22,12 +30,20 @@ jobs:
2230

2331
# Runs the Super-Linter action
2432
- name: Run Super-Linter on new changes
25-
uses: docker://ghcr.io/github/super-linter:slim-v4
33+
uses: github/super-linter/slim@v7
2634
env:
2735
DEFAULT_BRANCH: main
2836
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2937
MARKDOWN_CONFIG_FILE: .markdownlint.json
38+
PYTHON_RUFF_CONFIG_FILE: .ruff.toml
3039
# Only check new or edited files
3140
VALIDATE_ALL_CODEBASE: false
3241
# Fail on errors
3342
DISABLE_ERRORS: false
43+
# Both options below should be already covered by ruff
44+
VALIDATE_PYTHON_ISORT: false
45+
VALIDATE_PYTHON_FLAKE8: false
46+
VALIDATE_PYTHON_BLACK: false
47+
VALIDATE_PYTHON_MYPY: false
48+
VALIDATE_PYTHON_PYLINT: false
49+
VALIDATE_PYTHON_PYINK: false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
uv.lock
2+
13
# Byte-compiled / optimized / DLL files
24
__pycache__/
35
*.py[cod]

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"charliermarsh.ruff",
4+
"ms-python.python",
5+
"ms-python.vscode-pylance"
6+
]
7+
}

.vscode/settings.json

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
{
2-
"markdownlint.config": {
3-
"MD013": {
4-
"line_length": 120,
5-
"code_blocks": false,
6-
"tables": false
7-
},
8-
"MD014": false,
9-
"MD024": false,
10-
"MD026": {
11-
"punctuation": ".,:;!"
12-
}
2+
"markdownlint.config": {
3+
"MD013": {
4+
"line_length": 120,
5+
"code_blocks": false,
6+
"tables": false
7+
},
8+
"MD014": false,
9+
"MD024": false,
10+
"MD026": {
11+
"punctuation": ".,:;!"
1312
}
13+
},
14+
"[python]": {
15+
"editor.formatOnSave": true,
16+
"editor.codeActionsOnSave": {
17+
"source.fixAll": "explicit"
18+
}
19+
},
20+
"ruff.organizeImports": true,
21+
"ruff.fixAll": true,
22+
"editor.formatOnSave": true,
1423
}

src/itwinai/plugins/xtclim/pipeline.yaml renamed to pipeline.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ pipeline:
1212
init_args:
1313
steps:
1414
preprocessing-step:
15-
class_path: itwinai.plugins.xtclim.preprocess_functions_2d_ssp.PreprocessData
15+
class_path: itwinai.plugins.xtclim.preprocessing.preprocess_functions_2d_ssp.PreprocessData
1616
init_args:
1717
dataset_root: ${dataset_root}
1818
scenario: ${scenario}
1919
preprocessing-split-step:
20-
class_path: itwinai.plugins.xtclim.preprocess_2d_seasons.SplitPreprocessedData
20+
class_path: itwinai.plugins.xtclim.preprocessing.preprocess_2d_seasons.SplitPreprocessedData
2121
init_args:
2222
scenario: ${scenario}
2323
training-step:
2424
#class_path: src.trainer_dist.XTClimTrainer
25-
class_path: itwinai.plugins.xtclim.trainer.TorchTrainer
25+
class_path: itwinai.plugins.xtclim.src.trainer.TorchTrainer
2626
init_args:
2727
epochs: ${epochs}
2828
batch_size: ${batch_size}

pyproject.toml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "itwinai-xtclim-plugin"
77
version = "0.1.0"
8+
requires-python = ">=3.10"
89
description = "xtclim plugin for itwinai"
910
authors = [{ name = "Christian Page", email = "[email protected]" }]
1011
dependencies = [
@@ -26,12 +27,33 @@ dependencies = [
2627
"xarray",
2728
"netCDF4",
2829
"h5netcdf",
30+
"ruff>=0.9.6",
2931
]
3032

3133
[tool.setuptools.packages.find]
3234
# Declare this package as part of the `itwinai.plugins` namespace
3335
where = ["src"]
34-
include = ["itwinai.plugins.xtclim"]
36+
# Add plugin subfolders explicitly here
37+
include = [
38+
"itwinai.plugins.xtclim",
39+
"itwinai.plugins.xtclim.src",
40+
"itwinai.plugins.xtclim.preprocessing",
41+
]
3542

3643
[tool.setuptools.package-data]
3744
"*" = ["*.json", "*.yaml", "*.ipynb"]
45+
46+
# Ruff configuration: https://docs.astral.sh/ruff/configuration/
47+
[tool.ruff]
48+
line-length = 95
49+
50+
[tool.ruff.lint]
51+
select = ["E", "F", "I", "W"]
52+
ignore = ["E203"]
53+
fixable = ["ALL"]
54+
55+
[tool.ruff.format]
56+
quote-style = "double"
57+
indent-style = "space"
58+
skip-magic-trailing-comma = false
59+
line-ending = "auto"

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
extend-ignore = E203,W503
3+
max-line-length = 95
4+
exclude = .git,__pycache__,docs/conf.py,use-cases,tutorials,tests,old,build,dist,.venv*,envAI*,env-files,.vscode

src/itwinai/plugins/xtclim/preprocessing/__init__.py

Whitespace-only changes.

src/itwinai/plugins/xtclim/preprocess_2d_seasons.py renamed to src/itwinai/plugins/xtclim/preprocessing/preprocess_2d_seasons.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@
1010

1111
# #### 0. Libraries
1212

13+
import configparser as cp
14+
1315
import numpy as np
1416
import pandas as pd
15-
import configparser as cp
1617

1718
from itwinai.components import DataGetter, monitor_exec
1819

20+
1921
class SplitPreprocessedData(DataGetter):
20-
def __init__(
21-
self,
22-
scenario: str
23-
):
22+
def __init__(self, scenario: str):
2423
super().__init__()
2524
self.scenario = scenario
2625

27-
##### 2. Split Yearly Data into Four Seasonal Datasets
26+
# #### 2. Split Yearly Data into Four Seasonal Datasets
2827
# split daily data into seasons
2928
def season_split(
3029
self,
@@ -103,17 +102,17 @@ def season_split(
103102

104103
@monitor_exec
105104
def execute(self):
106-
#### Configuration file
105+
# ### Configuration file
107106
config = cp.ConfigParser()
108-
config.read('xtclim.json')
107+
config.read("xtclim.json")
109108

110-
##### 1. Load Data to xarray
109+
# #### 1. Load Data to xarray
111110

112111
# choose the needed number of members
113-
n_memb = config.get('TRAIN', 'n_memb')
112+
n_memb = config.get("TRAIN", "n_memb")
114113

115114
# define relevant scenarios
116-
#scenarios = ["126", "245", "370", "585"]
115+
# scenarios = ["126", "245", "370", "585"]
117116
scenarios = [self.scenario]
118117
# Load preprocessed "daily temperature images" and time series
119118

@@ -122,8 +121,7 @@ def execute(self):
122121
train_time = pd.read_csv("input/dates_train_data.csv")
123122
test_time = pd.read_csv("input/dates_test_data.csv")
124123

125-
126-
##### 3. Apply to Train and Test Datasets
124+
# #### 3. Apply to Train and Test Datasets
127125
train_season_images, train_season_time = self.season_split(
128126
train_images, train_time, "train", n_memb
129127
)
@@ -132,8 +130,7 @@ def execute(self):
132130
test_images, test_time, "test", n_memb
133131
)
134132

135-
136-
##### 4. Apply to Projection Datasets
133+
# #### 4. Apply to Projection Datasets
137134

138135
for scenario in scenarios:
139136
proj_images = np.load(f"input/preprocessed_2d_proj{scenario}_data_allssp.npy")

src/itwinai/plugins/xtclim/preprocess_3d_seasons.py renamed to src/itwinai/plugins/xtclim/preprocessing/preprocess_3d_seasons.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@
1010

1111
# #### 0. Libraries
1212

13+
import configparser as cp
14+
import json
15+
1316
import numpy as np
1417
import pandas as pd
15-
import configparser as cp
1618

17-
#### Configuration file
19+
# #### Configuration file
1820
config = cp.ConfigParser()
19-
config.read('xtclim.json')
21+
config.read("xtclim.json")
2022

2123
# #### 1. Load Data to xarray
2224

2325
# choose the needed number of members
24-
n_memb = config.getint('TRAIN', 'n_memb')
26+
n_memb = config.getint("TRAIN", "n_memb")
2527

2628
# define relevant scenarios
27-
#scenarios = ["126", "245", "370", "585"]
28-
scenarios = json.loads(config.getint('GENERAL', 'scenarios'))
29+
# scenarios = ["126", "245", "370", "585"]
30+
scenarios = json.loads(config.getint("GENERAL", "scenarios"))
2931

3032
# Load preprocessed "daily temperature images" and time series
3133

@@ -122,9 +124,7 @@ def season_split(
122124
)
123125

124126

125-
test_season_images, test_season_time = season_split(
126-
test_images, test_time, "test", n_memb
127-
)
127+
test_season_images, test_season_time = season_split(test_images, test_time, "test", n_memb)
128128

129129

130130
# #### 4. Apply to Projection Datasets

0 commit comments

Comments
 (0)