Skip to content

Commit a88205a

Browse files
authored
Merge pull request #125 from ISI-MIP/dev
Refactor app, build and tests
2 parents e01788b + 5217a15 commit a88205a

277 files changed

Lines changed: 8110 additions & 9996 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
File renamed without changes.

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ __pycache__/
55
*-
66
*.swp
77
.DS_Store
8+
.Rproj.user
89
.pytest_cache
910

1011
/env
11-
/*.sh
12+
/nvm
13+
/node_modules
1214

1315
/output
14-
.Rproj.user
16+
17+
/*.sh

.nvmrc

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

.pre-commit-config.yaml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
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+
files: \.[j]sx?$ # *.js, *.jsx
29+
types: [file]
30+
additional_dependencies:
31+
- eslint@9.39.4
32+
- eslint-plugin-react@7.37.5
33+
- eslint-plugin-simple-import-sort@12.1.1
34+
- react@18.3.1
35+
36+
- repo: https://github.com/crate-ci/typos
37+
rev: f06b85043a5ab470afbb0a5592456e733243983a # frozen: v1
38+
hooks:
39+
- id: typos

.ruff.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
"helpers",
24+
"utils"
25+
]
26+
section-order = [
27+
"future",
28+
"standard-library",
29+
"pytest",
30+
"django",
31+
"rest_framework",
32+
"third-party",
33+
"first-party",
34+
"local-folder"
35+
]
36+
37+
[lint.isort.sections]
38+
pytest = ["pytest"]
39+
django = ["django"]
40+
rest_framework = ["rest_framework"]

Makefile

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
export NVM_DIR="${PWD}/app/nvm"
1+
SHELL := bash
22

3-
.PHONY: prod dev serve assets links csvtables definitions glossary pattern protocol schema tree \
4-
typos app watch clean distclean
3+
export NVM_DIR=$(PWD)/nvm
4+
export NVM_VERSION=v0.40.4
55

6-
prod: assets csvtables definitions glossary pattern protocol schema tree
6+
export ISIMIP_LOG_LEVEL=WARNING
77

8-
dev: links csvtables definitions glossary pattern protocol schema tree
8+
.PHONY: all csvtables definitions glossary pattern protocol schema tree \
9+
serve typos app watch lint clean cleannode cleanenv distclean
910

10-
serve:
11-
python3 -m http.server -b 127.0.0.1 8080 -d output
12-
13-
assets:
14-
python3 build/assets.py
15-
16-
links:
17-
python3 build/assets.py --link
11+
all: csvtables definitions glossary pattern protocol schema tree
1812

1913
csvtables:
2014
python3 build/csvtables.py
@@ -37,19 +31,40 @@ schema:
3731
tree:
3832
python3 build/tree.py
3933

34+
serve:
35+
python3 -m http.server -b 127.0.0.1 8080 -d output
36+
4037
typos:
4138
typos --write-changes --force-exclude
4239

43-
app:
44-
make -C app
40+
app: nvm
41+
. $(NVM_DIR)/nvm.sh; nvm use && npm ci && npm run build
4542

46-
watch:
47-
make -C app watch
43+
watch: nvm node_modules
44+
. $(NVM_DIR)/nvm.sh; nvm use && npm ci && npm run watch
45+
46+
lint: nvm node_modules
47+
. $(NVM_DIR)/nvm.sh; nvm use && npm ci && npm run lint
48+
49+
nvm:
50+
mkdir -p $(NVM_DIR)
51+
NVM_DIR=$(NVM_DIR) PROFILE=/dev/null \
52+
bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$(NVM_VERSION)/install.sh | bash > /dev/null'
53+
. $(NVM_DIR)/nvm.sh; nvm install
54+
55+
node_modules:
56+
. $(NVM_DIR)/nvm.sh; nvm use && npm ci
4857

4958
clean:
5059
rm -fr output
5160

61+
cleannode:
62+
rm -rf nvm node_modules
63+
64+
cleanenv:
65+
rm -fr env
66+
5267
distclean:
5368
rm -fr output
69+
rm -rf nvm node_modules
5470
rm -fr env
55-
make -C app clean

README.md

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,84 @@
11
ISIMIP3 simulation protocol
22
===========================
33

4-
This project builds sector-specific ISIMIP protocols from a common data source.
5-
Machine-readable data are under [definitions](definitions/), and text under [protocol](protocol/).
6-
7-
The rendered protocols are found at https://protocol.isimip.org.
4+
This repository contains all information and tools to build the ISIMIP3 protocol as presented on [protocol.isimip.org](https://protocol.isimip.org). The YAML files containing the information for the tables are located under [definitions](definitions/) and the markdown files for the text under [protocol](protocol/).
85

96
You can clone this repository and work and render the files locally as documented below.
107

11-
You can also edit the markdown files at github directly. With a delay of minutes,
12-
your updates will be visible at `https://protocol.isimip.org`.
8+
You can also edit the markdown files at github directly. With a delay of minutes, your updates will be visible at `https://protocol.isimip.org`.
9+
10+
As a rule, the sector-specific text should be kept to a minimum and cover as much structure as possible by machine-readable code under [definitions](definitions/).
1311

14-
As a rule, the sector-specific text should be kept to a minimum and cover
15-
as much structure as possible by machine-readable code under [definitions](definitions/).
1612

1713
Setup
1814
-----
1915

2016
Building the protocol requires:
2117

22-
- **git**: for version control
23-
- **Python** (> 3.6)
24-
- **curl**: for downloading nvm in the app Makefile
25-
26-
The installation of Python (and its developing packages), however differs from operating system to operating system. Instructions can be found [here](https://github.com/ISI-MIP/isimip-qc/blob/main/README.md#prerequisites).
18+
- **Python** (> 3.10)
19+
- **git** for version control
20+
- **curl** for downloading `nvm`
2721

28-
A `Makefile` is provided to help with the installation process.
22+
The installation of Python (and its developing packages) differs from operating system to operating system. Instructions to setup Python for your system can be found [here](https://utils.isimip.org/prerequisites/).
2923

30-
If you work with different Python applications, we recommend to create a virtual environment for the protocol:
24+
We recommend to create a virtual environment for the protocol:
3125

3226
```bash
3327
python3 -m venv env
3428
source env/bin/activate # the env needs to be sourced everytime you use a new terminal
3529
```
3630

37-
The Python requirements are installed using:
31+
The Python requirements can be installed using:
3832

3933
```bash
4034
pip install -r requirements.txt
4135
```
4236

43-
The JavaScript part of the protocol needs to be build using NodeJS and Webpack. For convenience this can be done by using only:
37+
38+
Build
39+
-----
40+
41+
The different `build` scripts can be run by using:
4442

4543
```bash
46-
make app
44+
make
4745
```
4846

49-
`make app` bootstraps Node via nvm and requires `curl`.
47+
The output files are located in `output`.
5048

51-
52-
Build
53-
-----
49+
The JavaScript part of the protocol needs to be build using [NodeJS](https://nodejs.org) and [vite](https://vite.dev/). For convenience this can be done by using ([nvm](https://github.com/nvm-sh/nvm) and the Node dependencies are downloaded automatically, this requires `curl`):
5450

5551
```bash
56-
make # should work on Linux/macOS
57-
make dev # like make, but lining the front-end assets for development
58-
59-
make serve # starts a http server on port :8000 so that you can access the protocol in your browser
52+
make app
53+
make watch # automatically rebuild when the source changes
6054
```
6155

62-
The output files are located in `output`. The files, e.g. `index.html` can opened with a web browser.
56+
When working with different branches or after dependency changed, the following make targets can be used to clean the local copy:
57+
58+
```
59+
make clean # removes the output directory
60+
make cleannode # removes nvm and node_modules (JavaScript dependencies)
61+
make cleanenv # removes the virtual environment (Python dependencies)
62+
make distclean # runs all clean targets
63+
```
6364

6465

6566
Development server
6667
------------------
6768

68-
The command `make serve` will open a local webserver on port `:8000`. The protocol can than be accessed at http://localhost:8080 from a browser.
69+
The command
70+
71+
```bash
72+
make serve
73+
```
74+
75+
will open a local webserver on port `:8080`. The protocol can than be accessed at http://localhost:8080 from a browser.
6976

7077

7178
Editing
7279
-------
7380

74-
Edit the markdown files for each sector under [protocol](protocol).
81+
The textual part of the protocol can be edited using the markdown files in [protocol](protocol).
7582

7683
The interactive tables have the following syntax:
7784

@@ -125,7 +132,7 @@ The definition YAML files however can be changed without touching the JavaScript
125132
...
126133
```
127134

128-
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.
135+
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.
129136

130137
In order to add a new sector, the following steps need to be taken:
131138

app/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/Makefile

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)