Skip to content

Commit 4793d2e

Browse files
committed
Update .pre-commit-config and apply ruff-format and eslint rules
1 parent c7d3226 commit 4793d2e

23 files changed

Lines changed: 270 additions & 131 deletions

.pre-commit-config.yaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
1-
exclude: assets\/
2-
31
repos:
2+
- repo: meta
3+
hooks:
4+
- id: check-hooks-apply
5+
46
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.5.0
7+
rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0
68
hooks:
79
- id: check-ast
810
- id: check-json
911
- id: check-yaml
1012
- id: end-of-file-fixer
1113
- id: trailing-whitespace
1214
- id: debug-statements
15+
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: c60c980e561ed3e73101667fe8365c609d19a438 # frozen: v0.15.9
18+
hooks:
19+
- id: ruff-check
20+
args: [--fix, --exit-non-zero-on-fix]
21+
- id: ruff-format
22+
23+
- repo: https://github.com/pre-commit/mirrors-eslint
24+
rev: d72e5408a82df0b0cb6b9c878fb8cb4e947c1859 # frozen: v10.2.0
25+
hooks:
26+
- id: eslint
27+
args: [--fix, --color]
28+
additional_dependencies:
29+
- eslint@9.39.4
30+
- eslint-plugin-react@7.37.5
31+
- eslint-plugin-simple-import-sort@12.1.1
32+
- react@18.3.1
33+
34+
- repo: https://github.com/crate-ci/typos
35+
rev: f06b85043a5ab470afbb0a5592456e733243983a # frozen: v1
36+
hooks:
37+
- id: typos

.ruff.toml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
target-version = "py310"
2+
line-length = 120
3+
4+
[lint]
5+
select = [
6+
"B", # flake8-bugbear
7+
"C4", # flake8-comprehensions
8+
"E", # pycodestyle
9+
"F", # pyflakes
10+
"I", # isort
11+
"PGH", # pygrep-hooks
12+
"RUF", # ruff
13+
"UP", # pyupgrade
14+
"W", # pycodestyle
15+
"YTT", # flake8-2020
16+
]
17+
18+
[format]
19+
quote-style = "single"
20+
21+
[lint.isort]
22+
known-first-party = [
23+
"isimip_data"
24+
]
25+
section-order = [
26+
"future",
27+
"standard-library",
28+
"pytest",
29+
"django",
30+
"rest_framework",
31+
"third-party",
32+
"first-party",
33+
"local-folder"
34+
]
35+
36+
[lint.isort.sections]
37+
pytest = ["pytest"]
38+
django = ["django"]
39+
rest_framework = ["rest_framework"]
40+
41+
[lint.per-file-ignores]
42+
"config/settings/*.py" = [
43+
"F401",
44+
"F403",
45+
"F405",
46+
"F821",
47+
]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ The definition YAML files however can be changed without touching the JavaScript
121121
...
122122
```
123123

124-
Here `1850soc` only applies to the givem set of sectors and only to `ISIMIP3b`, while `histsoc` is used both in `ISIMIP3a` and `ISIMIP3b` and in every sector. Some attributes (e.g. `frequency` in `definitions/variable`) can have objects as value, which the are evaluated for the particular sector.
124+
Here `1850soc` only applies to the given set of sectors and only to `ISIMIP3b`, while `histsoc` is used both in `ISIMIP3a` and `ISIMIP3b` and in every sector. Some attributes (e.g. `frequency` in `definitions/variable`) can have objects as value, which the are evaluated for the particular sector.
125125

126126
In order to add a new sector, the following steps need to be taken:
127127

app/js/components/Pattern.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const Pattern = () => {
1717
.replaceAll('\\d{4}', '') // remove \d{4} etc.
1818
.replaceAll('\?P', '') // remove ?P
1919
.replaceAll('?', '') // remove ?
20-
.replaceAll('(<', '<').replaceAll('>)', '>') // remove parentesis around (< ... >)
20+
.replaceAll('(<', '<').replaceAll('>)', '>') // remove parentheses around (< ... >)
2121
.replaceAll(/>_/g, '>@').replaceAll(/_</g, '@<') // replace underscore between identifiers with @
2222
.replaceAll('_', '-') // replace remaining _ with -
2323
.replaceAll('@', '_') // replace @ with _

app/js/utils/filter.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
export const filterRows = (config, rows, group3) => {
22
if (Array.isArray(rows)) {
33
return rows.filter(row => {
4-
if (row.simulation_rounds === undefined || row.simulation_rounds.includes(config.simulation_round)) {
5-
if (row.products === undefined || row.products.filter(product => config.products.includes(product)).length) {
6-
if (row.sectors === undefined || config.sectors.length == 0 || row.sectors.filter(sector => config.sectors.includes(sector)).length) {
7-
return true
8-
}
9-
}
4+
if (row.simulation_rounds === undefined || row.simulation_rounds.includes(config.simulation_round)) {
5+
if (row.products === undefined || row.products.filter(product => config.products.includes(product)).length) {
6+
if (
7+
row.sectors === undefined ||
8+
config.sectors.length == 0 ||
9+
row.sectors.filter(sector => config.sectors.includes(sector)).length
10+
) {
11+
return true
12+
}
1013
}
14+
}
1115

12-
return false
16+
return false
1317
}).filter(row => {
1418
return row.hidden != true
1519
}).filter(row => {
@@ -34,7 +38,7 @@ export const filterField = (config, field) => {
3438
} else if (config.sectors.length == 1) {
3539
return (typeof field[config.sectors[0]] === 'undefined') ? field.other : field[config.sectors[0]]
3640
} else {
37-
return Object.fromEntries(Object.entries(field).filter(([sector, value]) => {
41+
return Object.fromEntries(Object.entries(field).filter((sector) => {
3842
if (sector == 'other') {
3943
// add the "other" entry only if there is a sector in the config which is not in the field
4044
return config.sectors.filter(s => !Object.keys(field).includes(s)).length > 0

app/js/utils/location.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ const parseLocation = () => {
2323
}
2424

2525
const simulation_round = first(tokens)
26-
if (definitions.simulation_round.map((simulation_round) => simulation_round.specifier)
27-
.includes(simulation_round)) {
26+
if (
27+
definitions.simulation_round
28+
.map((simulation_round) => simulation_round.specifier)
29+
.includes(simulation_round)
30+
) {
2831
config.simulation_round = simulation_round
2932
}
3033

3134
const sectors = tokens.slice(1)
32-
if (definitions.sector.some((sector) => sectors.includes(sector.specifier))) {
35+
if (
36+
definitions.sector
37+
.some((sector) => sectors.includes(sector.specifier))
38+
) {
3339
config.sectors = sectors
3440
}
3541

@@ -99,4 +105,4 @@ const buildPath = (config) => {
99105
return path
100106
}
101107

102-
export { parseLocation, updateLocation, parseAnchor, updateAnchor, buildPath }
108+
export { buildPath, parseAnchor, parseLocation, updateAnchor, updateLocation }

app/js/utils/ls.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,35 @@ const getConfig = () => {
55
const definitions = window.initialState.definitions
66

77
const simulation_round = ls.get('simulation_round')
8-
if (definitions.simulation_round.map((simulation_round) => simulation_round.specifier)
9-
.includes(simulation_round)) {
8+
if (
9+
definitions.simulation_round
10+
.map((simulation_round) => simulation_round.specifier)
11+
.includes(simulation_round)
12+
) {
1013
config.simulation_round = simulation_round
1114
}
1215

1316
const sectors = ls.get('sectors') ? JSON.parse(ls.get('sectors')) : []
14-
if (definitions.sector.some((sector) => sectors.includes(sector.specifier))) {
17+
if (
18+
definitions.sector
19+
.some((sector) => sectors.includes(sector.specifier))
20+
) {
1521
config.sectors = sectors
1622
}
1723

1824
const experiments = ls.get('experiments') ? JSON.parse(ls.get('experiments')) : []
19-
if (definitions.experiments.some((experiment) => experiments.includes(experiment.specifier))) {
25+
if (
26+
definitions.experiments
27+
.some((experiment) => experiments.includes(experiment.specifier))
28+
) {
2029
config.experiments = experiments
2130
}
2231

2332
const groups = ls.get('groups') ? JSON.parse(ls.get('groups')) : []
24-
if (definitions.group.some((group) => groups.includes(group.specifier))) {
33+
if (
34+
definitions.group
35+
.some((group) => groups.includes(group.specifier))
36+
) {
2537
config.groups = groups
2638
}
2739

build/csvtables.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from pathlib import Path
22

3-
from utils import filter_row, filter_rows, read_definitions, write_csv, setup_logs
3+
from utils import filter_row, filter_rows, read_definitions, setup_logs, write_csv
44

55
setup_logs()
66

7+
78
def main():
89
definitions = read_definitions()
910

@@ -23,8 +24,17 @@ def main():
2324
)
2425

2526
variable_definitions = []
26-
variable_fieldnames = ['group', 'specifier', 'long_name', 'units', 'resolution', 'frequency',
27-
'valid_min', 'valid_max', 'comment']
27+
variable_fieldnames = [
28+
'group',
29+
'specifier',
30+
'long_name',
31+
'units',
32+
'resolution',
33+
'frequency',
34+
'valid_min',
35+
'valid_max',
36+
'comment',
37+
]
2838
for row in filter_rows(definitions['variable'], simulation_round, 'OutputData', sector=sector):
2939
variable_definitions.append(filter_row(row, simulation_round, 'OutputData', sector=sector))
3040

@@ -34,5 +44,5 @@ def main():
3444
write_csv(output_path, variable_definitions, variable_fieldnames)
3545

3646

37-
if __name__ == "__main__":
47+
if __name__ == '__main__':
3848
main()

build/definitions.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from pathlib import Path
22

3-
from utils import filter_row, filter_rows, get_commit_hash, read_definitions, write_json, setup_logs
3+
from utils import filter_row, filter_rows, get_commit_hash, read_definitions, setup_logs, write_json
44

55
setup_logs()
66

7+
78
def main():
89
definitions = read_definitions()
910

@@ -16,36 +17,46 @@ def main():
1617
for product in products:
1718
if product.endswith('InputData'):
1819
for category in categories:
19-
output_path = Path('output').joinpath('definitions') \
20-
.joinpath(simulation_round).joinpath(product).joinpath(category) \
21-
.with_suffix('.json')
22-
23-
output_definitions = {
24-
'commit': get_commit_hash()
25-
}
20+
output_path = (
21+
Path('output')
22+
.joinpath('definitions')
23+
.joinpath(simulation_round)
24+
.joinpath(product)
25+
.joinpath(category)
26+
.with_suffix('.json')
27+
)
28+
29+
output_definitions = {'commit': get_commit_hash()}
2630
for definition_name, rows in definitions.items():
2731
output_definitions[definition_name] = []
2832
for row in filter_rows(rows, simulation_round, product, category=category):
29-
output_definitions[definition_name].append(filter_row(row, simulation_round, product, category=category))
33+
output_definitions[definition_name].append(
34+
filter_row(row, simulation_round, product, category=category)
35+
)
3036

3137
write_json(output_path, output_definitions)
3238

3339
else:
3440
for sector in sectors:
35-
output_path = Path('output').joinpath('definitions') \
36-
.joinpath(simulation_round).joinpath(product).joinpath(sector) \
37-
.with_suffix('.json')
38-
39-
output_definitions = {
40-
'commit': get_commit_hash()
41-
}
41+
output_path = (
42+
Path('output')
43+
.joinpath('definitions')
44+
.joinpath(simulation_round)
45+
.joinpath(product)
46+
.joinpath(sector)
47+
.with_suffix('.json')
48+
)
49+
50+
output_definitions = {'commit': get_commit_hash()}
4251
for definition_name, rows in definitions.items():
4352
output_definitions[definition_name] = []
4453
for row in filter_rows(rows, simulation_round, product, sector=sector):
45-
output_definitions[definition_name].append(filter_row(row, simulation_round, product, sector=sector))
54+
output_definitions[definition_name].append(
55+
filter_row(row, simulation_round, product, sector=sector)
56+
)
4657

4758
write_json(output_path, output_definitions)
4859

4960

50-
if __name__ == "__main__":
61+
if __name__ == '__main__':
5162
main()

build/glossary.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
setup_logs()
66

7+
78
def main():
89
glossary = {
910
'commit': get_commit_hash(),
10-
'terms': {}
11+
'terms': {},
1112
}
1213

1314
for identifier, rows in read_definitions().items():
@@ -24,5 +25,5 @@ def main():
2425
write_json(glossary_path, glossary)
2526

2627

27-
if __name__ == "__main__":
28+
if __name__ == '__main__':
2829
main()

0 commit comments

Comments
 (0)