deep-code 0.0.1.dev0__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.
- deep_code-0.0.1.dev0/LICENSE +21 -0
- deep_code-0.0.1.dev0/PKG-INFO +166 -0
- deep_code-0.0.1.dev0/README.md +135 -0
- deep_code-0.0.1.dev0/deep_code/__init__.py +24 -0
- deep_code-0.0.1.dev0/deep_code/cli/__init__.py +3 -0
- deep_code-0.0.1.dev0/deep_code/cli/main.py +22 -0
- deep_code-0.0.1.dev0/deep_code/cli/publish.py +26 -0
- deep_code-0.0.1.dev0/deep_code/constants.py +16 -0
- deep_code-0.0.1.dev0/deep_code/tests/tools/__init__.py +3 -0
- deep_code-0.0.1.dev0/deep_code/tests/tools/test_publish.py +120 -0
- deep_code-0.0.1.dev0/deep_code/tests/utils/__init__.py +3 -0
- deep_code-0.0.1.dev0/deep_code/tests/utils/test_dataset_stac_generator.py +219 -0
- deep_code-0.0.1.dev0/deep_code/tests/utils/test_github_automation.py +120 -0
- deep_code-0.0.1.dev0/deep_code/tests/utils/test_ogc_api_record.py +113 -0
- deep_code-0.0.1.dev0/deep_code/tests/utils/test_ogc_record_generator.py +63 -0
- deep_code-0.0.1.dev0/deep_code/tests/utils/test_osc_extension.py +117 -0
- deep_code-0.0.1.dev0/deep_code/tools/__init__.py +3 -0
- deep_code-0.0.1.dev0/deep_code/tools/check.py +4 -0
- deep_code-0.0.1.dev0/deep_code/tools/new.py +5 -0
- deep_code-0.0.1.dev0/deep_code/tools/publish.py +233 -0
- deep_code-0.0.1.dev0/deep_code/tools/register.py +0 -0
- deep_code-0.0.1.dev0/deep_code/tools/setup_ci.py +1 -0
- deep_code-0.0.1.dev0/deep_code/tools/test.py +2 -0
- deep_code-0.0.1.dev0/deep_code/utils/__init__.py +3 -0
- deep_code-0.0.1.dev0/deep_code/utils/dataset_stac_generator.py +426 -0
- deep_code-0.0.1.dev0/deep_code/utils/github_automation.py +122 -0
- deep_code-0.0.1.dev0/deep_code/utils/ogc_api_record.py +94 -0
- deep_code-0.0.1.dev0/deep_code/utils/ogc_record_generator.py +54 -0
- deep_code-0.0.1.dev0/deep_code/utils/osc_extension.py +201 -0
- deep_code-0.0.1.dev0/deep_code/version.py +22 -0
- deep_code-0.0.1.dev0/deep_code.egg-info/PKG-INFO +166 -0
- deep_code-0.0.1.dev0/deep_code.egg-info/SOURCES.txt +36 -0
- deep_code-0.0.1.dev0/deep_code.egg-info/dependency_links.txt +1 -0
- deep_code-0.0.1.dev0/deep_code.egg-info/entry_points.txt +2 -0
- deep_code-0.0.1.dev0/deep_code.egg-info/requires.txt +18 -0
- deep_code-0.0.1.dev0/deep_code.egg-info/top_level.txt +2 -0
- deep_code-0.0.1.dev0/pyproject.toml +60 -0
- deep_code-0.0.1.dev0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 DeepESDL and Brockmann Consult GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: deep_code
|
|
3
|
+
Version: 0.0.1.dev0
|
|
4
|
+
Summary: deepesdl earthcode integration utility tool
|
|
5
|
+
Author-email: Tejas Morbagal Harish <tejas.morbagalharish@brockmann-consult.de>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/deepesdl/deep-code
|
|
8
|
+
Project-URL: Issues, https://github.com/deepesdl/deep-code/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/deepesdl/deep-code/blob/main/CHANGES.md
|
|
10
|
+
Keywords: analysis ready data,data science,datacube,xarray,zarr,xcube,stac,FAIR,reproducible workflow,DeepESDL
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: click
|
|
15
|
+
Requires-Dist: fsspec
|
|
16
|
+
Requires-Dist: jsonschema
|
|
17
|
+
Requires-Dist: requests
|
|
18
|
+
Requires-Dist: pandas
|
|
19
|
+
Requires-Dist: pystac
|
|
20
|
+
Requires-Dist: pyyaml
|
|
21
|
+
Requires-Dist: xcube-core
|
|
22
|
+
Requires-Dist: xrlint
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: black; extra == "dev"
|
|
25
|
+
Requires-Dist: flake8; extra == "dev"
|
|
26
|
+
Requires-Dist: numpy; extra == "dev"
|
|
27
|
+
Requires-Dist: ruff; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-recording; extra == "dev"
|
|
31
|
+
|
|
32
|
+
# deep-code
|
|
33
|
+
|
|
34
|
+
[](https://github.com/deepesdl/deep-code/actions/workflows/unittest-workflow.yaml)
|
|
35
|
+
[](https://codecov.io/gh/deepesdl/deep-code)
|
|
36
|
+
[](https://github.com/psf/black)
|
|
37
|
+
[](https://github.com/deepesdl/deep-code/blob/main/LICENSE)
|
|
38
|
+
|
|
39
|
+
`deep-code` is a lightweight python tool that comprises a command line interface(CLI)
|
|
40
|
+
and Python API providing utilities that aid integration of DeepESDL datasets,
|
|
41
|
+
experiments with EarthCODE.
|
|
42
|
+
|
|
43
|
+
The first release will focus on implementing the publish feature of DeepESDL
|
|
44
|
+
experiments/workflow as OGC API record and Datasets as an OSC stac collection.
|
|
45
|
+
|
|
46
|
+
## Setup
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
`deep-code` will be available in PyPI and conda-forge. Till the stable release,
|
|
50
|
+
developers/contributors can follow the below steps to install deep-code.
|
|
51
|
+
|
|
52
|
+
## Installing from the repository for Developers/Contributors
|
|
53
|
+
|
|
54
|
+
To install deep-code directly from the git repository, clone the repository, and execute the steps below:
|
|
55
|
+
|
|
56
|
+
```commandline
|
|
57
|
+
conda env create
|
|
58
|
+
conda activate deep-code
|
|
59
|
+
pip install -e .
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This installs all the dependencies of `deep-code` into a fresh conda environment,
|
|
63
|
+
and installs deep-code from the repository into the same environment.
|
|
64
|
+
|
|
65
|
+
## Testing
|
|
66
|
+
|
|
67
|
+
To run the unit test suite:
|
|
68
|
+
|
|
69
|
+
```commandline
|
|
70
|
+
pytest
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
To analyze test coverage
|
|
74
|
+
```shell
|
|
75
|
+
pytest --cov=deep-code
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
To produce an HTML coverage report
|
|
79
|
+
|
|
80
|
+
```commandline
|
|
81
|
+
pytest --cov-report html --cov=deep-code
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## deep_code usage
|
|
85
|
+
|
|
86
|
+
`deep_code` provides a command-line tool called deep-code, which has several subcommands
|
|
87
|
+
providing different utility functions.
|
|
88
|
+
Use the --help option with these subcommands to get more details on usage.
|
|
89
|
+
|
|
90
|
+
### deep-code publish-product
|
|
91
|
+
|
|
92
|
+
Publish a dataset which is a result of an experiment to the EarthCODE
|
|
93
|
+
open-science catalog.
|
|
94
|
+
|
|
95
|
+
```commandline
|
|
96
|
+
deep-code publish-dataset /path/to/dataset-config.yaml
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### .gitaccess example
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
github-username: your-git-user
|
|
103
|
+
github-token: personal access token
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### dataset-config.yaml example
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
dataset_id: hydrology-1D-0.009deg-100x60x60-3.0.2.zarr
|
|
110
|
+
collection_id: hydrology
|
|
111
|
+
osc_themes:
|
|
112
|
+
- Land
|
|
113
|
+
- Oceans
|
|
114
|
+
# non-mandatory
|
|
115
|
+
documentation_link: https://deepesdl.readthedocs.io/en/latest/datasets/hydrology-1D-0.009deg-100x60x60-3.0.2.zarr/
|
|
116
|
+
access_link: s3://test
|
|
117
|
+
dataset_status: completed
|
|
118
|
+
osc_region: global
|
|
119
|
+
cf_parameter:
|
|
120
|
+
- name: hydrology
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
dataset-id has to be a valid dataset-id from `deep-esdl-public` s3 or your team bucket.
|
|
124
|
+
|
|
125
|
+
### deep-code publish-workflow
|
|
126
|
+
|
|
127
|
+
Publish a workflow/experiment to the EarthCODE open-science catalog.
|
|
128
|
+
|
|
129
|
+
```commandline
|
|
130
|
+
deep-code publish-workflow /path/to/workflow-config.yaml
|
|
131
|
+
```
|
|
132
|
+
#### workflow-config.yaml example
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
workflow_id: "4D Med hydrology cube generation"
|
|
136
|
+
properties:
|
|
137
|
+
title: "Hydrology cube generation recipe"
|
|
138
|
+
description: "4D Med cube generation"
|
|
139
|
+
keywords:
|
|
140
|
+
- Earth Science
|
|
141
|
+
themes:
|
|
142
|
+
- Atmosphere
|
|
143
|
+
- Ocean
|
|
144
|
+
- Evaporation
|
|
145
|
+
license: proprietary
|
|
146
|
+
jupyter_kernel_info:
|
|
147
|
+
name: deepesdl-xcube-1.7.1
|
|
148
|
+
python_version: 3.11
|
|
149
|
+
env_file: https://git/env.yml
|
|
150
|
+
links:
|
|
151
|
+
- rel: "documentation"
|
|
152
|
+
type: "application/json"
|
|
153
|
+
title: "4DMed Hydrology Cube Generation Recipe"
|
|
154
|
+
href: "https://github.com/deepesdl/cube-gen/tree/main/hydrology/README.md"
|
|
155
|
+
- rel: "jupyter-notebook"
|
|
156
|
+
type: "application/json"
|
|
157
|
+
title: "Workflow Jupyter Notebook"
|
|
158
|
+
href: "https://github.com/deepesdl/cube-gen/blob/main/hydrology/notebooks/reading_hydrology.ipynb"
|
|
159
|
+
contact:
|
|
160
|
+
- name: Tejas Morbagal Harish
|
|
161
|
+
organization: Brockmann Consult GmbH
|
|
162
|
+
links:
|
|
163
|
+
- rel: "about"
|
|
164
|
+
type: "text/html"
|
|
165
|
+
href: "https://www.brockmann-consult.de/"
|
|
166
|
+
```
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# deep-code
|
|
2
|
+
|
|
3
|
+
[](https://github.com/deepesdl/deep-code/actions/workflows/unittest-workflow.yaml)
|
|
4
|
+
[](https://codecov.io/gh/deepesdl/deep-code)
|
|
5
|
+
[](https://github.com/psf/black)
|
|
6
|
+
[](https://github.com/deepesdl/deep-code/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
`deep-code` is a lightweight python tool that comprises a command line interface(CLI)
|
|
9
|
+
and Python API providing utilities that aid integration of DeepESDL datasets,
|
|
10
|
+
experiments with EarthCODE.
|
|
11
|
+
|
|
12
|
+
The first release will focus on implementing the publish feature of DeepESDL
|
|
13
|
+
experiments/workflow as OGC API record and Datasets as an OSC stac collection.
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
`deep-code` will be available in PyPI and conda-forge. Till the stable release,
|
|
19
|
+
developers/contributors can follow the below steps to install deep-code.
|
|
20
|
+
|
|
21
|
+
## Installing from the repository for Developers/Contributors
|
|
22
|
+
|
|
23
|
+
To install deep-code directly from the git repository, clone the repository, and execute the steps below:
|
|
24
|
+
|
|
25
|
+
```commandline
|
|
26
|
+
conda env create
|
|
27
|
+
conda activate deep-code
|
|
28
|
+
pip install -e .
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This installs all the dependencies of `deep-code` into a fresh conda environment,
|
|
32
|
+
and installs deep-code from the repository into the same environment.
|
|
33
|
+
|
|
34
|
+
## Testing
|
|
35
|
+
|
|
36
|
+
To run the unit test suite:
|
|
37
|
+
|
|
38
|
+
```commandline
|
|
39
|
+
pytest
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
To analyze test coverage
|
|
43
|
+
```shell
|
|
44
|
+
pytest --cov=deep-code
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
To produce an HTML coverage report
|
|
48
|
+
|
|
49
|
+
```commandline
|
|
50
|
+
pytest --cov-report html --cov=deep-code
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## deep_code usage
|
|
54
|
+
|
|
55
|
+
`deep_code` provides a command-line tool called deep-code, which has several subcommands
|
|
56
|
+
providing different utility functions.
|
|
57
|
+
Use the --help option with these subcommands to get more details on usage.
|
|
58
|
+
|
|
59
|
+
### deep-code publish-product
|
|
60
|
+
|
|
61
|
+
Publish a dataset which is a result of an experiment to the EarthCODE
|
|
62
|
+
open-science catalog.
|
|
63
|
+
|
|
64
|
+
```commandline
|
|
65
|
+
deep-code publish-dataset /path/to/dataset-config.yaml
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### .gitaccess example
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
github-username: your-git-user
|
|
72
|
+
github-token: personal access token
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### dataset-config.yaml example
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
dataset_id: hydrology-1D-0.009deg-100x60x60-3.0.2.zarr
|
|
79
|
+
collection_id: hydrology
|
|
80
|
+
osc_themes:
|
|
81
|
+
- Land
|
|
82
|
+
- Oceans
|
|
83
|
+
# non-mandatory
|
|
84
|
+
documentation_link: https://deepesdl.readthedocs.io/en/latest/datasets/hydrology-1D-0.009deg-100x60x60-3.0.2.zarr/
|
|
85
|
+
access_link: s3://test
|
|
86
|
+
dataset_status: completed
|
|
87
|
+
osc_region: global
|
|
88
|
+
cf_parameter:
|
|
89
|
+
- name: hydrology
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
dataset-id has to be a valid dataset-id from `deep-esdl-public` s3 or your team bucket.
|
|
93
|
+
|
|
94
|
+
### deep-code publish-workflow
|
|
95
|
+
|
|
96
|
+
Publish a workflow/experiment to the EarthCODE open-science catalog.
|
|
97
|
+
|
|
98
|
+
```commandline
|
|
99
|
+
deep-code publish-workflow /path/to/workflow-config.yaml
|
|
100
|
+
```
|
|
101
|
+
#### workflow-config.yaml example
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
workflow_id: "4D Med hydrology cube generation"
|
|
105
|
+
properties:
|
|
106
|
+
title: "Hydrology cube generation recipe"
|
|
107
|
+
description: "4D Med cube generation"
|
|
108
|
+
keywords:
|
|
109
|
+
- Earth Science
|
|
110
|
+
themes:
|
|
111
|
+
- Atmosphere
|
|
112
|
+
- Ocean
|
|
113
|
+
- Evaporation
|
|
114
|
+
license: proprietary
|
|
115
|
+
jupyter_kernel_info:
|
|
116
|
+
name: deepesdl-xcube-1.7.1
|
|
117
|
+
python_version: 3.11
|
|
118
|
+
env_file: https://git/env.yml
|
|
119
|
+
links:
|
|
120
|
+
- rel: "documentation"
|
|
121
|
+
type: "application/json"
|
|
122
|
+
title: "4DMed Hydrology Cube Generation Recipe"
|
|
123
|
+
href: "https://github.com/deepesdl/cube-gen/tree/main/hydrology/README.md"
|
|
124
|
+
- rel: "jupyter-notebook"
|
|
125
|
+
type: "application/json"
|
|
126
|
+
title: "Workflow Jupyter Notebook"
|
|
127
|
+
href: "https://github.com/deepesdl/cube-gen/blob/main/hydrology/notebooks/reading_hydrology.ipynb"
|
|
128
|
+
contact:
|
|
129
|
+
- name: Tejas Morbagal Harish
|
|
130
|
+
organization: Brockmann Consult GmbH
|
|
131
|
+
links:
|
|
132
|
+
- rel: "about"
|
|
133
|
+
type: "text/html"
|
|
134
|
+
href: "https://www.brockmann-consult.de/"
|
|
135
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
# Copyright (c) 2024 by DeepESDL and Brockmann Consult GmbH
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
5
|
+
# copy of this software and associated documentation files (the "Software"),
|
|
6
|
+
# to deal in the Software without restriction, including without limitation
|
|
7
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
|
9
|
+
# Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
|
12
|
+
# all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
19
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
# DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
from .version import version
|
|
23
|
+
|
|
24
|
+
__version__ = version
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) 2025 by Brockmann Consult GmbH
|
|
4
|
+
# Permissions are hereby granted under the terms of the MIT License:
|
|
5
|
+
# https://opensource.org/licenses/MIT.
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from deep_code.cli.publish import publish_dataset, publish_workflow
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@click.group()
|
|
13
|
+
def main():
|
|
14
|
+
"""Deep Code CLI."""
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
main.add_command(publish_dataset)
|
|
19
|
+
main.add_command(publish_workflow)
|
|
20
|
+
|
|
21
|
+
if __name__ == "__main__":
|
|
22
|
+
main()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) 2025 by Brockmann Consult GmbH
|
|
4
|
+
# Permissions are hereby granted under the terms of the MIT License:
|
|
5
|
+
# https://opensource.org/licenses/MIT.
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from deep_code.tools.publish import DatasetPublisher, WorkflowPublisher
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@click.command(name="publish-dataset")
|
|
13
|
+
@click.argument("dataset_config", type=click.Path(exists=True))
|
|
14
|
+
def publish_dataset(dataset_config):
|
|
15
|
+
"""Request publishing a dataset to the open science catalogue.
|
|
16
|
+
"""
|
|
17
|
+
publisher = DatasetPublisher()
|
|
18
|
+
publisher.publish_dataset(dataset_config_path=dataset_config)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@click.command(name="publish-workflow")
|
|
22
|
+
@click.argument("workflow_metadata", type=click.Path(exists=True))
|
|
23
|
+
def publish_workflow(workflow_metadata):
|
|
24
|
+
|
|
25
|
+
workflow_publisher = WorkflowPublisher()
|
|
26
|
+
workflow_publisher.publish_workflow(workflow_config_path=workflow_metadata)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Copyright (c) 2024 by Brockmann Consult GmbH
|
|
4
|
+
# Permissions are hereby granted under the terms of the MIT License:
|
|
5
|
+
# https://opensource.org/licenses/MIT.
|
|
6
|
+
|
|
7
|
+
OSC_SCHEMA_URI = "https://stac-extensions.github.io/osc/v1.0.0-rc.3/schema.json"
|
|
8
|
+
CF_SCHEMA_URI = "https://stac-extensions.github.io/cf/v0.2.0/schema.json"
|
|
9
|
+
OSC_REPO_OWNER = "ESA-EarthCODE"
|
|
10
|
+
OSC_REPO_NAME = "open-science-catalog-metadata-testing"
|
|
11
|
+
OSC_BRANCH_NAME = "add-new-collection"
|
|
12
|
+
DEFAULT_THEME_SCHEME = (
|
|
13
|
+
"https://gcmd.earthdata.nasa.gov/kms/concepts/concept_scheme/sciencekeywords"
|
|
14
|
+
)
|
|
15
|
+
OGC_API_RECORD_SPEC = "http://www.opengis.net/spec/ogcapi-records-1/1.0/req/record-core"
|
|
16
|
+
WF_BRANCH_NAME = "add-new-workflow-from-deepesdl"
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
from unittest.mock import MagicMock, mock_open, patch
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from deep_code.tools.publish import DatasetPublisher
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestDatasetPublisher:
|
|
9
|
+
@patch("deep_code.tools.publish.fsspec.open")
|
|
10
|
+
def test_init_missing_credentials(self, mock_fsspec_open):
|
|
11
|
+
mock_fsspec_open.return_value.__enter__.return_value = mock_open(
|
|
12
|
+
read_data="{}"
|
|
13
|
+
)()
|
|
14
|
+
|
|
15
|
+
with pytest.raises(
|
|
16
|
+
ValueError, match="GitHub credentials are missing in the `.gitaccess` file."
|
|
17
|
+
):
|
|
18
|
+
DatasetPublisher()
|
|
19
|
+
|
|
20
|
+
@patch("deep_code.tools.publish.fsspec.open")
|
|
21
|
+
def test_publish_dataset_missing_ids(self, mock_fsspec_open):
|
|
22
|
+
git_yaml_content = """
|
|
23
|
+
github-username: test-user
|
|
24
|
+
github-token: test-token
|
|
25
|
+
"""
|
|
26
|
+
dataset_yaml_content = """
|
|
27
|
+
collection-id: test-collection
|
|
28
|
+
"""
|
|
29
|
+
mock_fsspec_open.side_effect = [
|
|
30
|
+
mock_open(read_data=git_yaml_content)(),
|
|
31
|
+
mock_open(read_data=dataset_yaml_content)(),
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
publisher = DatasetPublisher()
|
|
35
|
+
|
|
36
|
+
with pytest.raises(
|
|
37
|
+
ValueError, match="Dataset ID or Collection ID missing in the config."
|
|
38
|
+
):
|
|
39
|
+
publisher.publish_dataset("/path/to/dataset-config.yaml")
|
|
40
|
+
|
|
41
|
+
@patch("deep_code.utils.github_automation.os.chdir")
|
|
42
|
+
@patch("deep_code.utils.github_automation.subprocess.run")
|
|
43
|
+
@patch("deep_code.utils.github_automation.os.path.expanduser", return_value="/tmp")
|
|
44
|
+
@patch("requests.post")
|
|
45
|
+
@patch("deep_code.utils.github_automation.GitHubAutomation")
|
|
46
|
+
@patch("deep_code.tools.publish.fsspec.open")
|
|
47
|
+
def test_publish_dataset_success(
|
|
48
|
+
self,
|
|
49
|
+
mock_fsspec_open,
|
|
50
|
+
mock_github_automation,
|
|
51
|
+
mock_requests_post,
|
|
52
|
+
mock_expanduser,
|
|
53
|
+
mock_subprocess_run,
|
|
54
|
+
mock_chdir,
|
|
55
|
+
):
|
|
56
|
+
# Mock the YAML reads
|
|
57
|
+
git_yaml_content = """
|
|
58
|
+
github-username: test-user
|
|
59
|
+
github-token: test-token
|
|
60
|
+
"""
|
|
61
|
+
dataset_yaml_content = """
|
|
62
|
+
dataset_id: test-dataset
|
|
63
|
+
collection_id: test-collection
|
|
64
|
+
documentation_link: http://example.com/doc
|
|
65
|
+
access_link: http://example.com/access
|
|
66
|
+
dataset_status: ongoing
|
|
67
|
+
dataset_region: Global
|
|
68
|
+
osc_theme: ["climate"]
|
|
69
|
+
cf_parameter: []
|
|
70
|
+
"""
|
|
71
|
+
mock_fsspec_open.side_effect = [
|
|
72
|
+
mock_open(read_data=git_yaml_content)(),
|
|
73
|
+
mock_open(read_data=dataset_yaml_content)(),
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
# Mock GitHubAutomation methods
|
|
77
|
+
mock_git = mock_github_automation.return_value
|
|
78
|
+
mock_git.fork_repository.return_value = None
|
|
79
|
+
mock_git.clone_repository.return_value = None
|
|
80
|
+
mock_git.create_branch.return_value = None
|
|
81
|
+
mock_git.add_file.return_value = None
|
|
82
|
+
mock_git.commit_and_push.return_value = None
|
|
83
|
+
mock_git.create_pull_request.return_value = "http://example.com/pr"
|
|
84
|
+
mock_git.clean_up.return_value = None
|
|
85
|
+
|
|
86
|
+
# Mock subprocess.run & os.chdir
|
|
87
|
+
mock_subprocess_run.return_value = None
|
|
88
|
+
mock_chdir.return_value = None
|
|
89
|
+
|
|
90
|
+
# Mock STAC generator
|
|
91
|
+
mock_collection = MagicMock()
|
|
92
|
+
mock_collection.to_dict.return_value = {
|
|
93
|
+
"type": "Collection",
|
|
94
|
+
"id": "test-collection",
|
|
95
|
+
"description": "A test STAC collection",
|
|
96
|
+
"extent": {
|
|
97
|
+
"spatial": {"bbox": [[-180.0, -90.0, 180.0, 90.0]]},
|
|
98
|
+
"temporal": {"interval": [["2023-01-01T00:00:00Z", None]]},
|
|
99
|
+
},
|
|
100
|
+
"links": [],
|
|
101
|
+
"stac_version": "1.0.0",
|
|
102
|
+
}
|
|
103
|
+
with patch("deep_code.tools.publish.OscDatasetStacGenerator") as mock_generator:
|
|
104
|
+
mock_generator.return_value.build_dataset_stac_collection.return_value = (
|
|
105
|
+
mock_collection
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
# Instantiate & publish
|
|
109
|
+
publisher = DatasetPublisher()
|
|
110
|
+
publisher.publish_dataset("/fake/path/to/dataset-config.yaml")
|
|
111
|
+
|
|
112
|
+
# Assert that we called git clone with /tmp/temp_repo
|
|
113
|
+
# Because expanduser("~") is now patched to /tmp, the actual path is /tmp/temp_repo
|
|
114
|
+
auth_url = "https://test-user:test-token@github.com/test-user/open-science-catalog-metadata-testing.git"
|
|
115
|
+
mock_subprocess_run.assert_any_call(
|
|
116
|
+
["git", "clone", auth_url, "/tmp/temp_repo"], check=True
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Also confirm we changed directories to /tmp/temp_repo
|
|
120
|
+
mock_chdir.assert_any_call("/tmp/temp_repo")
|