Skip to content

Commit 4427544

Browse files
authored
Merge pull request #36 from ecmwf/feat/downstream_ci
first draft updating github workflows
2 parents a92919b + 32c36c0 commit 4427544

19 files changed

+447
-189
lines changed

.flake8

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[flake8]
2+
# Example to set max line length
3+
max-line-length = 88
4+
5+
# Per-file ignore settings
6+
per-file-ignores =
7+
# Ignore F401 (unused import) in __init__.py files
8+
__init__.py: F401
9+
10+
# Ignore specific errors in the tests folder
11+
# - F405: Undefined variable
12+
# - F403: Wildcard import usage
13+
tests/*: F405,F403

.github/workflows/cd.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: cd
2+
3+
on:
4+
push:
5+
tags:
6+
- '**'
7+
8+
jobs:
9+
10+
pypi:
11+
uses: ecmwf-actions/reusable-workflows/.github/workflows/cd-pypi.yml@v2
12+
secrets: inherit

.github/workflows/ci.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,15 @@ on:
88

99
jobs:
1010

11-
quality_assurance:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v2
15-
- run: pip install ruff
16-
- run: ruff check # check linting violations
17-
- run: ruff format --check # check formatting
11+
qa-pre-commit:
12+
uses: ecmwf-actions/reusable-workflows/.github/workflows/qa-precommit-run.yml@v2
13+
secrets: inherit
1814

19-
setup_and_test:
20-
runs-on: ubuntu-latest
21-
steps:
22-
- uses: actions/checkout@v3
23-
- uses: actions/setup-python@v2
24-
- name: install earthkit-hydro
25-
shell: bash -l {0}
26-
run: pip install .[test]
27-
- name: run tests
28-
shell: bash -l {0}
29-
run: pytest
15+
test:
16+
uses: ecmwf-actions/reusable-workflows/.github/workflows/qa-pytest-pyproject.yml@v2
17+
secrets: inherit
18+
19+
# TODO: add back
20+
# qa-python:
21+
# uses: ecmwf-actions/reusable-workflows/.github/workflows/ci-python.yml@v2
22+
# secrets: inherit

.github/workflows/downstream-ci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: downstream-ci
2+
3+
on:
4+
# Trigger the workflow on push to master or develop, except tag creation
5+
push:
6+
branches:
7+
- 'main'
8+
- 'develop'
9+
tags-ignore:
10+
- '**'
11+
12+
# Trigger the workflow on pull request
13+
pull_request: ~
14+
15+
# Trigger the workflow manually
16+
workflow_dispatch: ~
17+
18+
# Trigger after public PR approved for CI
19+
pull_request_target:
20+
types: [labeled]
21+
22+
jobs:
23+
# Run CI including downstream packages on self-hosted runners
24+
downstream-ci:
25+
name: downstream-ci
26+
if: ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }}
27+
uses: ecmwf-actions/downstream-ci/.github/workflows/downstream-ci.yml@feat/add-earthkit-hydro
28+
with:
29+
earthkit-hydro: ecmwf/earthkit-hydro@${{ github.event.pull_request.head.sha || github.sha }}
30+
codecov_upload: true
31+
python_qa: true
32+
secrets: inherit
33+
34+
# Run CI of private downstream packages on self-hosted runners
35+
private-downstream-ci:
36+
name: private-downstream-ci
37+
needs: [downstream-ci]
38+
if: (success() || failure()) && ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }}
39+
runs-on: ubuntu-latest
40+
permissions:
41+
pull-requests: write
42+
steps:
43+
- name: Dispatch private downstream CI
44+
uses: ecmwf-actions/dispatch-private-downstream-ci@v1
45+
with:
46+
token: ${{ secrets.GH_REPO_READ_TOKEN }}
47+
owner: ecmwf-actions
48+
repository: private-downstream-ci
49+
event_type: downstream-ci
50+
payload: '{"earthkit-hydro": "ecmwf/earthkit-hydro@${{ github.event.pull_request.head.sha || github.sha }}"}'
51+
52+
# Build downstream packages on HPC
53+
downstream-ci-hpc:
54+
name: downstream-ci-hpc
55+
if: ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }}
56+
uses: ecmwf-actions/downstream-ci/.github/workflows/downstream-ci-hpc.yml@feat/add-earthkit-hydro
57+
with:
58+
earthkit-hydro: ecmwf/earthkit-hydro@${{ github.event.pull_request.head.sha || github.sha }}
59+
secrets: inherit
60+
61+
# Run CI of private downstream packages on HPC
62+
private-downstream-ci-hpc:
63+
name: private-downstream-ci-hpc
64+
needs: [downstream-ci-hpc]
65+
if: (success() || failure()) && ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }}
66+
runs-on: ubuntu-latest
67+
permissions:
68+
pull-requests: write
69+
steps:
70+
- name: Dispatch private downstream CI
71+
uses: ecmwf-actions/dispatch-private-downstream-ci@v1
72+
with:
73+
token: ${{ secrets.GH_REPO_READ_TOKEN }}
74+
owner: ecmwf-actions
75+
repository: private-downstream-ci
76+
event_type: downstream-ci-hpc
77+
payload: '{"earthkit-hydro": "ecmwf/earthkit-hydro@${{ github.event.pull_request.head.sha || github.sha }}"}'

.github/workflows/label-public-pr.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: label-public-pr
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
label:
9+
uses: ecmwf-actions/reusable-workflows/.github/workflows/label-pr.yml@v2

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__pycache__/
22
.ipynb_checkpoints/
3-
*.egg-info
3+
*.egg-info

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ repos:
1212
args: [ --fix ]
1313
- id: ruff-format # fix formatting
1414
types_or: [ python, pyi, jupyter ]
15+
- repo: https://github.com/psf/black
16+
rev: 25.1.0
17+
hooks:
18+
- id: black
19+
- repo: https://github.com/pycqa/isort
20+
rev: 5.13.2
21+
hooks:
22+
- id: isort
23+
- repo: https://github.com/pycqa/flake8
24+
rev: 7.0.0
25+
hooks:
26+
- id: flake8
1527
- repo: https://github.com/pre-commit/pre-commit-hooks
1628
rev: v4.4.0
1729
hooks:

docs/notebooks/example.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@
370370
],
371371
"source": [
372372
"precipitation_field = ekd.from_source(\n",
373-
" \"file\", \"/ec/ws4/tc/emos/work/cems/floods/efas/emos/efas/europe5km/202502/EUD2025021100/forcings/R06a.nc\"\n",
373+
" \"file\",\n",
374+
" \"/ec/ws4/tc/emos/work/cems/floods/efas/emos/efas/europe5km/202502/EUD2025021100/forcings/R06a.nc\",\n",
374375
")[0].to_numpy()\n",
375376
"\n",
376377
"qplot.contourf(precipitation_field[::-1, :], style=style)"

pyproject.toml

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ build-backend = "setuptools.build_meta"
66
name = "earthkit-hydro"
77
requires-python = ">=3.8"
88
authors = [
9-
{name = "European Centre for Medium-Range Weather Forecasts (ECMWF)", email = "[email protected]"},
10-
]
9+
{ name = "European Centre for Medium-Range Weather Forecasts (ECMWF)", email = "[email protected]" }
10+
]
1111
maintainers = [
1212
{name = "Oisín M. Morrison", email = "[email protected]"},
13-
{name = "Corentin Carton de Wiart", email = "[email protected]"},
14-
]
13+
{name = "Corentin Carton de Wiart", email = "[email protected]"}
14+
]
1515
description = "A Python library for common hydrological functions"
1616
license = {file = "LICENSE"}
1717
classifiers = [
@@ -27,14 +27,11 @@ classifiers = [
2727
"Programming Language :: Python :: 3.11",
2828
"Programming Language :: Python :: 3.12",
2929
"Programming Language :: Python :: 3.13",
30-
"Topic :: Scientific/Engineering",
31-
]
30+
"Topic :: Scientific/Engineering"
31+
]
3232
dynamic = ["version", "readme"]
3333

34-
dependencies = [
35-
"numpy",
36-
"joblib"
37-
]
34+
dependencies = ["numpy", "joblib"]
3835

3936
[project.urls]
4037
repository = "https://github.com/ecmwf/earthkit-hydro"
@@ -43,43 +40,52 @@ dependencies = [
4340

4441
[project.optional-dependencies]
4542
readers = [
46-
"earthkit-data",
47-
]
48-
test = [
43+
"earthkit-data"
44+
]
45+
tests = [
4946
"pytest",
50-
"pytest-cases",
51-
]
47+
"pytest-cases"
48+
]
5249
dev = [
5350
"pytest",
5451
"pytest-cases",
55-
"ruff",
5652
"pre-commit"
57-
]
53+
]
54+
all = [
55+
"earthkit-data",
56+
"pytest",
57+
"pytest-cases",
58+
"pre-commit"
59+
]
60+
61+
[tool.black]
62+
line-length = 88
63+
skip-string-normalization = false
64+
65+
[tool.isort]
66+
profile = "black" # Ensures compatibility with Black's formatting.
67+
line_length = 88 # Same as Black's line length for consistency.
5868

5969
# Linting settings
6070
[tool.ruff]
61-
line-length = 120
62-
indent-width = 4
71+
line-length = 88
6372

6473
[tool.ruff.format]
6574
quote-style = "double"
66-
indent-style = "space"
6775

6876
[tool.ruff.lint.per-file-ignores]
6977
"__init__.py" = [
7078
"F401", # unused imports
71-
]
79+
]
7280
"tests/*" = [
7381
"F405", # variable may be undefined, or defined from star imports
74-
"F403" # use of wildcard imports
75-
]
82+
"F403", # use of wildcard imports
83+
]
7684

7785
# Testing
7886
[tool.pytest]
7987
addopts = "--pdbcls=IPython.terminal.debugger:Pdb"
80-
testpaths = [
81-
"tests",
82-
]
88+
testpaths = ["tests"]
8389

8490
# Packaging/setuptools options
8591
[tool.setuptools]
@@ -94,8 +100,7 @@ exclude = ["tests"]
94100

95101
[tool.setuptools_scm]
96102
write_to = "src/earthkit/hydro/_version.py"
97-
write_to_template = '''
98-
# Do not change! Do not track in version control!
103+
write_to_template = '''# Do not change! Do not track in version control!
99104
__version__ = "{version}"
100105
'''
101106
parentdir_prefix_version='earthkit-hydro-' # get version from GitHub-like tarballs

src/earthkit/hydro/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
from .readers import from_cama_downxy, from_cama_nextxy, from_d8, load_river_network, create_river_network
2-
from .river_network import RiverNetwork
31
from .accumulation import flow_downstream
4-
from .movement import move_downstream, move_upstream
52
from .catchment import find_catchments, find_subcatchments
63
from .core import flow
4+
from .movement import move_downstream, move_upstream
5+
from .readers import (
6+
create_river_network,
7+
from_cama_downxy,
8+
from_cama_nextxy,
9+
from_d8,
10+
load_river_network,
11+
)
12+
from .river_network import RiverNetwork

0 commit comments

Comments
 (0)