pinta-dags 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pinta_dags-0.1.0/PKG-INFO +87 -0
- pinta_dags-0.1.0/README.md +72 -0
- pinta_dags-0.1.0/pyproject.toml +109 -0
- pinta_dags-0.1.0/pyproject.toml.orig +107 -0
- pinta_dags-0.1.0/src/pinta_dags/__init__.py +6 -0
- pinta_dags-0.1.0/src/pinta_dags/config.py +196 -0
- pinta_dags-0.1.0/src/pinta_dags/constraints.txt +710 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/__init__.py +4 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/calculate_dem_diff.py +195 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/calculate_rasters_for_production_area.py +266 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/calculate_reference_dem.py +162 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/dissolve_update_areas.py +404 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/initialize_dem_preview.py +157 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/load_dem.py +247 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/print_hello_world.py +75 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/process_production_areas.py +77 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/register_update_areas.py +251 -0
- pinta_dags-0.1.0/src/pinta_dags/dags/suggest_masked_update_areas.py +133 -0
- pinta_dags-0.1.0/src/pinta_dags/py.typed +0 -0
- pinta_dags-0.1.0/src/pinta_dags/scripts/__init__.py +6 -0
- pinta_dags-0.1.0/src/pinta_dags/scripts/prepare_airflow_constraints.py +129 -0
- pinta_dags-0.1.0/src/pinta_dags/sensors/__init__.py +4 -0
- pinta_dags-0.1.0/src/pinta_dags/sensors/folder_hash_sensor.py +68 -0
- pinta_dags-0.1.0/src/pinta_dags/tasks.py +352 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: pinta-dags
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DAG component of the elevation production system
|
|
5
|
+
Requires-Dist: pinta-db>=0.2.0,<0.3
|
|
6
|
+
Requires-Dist: pinta-processing>=0.1.0,<0.2
|
|
7
|
+
Requires-Dist: pinta-lib
|
|
8
|
+
Requires-Dist: apache-airflow[docker,postgres,standard]==3.3.1 ; extra == 'airflow'
|
|
9
|
+
Requires-Dist: pinta-db[psycopg]>=0.2.0,<0.3 ; extra == 'airflow'
|
|
10
|
+
Requires-Dist: numpy==2.5.1 ; extra == 'airflow'
|
|
11
|
+
Requires-Dist: scipy==1.18.0 ; extra == 'airflow'
|
|
12
|
+
Requires-Python: >=3.12, <3.14
|
|
13
|
+
Provides-Extra: airflow
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Airflow Workflow component
|
|
17
|
+
|
|
18
|
+
## Development
|
|
19
|
+
|
|
20
|
+
By default, Airflow runs in a container, started from the repository root with Docker
|
|
21
|
+
Compose:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
docker compose up -d
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
(or `make up`). This is the default Airflow used in development and e2e tests, available at
|
|
28
|
+
<http://localhost:8080>.
|
|
29
|
+
|
|
30
|
+
### Local development
|
|
31
|
+
|
|
32
|
+
Optionally run a local standalone Airflow on the host (in the dev-container) from the
|
|
33
|
+
repository root. This is mainly for testing Airflow version upgrades and as a backup:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
make airflow-start
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
After execution, the Airflow logs will appear in the terminal. Passwords are pre-written
|
|
40
|
+
deterministically to `.airflow/simple_auth_manager_passwords.json.generated` from the values of `.env`.
|
|
41
|
+
Run `make airflow-clean airflow-start` to pick up changes to those passwords.
|
|
42
|
+
|
|
43
|
+
Once started, Airflow can be accessed via browser at <http://localhost:8080>.
|
|
44
|
+
|
|
45
|
+
The **PORTS** tab in the terminal panel also shows which port the Airflow webserver is running on, and VS Code
|
|
46
|
+
provides "Open in browser" buttons.
|
|
47
|
+
|
|
48
|
+
If necessary, code changes can be updated for Airflow use immediately by running the command `airflow dags reserialize`
|
|
49
|
+
or `make airflow-reserialize` from the root of the repository.
|
|
50
|
+
Airflow also automatically updates DAG file changes periodically.
|
|
51
|
+
|
|
52
|
+
#### Developing DAGs locally
|
|
53
|
+
|
|
54
|
+
If you want to run the load dem DAG, you can place test data inside the repo root `test_data` folder, which is automatically mounted to the processing container.
|
|
55
|
+
|
|
56
|
+
## DAG development practices
|
|
57
|
+
|
|
58
|
+
* When accessing any database, use `@task.docker` since database urls work only inside containers
|
|
59
|
+
|
|
60
|
+
## Updating Airflow
|
|
61
|
+
|
|
62
|
+
`numpy` and `scipy` are pinned in the DAG component because Airflow's upstream constraints file already fixes versions for the whole dependency set, but those two packages need to be kept under explicit control in this repository so the workspace can resolve the Airflow extra consistently across components. Pulling them out of the generated constraints file and pinning them in `pyproject.toml` makes upgrades repeatable and avoids resolution conflicts when `uv add` is run.
|
|
63
|
+
|
|
64
|
+
* Update the Airflow version in `components/dags/pyproject.toml` manually.
|
|
65
|
+
* Update required AIRFLOW_VERSION and PYTHON_VERSION in Makefile
|
|
66
|
+
* Fetch and normalize the matching constraints file with `make airflow-prepare-constraints`.
|
|
67
|
+
* The helper downloads the upstream Apache Airflow constraints file for the selected Python version, removes the `numpy` and `scipy` pins, and writes a local modified copy under `components/dags/.airflow/constraints/`.
|
|
68
|
+
* The helper prints the upstream `numpy` and `scipy` versions. Update the `numpy` and `scipy` pins in `components/dags/pyproject.toml` to match.
|
|
69
|
+
* If the backend Airflow client needs to stay in sync, update the pin in `components/backend/pyproject.toml` as well.
|
|
70
|
+
* Run `uv add --optional airflow apache-airflow[docker,postgres,standard]==<version> --constraint <path-to-modified-constraints>` from `components/dags`.
|
|
71
|
+
* Run tests and test standalone usage; remove warning filters or other workarounds required by the old version if
|
|
72
|
+
necessary.
|
|
73
|
+
|
|
74
|
+
### Special Cases
|
|
75
|
+
|
|
76
|
+
If there is a need to update dependencies defined by the Airflow constraint file—for example, due to a vulnerability, a
|
|
77
|
+
bug, or a new feature in a specific provider package:
|
|
78
|
+
|
|
79
|
+
* Update the Ansible role's constraint file as needed, e.g., for a single package (add a comment explaining why it was
|
|
80
|
+
updated from the original if necessary).
|
|
81
|
+
* Compile new requirements files locally (see commands at the top of the files).
|
|
82
|
+
* Test sufficiently.
|
|
83
|
+
* Deploy the update to the environments.
|
|
84
|
+
|
|
85
|
+
**NOTE:** Updating the shared constraint file for a single Airflow version will simultaneously push the new versions to
|
|
86
|
+
other environments if a deployment is performed (e.g., for a configuration update) before the update has been
|
|
87
|
+
sufficiently verified.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Airflow Workflow component
|
|
2
|
+
|
|
3
|
+
## Development
|
|
4
|
+
|
|
5
|
+
By default, Airflow runs in a container, started from the repository root with Docker
|
|
6
|
+
Compose:
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
docker compose up -d
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
(or `make up`). This is the default Airflow used in development and e2e tests, available at
|
|
13
|
+
<http://localhost:8080>.
|
|
14
|
+
|
|
15
|
+
### Local development
|
|
16
|
+
|
|
17
|
+
Optionally run a local standalone Airflow on the host (in the dev-container) from the
|
|
18
|
+
repository root. This is mainly for testing Airflow version upgrades and as a backup:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
make airflow-start
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
After execution, the Airflow logs will appear in the terminal. Passwords are pre-written
|
|
25
|
+
deterministically to `.airflow/simple_auth_manager_passwords.json.generated` from the values of `.env`.
|
|
26
|
+
Run `make airflow-clean airflow-start` to pick up changes to those passwords.
|
|
27
|
+
|
|
28
|
+
Once started, Airflow can be accessed via browser at <http://localhost:8080>.
|
|
29
|
+
|
|
30
|
+
The **PORTS** tab in the terminal panel also shows which port the Airflow webserver is running on, and VS Code
|
|
31
|
+
provides "Open in browser" buttons.
|
|
32
|
+
|
|
33
|
+
If necessary, code changes can be updated for Airflow use immediately by running the command `airflow dags reserialize`
|
|
34
|
+
or `make airflow-reserialize` from the root of the repository.
|
|
35
|
+
Airflow also automatically updates DAG file changes periodically.
|
|
36
|
+
|
|
37
|
+
#### Developing DAGs locally
|
|
38
|
+
|
|
39
|
+
If you want to run the load dem DAG, you can place test data inside the repo root `test_data` folder, which is automatically mounted to the processing container.
|
|
40
|
+
|
|
41
|
+
## DAG development practices
|
|
42
|
+
|
|
43
|
+
* When accessing any database, use `@task.docker` since database urls work only inside containers
|
|
44
|
+
|
|
45
|
+
## Updating Airflow
|
|
46
|
+
|
|
47
|
+
`numpy` and `scipy` are pinned in the DAG component because Airflow's upstream constraints file already fixes versions for the whole dependency set, but those two packages need to be kept under explicit control in this repository so the workspace can resolve the Airflow extra consistently across components. Pulling them out of the generated constraints file and pinning them in `pyproject.toml` makes upgrades repeatable and avoids resolution conflicts when `uv add` is run.
|
|
48
|
+
|
|
49
|
+
* Update the Airflow version in `components/dags/pyproject.toml` manually.
|
|
50
|
+
* Update required AIRFLOW_VERSION and PYTHON_VERSION in Makefile
|
|
51
|
+
* Fetch and normalize the matching constraints file with `make airflow-prepare-constraints`.
|
|
52
|
+
* The helper downloads the upstream Apache Airflow constraints file for the selected Python version, removes the `numpy` and `scipy` pins, and writes a local modified copy under `components/dags/.airflow/constraints/`.
|
|
53
|
+
* The helper prints the upstream `numpy` and `scipy` versions. Update the `numpy` and `scipy` pins in `components/dags/pyproject.toml` to match.
|
|
54
|
+
* If the backend Airflow client needs to stay in sync, update the pin in `components/backend/pyproject.toml` as well.
|
|
55
|
+
* Run `uv add --optional airflow apache-airflow[docker,postgres,standard]==<version> --constraint <path-to-modified-constraints>` from `components/dags`.
|
|
56
|
+
* Run tests and test standalone usage; remove warning filters or other workarounds required by the old version if
|
|
57
|
+
necessary.
|
|
58
|
+
|
|
59
|
+
### Special Cases
|
|
60
|
+
|
|
61
|
+
If there is a need to update dependencies defined by the Airflow constraint file—for example, due to a vulnerability, a
|
|
62
|
+
bug, or a new feature in a specific provider package:
|
|
63
|
+
|
|
64
|
+
* Update the Ansible role's constraint file as needed, e.g., for a single package (add a comment explaining why it was
|
|
65
|
+
updated from the original if necessary).
|
|
66
|
+
* Compile new requirements files locally (see commands at the top of the files).
|
|
67
|
+
* Test sufficiently.
|
|
68
|
+
* Deploy the update to the environments.
|
|
69
|
+
|
|
70
|
+
**NOTE:** Updating the shared constraint file for a single Airflow version will simultaneously push the new versions to
|
|
71
|
+
other environments if a deployment is performed (e.g., for a configuration update) before the update has been
|
|
72
|
+
sufficiently verified.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pinta-dags"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "DAG component of the elevation production system"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12,<3.14"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"pinta-db>=0.2.0,<0.3",
|
|
9
|
+
"pinta-processing>=0.1.0,<0.2",
|
|
10
|
+
"pinta-lib",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[project.optional-dependencies]
|
|
14
|
+
airflow = [
|
|
15
|
+
"apache-airflow[docker,postgres,standard]==3.3.1",
|
|
16
|
+
"pinta-db[psycopg]>=0.2.0,<0.3",
|
|
17
|
+
"numpy==2.5.1",
|
|
18
|
+
"scipy==1.18.0",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["uv_build>=0.13.7,<0.14.0"]
|
|
23
|
+
build-backend = "uv_build"
|
|
24
|
+
|
|
25
|
+
[tool.uv]
|
|
26
|
+
default-groups = [
|
|
27
|
+
"dev",
|
|
28
|
+
"lint",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[tool.uv.build-backend]
|
|
32
|
+
module-name = "pinta_dags"
|
|
33
|
+
include = [
|
|
34
|
+
"py.typed",
|
|
35
|
+
"constraints.txt",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[tool.uv.sources.pinta-processing]
|
|
39
|
+
workspace = true
|
|
40
|
+
|
|
41
|
+
[tool.uv.sources.pinta-db]
|
|
42
|
+
workspace = true
|
|
43
|
+
|
|
44
|
+
[tool.uv.sources.pinta-lib]
|
|
45
|
+
workspace = true
|
|
46
|
+
|
|
47
|
+
[tool.pytest.ini_options]
|
|
48
|
+
testpaths = ["test"]
|
|
49
|
+
addopts = "-n 0 --import-mode=importlib -p no:pytest-qgis"
|
|
50
|
+
timeout = 60
|
|
51
|
+
|
|
52
|
+
[tool.ruff]
|
|
53
|
+
extend = "../../pyproject.toml"
|
|
54
|
+
|
|
55
|
+
[tool.semantic_release]
|
|
56
|
+
commit_parser = "conventional-monorepo"
|
|
57
|
+
major_on_zero = false
|
|
58
|
+
allow_zero_version = true
|
|
59
|
+
commit_message = """
|
|
60
|
+
chore(release): pinta-dags@{version}
|
|
61
|
+
|
|
62
|
+
Automatically generated by python-semantic-release
|
|
63
|
+
"""
|
|
64
|
+
tag_format = "pinta-dags-v{version}"
|
|
65
|
+
version_toml = ["pyproject.toml:project.version"]
|
|
66
|
+
build_command = """
|
|
67
|
+
set -euo pipefail
|
|
68
|
+
python -m pip install uv packaging
|
|
69
|
+
rm -rf dist
|
|
70
|
+
uv lock --upgrade-package "$PACKAGE_NAME"
|
|
71
|
+
git add ../../uv.lock
|
|
72
|
+
python ../../scripts/build_constraints.py --module pinta_dags --extra airflow --airflow
|
|
73
|
+
uv build --out-dir dist
|
|
74
|
+
python ../../scripts/check_wheel_constraints.py --module pinta_dags --extra airflow
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
[tool.semantic_release.commit_parser_options]
|
|
78
|
+
path_filters = ["."]
|
|
79
|
+
scope_prefix = "dags"
|
|
80
|
+
minor_tags = ["feat"]
|
|
81
|
+
patch_tags = [
|
|
82
|
+
"fix",
|
|
83
|
+
"build",
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
[tool.semantic_release.changelog]
|
|
87
|
+
mode = "init"
|
|
88
|
+
exclude_commit_patterns = ['(?!(?:feat|fix)(?:\([^)]*?\))?!?: ).*']
|
|
89
|
+
|
|
90
|
+
[tool.semantic_release.branches.main]
|
|
91
|
+
match = "(main|master)"
|
|
92
|
+
prerelease_token = "dev"
|
|
93
|
+
|
|
94
|
+
[dependency-groups]
|
|
95
|
+
dev = [
|
|
96
|
+
"pytest-dotenv",
|
|
97
|
+
"pytest-mock",
|
|
98
|
+
"pytest-order",
|
|
99
|
+
"pytest-rerunfailures",
|
|
100
|
+
"pytest-subtests",
|
|
101
|
+
"pytest-timeout",
|
|
102
|
+
"pytest-xdist",
|
|
103
|
+
"coverage-enable-subprocess",
|
|
104
|
+
]
|
|
105
|
+
lint = [
|
|
106
|
+
"prek",
|
|
107
|
+
"mypy",
|
|
108
|
+
"ruff",
|
|
109
|
+
]
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pinta-dags"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "DAG component of the elevation production system"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12,<3.14"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"pinta-db>=0.2.0,<0.3",
|
|
9
|
+
"pinta-processing>=0.1.0,<0.2",
|
|
10
|
+
"pinta-lib",
|
|
11
|
+
]
|
|
12
|
+
[project.optional-dependencies]
|
|
13
|
+
airflow = [
|
|
14
|
+
"apache-airflow[docker,postgres,standard]==3.3.1",
|
|
15
|
+
"pinta-db[psycopg]>=0.2.0,<0.3",
|
|
16
|
+
"numpy==2.5.1",
|
|
17
|
+
"scipy==1.18.0",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[build-system]
|
|
21
|
+
requires = ["uv_build>=0.13.7,<0.14.0"]
|
|
22
|
+
build-backend = "uv_build"
|
|
23
|
+
|
|
24
|
+
[tool.uv.build-backend]
|
|
25
|
+
module-name = "pinta_dags"
|
|
26
|
+
include = ["py.typed", "constraints.txt"]
|
|
27
|
+
|
|
28
|
+
[tool.uv.sources]
|
|
29
|
+
pinta-processing = { workspace = true }
|
|
30
|
+
pinta-db = { workspace = true }
|
|
31
|
+
pinta-lib = { workspace = true }
|
|
32
|
+
|
|
33
|
+
[tool.uv]
|
|
34
|
+
default-groups = ["dev", "lint"]
|
|
35
|
+
|
|
36
|
+
[dependency-groups]
|
|
37
|
+
dev = [
|
|
38
|
+
# Airflow as dev dependency to avoid pinning the version
|
|
39
|
+
# of published dag package to specific airflow version
|
|
40
|
+
# (airflow can be updated without releasing a new version of the dags)
|
|
41
|
+
|
|
42
|
+
"pytest-dotenv",
|
|
43
|
+
"pytest-mock",
|
|
44
|
+
"pytest-order",
|
|
45
|
+
"pytest-rerunfailures",
|
|
46
|
+
"pytest-subtests",
|
|
47
|
+
"pytest-timeout",
|
|
48
|
+
"pytest-xdist",
|
|
49
|
+
"coverage-enable-subprocess",
|
|
50
|
+
]
|
|
51
|
+
lint = [
|
|
52
|
+
"prek",
|
|
53
|
+
"mypy",
|
|
54
|
+
"ruff",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[tool.pytest.ini_options]
|
|
58
|
+
testpaths = [
|
|
59
|
+
"test",
|
|
60
|
+
]
|
|
61
|
+
addopts = "-n 0 --import-mode=importlib -p no:pytest-qgis"
|
|
62
|
+
timeout = 60
|
|
63
|
+
|
|
64
|
+
# extend required for isort action to pick up correct config
|
|
65
|
+
[tool.ruff]
|
|
66
|
+
extend = "../../pyproject.toml"
|
|
67
|
+
|
|
68
|
+
[tool.semantic_release]
|
|
69
|
+
commit_parser = "conventional-monorepo"
|
|
70
|
+
major_on_zero = false
|
|
71
|
+
allow_zero_version = true
|
|
72
|
+
commit_message = """\
|
|
73
|
+
chore(release): pinta-dags@{version}
|
|
74
|
+
|
|
75
|
+
Automatically generated by python-semantic-release
|
|
76
|
+
"""
|
|
77
|
+
tag_format = "pinta-dags-v{version}"
|
|
78
|
+
version_toml = ["pyproject.toml:project.version"]
|
|
79
|
+
build_command = """
|
|
80
|
+
set -euo pipefail
|
|
81
|
+
python -m pip install uv packaging
|
|
82
|
+
rm -rf dist
|
|
83
|
+
uv lock --upgrade-package "$PACKAGE_NAME"
|
|
84
|
+
git add ../../uv.lock
|
|
85
|
+
python ../../scripts/build_constraints.py --module pinta_dags --extra airflow --airflow
|
|
86
|
+
uv build --out-dir dist
|
|
87
|
+
python ../../scripts/check_wheel_constraints.py --module pinta_dags --extra airflow
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
[tool.semantic_release.commit_parser_options]
|
|
91
|
+
path_filters = ["."]
|
|
92
|
+
scope_prefix = "dags"
|
|
93
|
+
# Only feat, fix and build (dependency bumps) commits are releasable
|
|
94
|
+
minor_tags = ["feat"]
|
|
95
|
+
patch_tags = ["fix", "build"]
|
|
96
|
+
|
|
97
|
+
[tool.semantic_release.changelog]
|
|
98
|
+
# Re-create the changelog from the full history on every release
|
|
99
|
+
mode = "init"
|
|
100
|
+
# Keep only feat and fix commits in the changelog
|
|
101
|
+
exclude_commit_patterns = [
|
|
102
|
+
'''(?!(?:feat|fix)(?:\([^)]*?\))?!?: ).*''',
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
[tool.semantic_release.branches.main]
|
|
106
|
+
match = "(main|master)"
|
|
107
|
+
prerelease_token = "dev"
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# Copyright (c) 2026 National Land Survey of Finland
|
|
2
|
+
# (https://www.maanmittauslaitos.fi/en).
|
|
3
|
+
# This file is part of the Pinta.
|
|
4
|
+
# Licensed under the MIT License; see the repository LICENSE file.
|
|
5
|
+
|
|
6
|
+
"""Airflow-related configurations."""
|
|
7
|
+
|
|
8
|
+
import datetime
|
|
9
|
+
import enum
|
|
10
|
+
from typing import Any
|
|
11
|
+
from urllib.parse import urlsplit, urlunsplit
|
|
12
|
+
|
|
13
|
+
from airflow.sdk import Variable
|
|
14
|
+
from docker.types import Mount
|
|
15
|
+
from pinta_common import Settings
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AirflowVariable(enum.StrEnum):
|
|
19
|
+
"""Names of Airflow Variables used across Pinta DAGs."""
|
|
20
|
+
|
|
21
|
+
# Default number of retries for Pinta tasks.
|
|
22
|
+
DEFAULT_TASK_RETRIES = "pinta_default_task_retries"
|
|
23
|
+
|
|
24
|
+
# Maximum number of DEM files processed concurrently in a single load_dem run
|
|
25
|
+
LOAD_DEM_MAX_PARALLEL_PIPELINES = "pinta_load_dem_max_parallel_pipelines"
|
|
26
|
+
# Number of staging tables used during load_dem to reduce PostGIS write contention
|
|
27
|
+
LOAD_DEM_STAGING_TABLES = "pinta_load_dem_staging_tables"
|
|
28
|
+
|
|
29
|
+
# Maximum number of las2dem tile pipelines running in parallel for reference DEM
|
|
30
|
+
CALCULATE_REFERENCE_DEM_MAX_PARALLEL_PIPELINES = (
|
|
31
|
+
"pinta_calculate_reference_dem_max_parallel_pipelines"
|
|
32
|
+
)
|
|
33
|
+
CALCULATE_REFERENCE_DEM_STAGING_TABLES = (
|
|
34
|
+
"pinta_calculate_reference_dem_staging_tables"
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Maximum number of DEM diff tile pipelines running in parallel.
|
|
38
|
+
CALCULATE_DEM_DIFF_MAX_PARALLEL_PIPELINES = (
|
|
39
|
+
"pinta_calculate_dem_diff_max_parallel_pipelines"
|
|
40
|
+
)
|
|
41
|
+
CALCULATE_DEM_DIFF_STAGING_TABLES = "pinta_calculate_dem_diff_staging_tables"
|
|
42
|
+
|
|
43
|
+
# Maximum number of update area dissolve pipelines running in parallel.
|
|
44
|
+
DISSOLVE_UPDATE_AREAS_MAX_PARALLEL_PIPELINES = (
|
|
45
|
+
"pinta_dissolve_update_areas_max_parallel_pipelines"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# Maximum number of update area register pipelines running in parallel.
|
|
49
|
+
REGISTER_UPDATE_AREAS_MAX_PARALLEL_PIPELINES = (
|
|
50
|
+
"pinta_register_update_areas_max_parallel_pipelines"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Vector mask sources as a JSON object of source name to GDAL/OGR data
|
|
54
|
+
# source, e.g. {"lake_parts": "/input/finland.gpkg|layername=lake_part"}.
|
|
55
|
+
MASK_OGR_SOURCES = "pinta_processing_mask_ogr_sources"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# How often a triggered child DAG is polled for completion.
|
|
59
|
+
TRIGGER_POKE_INTERVAL_SECONDS = 5
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def connection_uri_template(conn_id: str) -> str:
|
|
63
|
+
"""Jinja template for a connection's SQLAlchemy URI with the psycopg3 driver."""
|
|
64
|
+
return (
|
|
65
|
+
f"{{{{ conn.{conn_id}.get_hook().get_uri() "
|
|
66
|
+
f"| replace('postgresql://', 'postgresql+psycopg://') }}}}"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def build_job_connection_uri(base_uri: str, database_name: str) -> str:
|
|
71
|
+
"""Return ``base_uri`` with its database path replaced by ``database_name``."""
|
|
72
|
+
parts = urlsplit(base_uri)
|
|
73
|
+
return urlunsplit(
|
|
74
|
+
(
|
|
75
|
+
parts.scheme,
|
|
76
|
+
parts.netloc,
|
|
77
|
+
f"/{database_name}",
|
|
78
|
+
parts.query,
|
|
79
|
+
parts.fragment,
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _get_default_retries() -> int:
|
|
85
|
+
var = AirflowVariable.DEFAULT_TASK_RETRIES
|
|
86
|
+
retries = int(Variable.get(var, 0))
|
|
87
|
+
if retries < 0:
|
|
88
|
+
msg = f"{var} must be at least 0"
|
|
89
|
+
raise ValueError(msg)
|
|
90
|
+
return retries
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
PINTA_COMMON_TASK_ARGS: dict[str, Any] = {
|
|
94
|
+
"retries": _get_default_retries(),
|
|
95
|
+
"retry_delay": datetime.timedelta(seconds=10),
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
PINTA_CONTAINER_TASK_ARGS: dict[str, Any] = {
|
|
99
|
+
**PINTA_COMMON_TASK_ARGS,
|
|
100
|
+
"image": "{{ var.value.pinta_processing_image }}",
|
|
101
|
+
"force_pull": False,
|
|
102
|
+
# Cannot be templated at the moment
|
|
103
|
+
"docker_url": Variable.get(
|
|
104
|
+
"pinta_docker_socket_url", "unix:///var/run/docker.sock"
|
|
105
|
+
),
|
|
106
|
+
"network_mode": Variable.get("pinta_container_network_mode", None),
|
|
107
|
+
"environment": {
|
|
108
|
+
"TASK_LOG_LEVEL": "{{ var.value.pinta_processing_task_log_level }}",
|
|
109
|
+
"DB_SRID": "{{ var.value.pinta_db_srid }}",
|
|
110
|
+
"DB_DEM_PIXEL_SIZE": "{{ var.value.pinta_db_dem_pixel_size }}",
|
|
111
|
+
"DB_DEM_NODATA": "{{ var.value.pinta_db_dem_nodata }}",
|
|
112
|
+
"DB_JOB_WRITER_ROLE": Settings.DB_JOB_WRITER_ROLE,
|
|
113
|
+
"PINTA_DEVELOPMENT_MODE": str(Settings.DEVELOPMENT_MODE).lower(),
|
|
114
|
+
"LAStoolsLicenseFile": "/lastools/lastoolslicense.txt",
|
|
115
|
+
# Resolved per run (empty = off); dev/e2e set it so unlicensed binaries run.
|
|
116
|
+
"LASTOOLS_DEMO_MODE": "{{ var.value.get('pinta_lastools_demo_mode', '') }}",
|
|
117
|
+
},
|
|
118
|
+
"tty": True, # To be able to see the logs
|
|
119
|
+
# When using remote engine or docker-in-docker,
|
|
120
|
+
# mounting temporary volume from host is not supported
|
|
121
|
+
"mount_tmp_dir": False,
|
|
122
|
+
"auto_remove": "success",
|
|
123
|
+
"mounts": [],
|
|
124
|
+
"extra_hosts": {"host.docker.internal": "host-gateway"},
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
# maybe not the most optimal way of setting mounts
|
|
128
|
+
if mount_dir := Variable.get("pinta_processing_code_mount_dir", None):
|
|
129
|
+
PINTA_CONTAINER_TASK_ARGS["mounts"].append(
|
|
130
|
+
Mount(
|
|
131
|
+
target="/code",
|
|
132
|
+
source=mount_dir,
|
|
133
|
+
type="bind",
|
|
134
|
+
read_only=True,
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
if data_dir := Variable.get("pinta_container_source_base_path", None):
|
|
138
|
+
PINTA_CONTAINER_TASK_ARGS["mounts"].append(
|
|
139
|
+
Mount(
|
|
140
|
+
target=Variable.get("pinta_container_target_base_path", None),
|
|
141
|
+
source=data_dir,
|
|
142
|
+
type="bind",
|
|
143
|
+
read_only=True,
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
if data_base_path := Variable.get("pinta_data_base_path", "/test_data"):
|
|
147
|
+
PINTA_CONTAINER_TASK_ARGS["mounts"].append(
|
|
148
|
+
Mount(
|
|
149
|
+
target="/input",
|
|
150
|
+
source=data_base_path,
|
|
151
|
+
type="bind",
|
|
152
|
+
read_only=True,
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
if dem_base_path := Variable.get("pinta_dem_base_path", "/test_data/dem"):
|
|
156
|
+
PINTA_CONTAINER_TASK_ARGS["mounts"].append(
|
|
157
|
+
Mount(
|
|
158
|
+
target="/dem",
|
|
159
|
+
source=dem_base_path,
|
|
160
|
+
type="bind",
|
|
161
|
+
read_only=True,
|
|
162
|
+
)
|
|
163
|
+
)
|
|
164
|
+
if lastools_path := Variable.get("pinta_lastools_path", "/external/LAStools"):
|
|
165
|
+
PINTA_CONTAINER_TASK_ARGS["mounts"].append(
|
|
166
|
+
Mount(
|
|
167
|
+
target="/lastools",
|
|
168
|
+
source=lastools_path,
|
|
169
|
+
type="bind",
|
|
170
|
+
read_only=True,
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
if feature_flag_config_path := Variable.get("pinta_feature_flag_config_path", None):
|
|
174
|
+
PINTA_CONTAINER_TASK_ARGS["environment"]["PINTA_FEATURE_FLAG_CONFIG"] = (
|
|
175
|
+
"/feature_flags.json"
|
|
176
|
+
)
|
|
177
|
+
PINTA_CONTAINER_TASK_ARGS["mounts"].append(
|
|
178
|
+
Mount(
|
|
179
|
+
target="/feature_flags.json",
|
|
180
|
+
source=feature_flag_config_path,
|
|
181
|
+
type="bind",
|
|
182
|
+
read_only=True,
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
if lastools_license_path := Variable.get("pinta_lastools_license_path", None):
|
|
186
|
+
PINTA_CONTAINER_TASK_ARGS["environment"]["LAStoolsLicenseFile"] = (
|
|
187
|
+
"/lastoolslicense.txt"
|
|
188
|
+
)
|
|
189
|
+
PINTA_CONTAINER_TASK_ARGS["mounts"].append(
|
|
190
|
+
Mount(
|
|
191
|
+
target="/lastoolslicense.txt",
|
|
192
|
+
source=lastools_license_path,
|
|
193
|
+
type="bind",
|
|
194
|
+
read_only=True,
|
|
195
|
+
)
|
|
196
|
+
)
|