deep-code 0.0.1__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/LICENSE +21 -0
- deep_code-0.0.1/PKG-INFO +154 -0
- deep_code-0.0.1/README.md +123 -0
- deep_code-0.0.1/deep_code/__init__.py +24 -0
- deep_code-0.0.1/deep_code/cli/__init__.py +3 -0
- deep_code-0.0.1/deep_code/cli/main.py +21 -0
- deep_code-0.0.1/deep_code/cli/publish.py +21 -0
- deep_code-0.0.1/deep_code/constants.py +31 -0
- deep_code-0.0.1/deep_code/tests/tools/__init__.py +3 -0
- deep_code-0.0.1/deep_code/tests/tools/test_publish.py +108 -0
- deep_code-0.0.1/deep_code/tests/utils/__init__.py +3 -0
- deep_code-0.0.1/deep_code/tests/utils/test_dataset_stac_generator.py +277 -0
- deep_code-0.0.1/deep_code/tests/utils/test_github_automation.py +171 -0
- deep_code-0.0.1/deep_code/tests/utils/test_ogc_api_record.py +243 -0
- deep_code-0.0.1/deep_code/tests/utils/test_ogc_record_generator.py +60 -0
- deep_code-0.0.1/deep_code/tests/utils/test_osc_extension.py +117 -0
- deep_code-0.0.1/deep_code/tools/__init__.py +3 -0
- deep_code-0.0.1/deep_code/tools/check.py +4 -0
- deep_code-0.0.1/deep_code/tools/new.py +5 -0
- deep_code-0.0.1/deep_code/tools/publish.py +419 -0
- deep_code-0.0.1/deep_code/tools/register.py +0 -0
- deep_code-0.0.1/deep_code/tools/setup_ci.py +1 -0
- deep_code-0.0.1/deep_code/tools/test.py +2 -0
- deep_code-0.0.1/deep_code/utils/__init__.py +3 -0
- deep_code-0.0.1/deep_code/utils/dataset_stac_generator.py +547 -0
- deep_code-0.0.1/deep_code/utils/github_automation.py +145 -0
- deep_code-0.0.1/deep_code/utils/helper.py +14 -0
- deep_code-0.0.1/deep_code/utils/ogc_api_record.py +268 -0
- deep_code-0.0.1/deep_code/utils/ogc_record_generator.py +69 -0
- deep_code-0.0.1/deep_code/utils/osc_extension.py +189 -0
- deep_code-0.0.1/deep_code/version.py +22 -0
- deep_code-0.0.1/deep_code.egg-info/PKG-INFO +154 -0
- deep_code-0.0.1/deep_code.egg-info/SOURCES.txt +37 -0
- deep_code-0.0.1/deep_code.egg-info/dependency_links.txt +1 -0
- deep_code-0.0.1/deep_code.egg-info/entry_points.txt +2 -0
- deep_code-0.0.1/deep_code.egg-info/requires.txt +18 -0
- deep_code-0.0.1/deep_code.egg-info/top_level.txt +2 -0
- deep_code-0.0.1/pyproject.toml +60 -0
- deep_code-0.0.1/setup.cfg +4 -0
deep_code-0.0.1/LICENSE
ADDED
|
@@ -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.
|
deep_code-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: deep_code
|
|
3
|
+
Version: 0.0.1
|
|
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
|
+
The CLI retrieves the Git username and personal access token from a hidden file named
|
|
91
|
+
.gitaccess. Ensure this file is located in the same directory where you execute the CLI
|
|
92
|
+
command.
|
|
93
|
+
|
|
94
|
+
#### .gitaccess example
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
github-username: your-git-user
|
|
98
|
+
github-token: personal access token
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### deep-code publish
|
|
102
|
+
|
|
103
|
+
Publish the experiment, workflow and dataset which is a result of an experiment to
|
|
104
|
+
the EarthCODE open-science catalog.
|
|
105
|
+
|
|
106
|
+
```commandline
|
|
107
|
+
deep-code publish /path/to/dataset-config.yaml /path/to/workflow-config.yaml
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### dataset-config.yaml example
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
dataset_id: hydrology-1D-0.009deg-100x60x60-3.0.2.zarr
|
|
114
|
+
collection_id: hydrology
|
|
115
|
+
osc_themes:
|
|
116
|
+
- Land
|
|
117
|
+
- Oceans
|
|
118
|
+
# non-mandatory
|
|
119
|
+
documentation_link: https://deepesdl.readthedocs.io/en/latest/datasets/hydrology-1D-0.009deg-100x60x60-3.0.2.zarr/
|
|
120
|
+
access_link: s3://test
|
|
121
|
+
dataset_status: completed
|
|
122
|
+
osc_region: global
|
|
123
|
+
cf_parameter:
|
|
124
|
+
- name: hydrology
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
dataset-id has to be a valid dataset-id from `deep-esdl-public` s3 bucket or your team
|
|
128
|
+
bucket.
|
|
129
|
+
|
|
130
|
+
#### workflow-config.yaml example
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
workflow_id: "esa-cci-permafrost"
|
|
134
|
+
properties:
|
|
135
|
+
title: "ESA CCI permafrost"
|
|
136
|
+
description: "cube generation workflow for esa-cci-permafrost"
|
|
137
|
+
keywords:
|
|
138
|
+
- Earth Science
|
|
139
|
+
themes:
|
|
140
|
+
- cryosphere
|
|
141
|
+
license: proprietary
|
|
142
|
+
jupyter_kernel_info:
|
|
143
|
+
name: deepesdl-xcube-1.8.3
|
|
144
|
+
python_version: 3.11
|
|
145
|
+
env_file: "https://github.com/deepesdl/cube-gen/blob/main/Permafrost/environment.yml"
|
|
146
|
+
jupyter_notebook_url: "https://github.com/deepesdl/cube-gen/blob/main/Permafrost/Create-CCI-Permafrost-cube-EarthCODE.ipynb"
|
|
147
|
+
contact:
|
|
148
|
+
- name: Tejas Morbagal Harish
|
|
149
|
+
organization: Brockmann Consult GmbH
|
|
150
|
+
links:
|
|
151
|
+
- rel: "about"
|
|
152
|
+
type: "text/html"
|
|
153
|
+
href: "https://www.brockmann-consult.de/"
|
|
154
|
+
```
|
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
The CLI retrieves the Git username and personal access token from a hidden file named
|
|
60
|
+
.gitaccess. Ensure this file is located in the same directory where you execute the CLI
|
|
61
|
+
command.
|
|
62
|
+
|
|
63
|
+
#### .gitaccess example
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
github-username: your-git-user
|
|
67
|
+
github-token: personal access token
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### deep-code publish
|
|
71
|
+
|
|
72
|
+
Publish the experiment, workflow and dataset which is a result of an experiment to
|
|
73
|
+
the EarthCODE open-science catalog.
|
|
74
|
+
|
|
75
|
+
```commandline
|
|
76
|
+
deep-code publish /path/to/dataset-config.yaml /path/to/workflow-config.yaml
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### dataset-config.yaml example
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
dataset_id: hydrology-1D-0.009deg-100x60x60-3.0.2.zarr
|
|
83
|
+
collection_id: hydrology
|
|
84
|
+
osc_themes:
|
|
85
|
+
- Land
|
|
86
|
+
- Oceans
|
|
87
|
+
# non-mandatory
|
|
88
|
+
documentation_link: https://deepesdl.readthedocs.io/en/latest/datasets/hydrology-1D-0.009deg-100x60x60-3.0.2.zarr/
|
|
89
|
+
access_link: s3://test
|
|
90
|
+
dataset_status: completed
|
|
91
|
+
osc_region: global
|
|
92
|
+
cf_parameter:
|
|
93
|
+
- name: hydrology
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
dataset-id has to be a valid dataset-id from `deep-esdl-public` s3 bucket or your team
|
|
97
|
+
bucket.
|
|
98
|
+
|
|
99
|
+
#### workflow-config.yaml example
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
workflow_id: "esa-cci-permafrost"
|
|
103
|
+
properties:
|
|
104
|
+
title: "ESA CCI permafrost"
|
|
105
|
+
description: "cube generation workflow for esa-cci-permafrost"
|
|
106
|
+
keywords:
|
|
107
|
+
- Earth Science
|
|
108
|
+
themes:
|
|
109
|
+
- cryosphere
|
|
110
|
+
license: proprietary
|
|
111
|
+
jupyter_kernel_info:
|
|
112
|
+
name: deepesdl-xcube-1.8.3
|
|
113
|
+
python_version: 3.11
|
|
114
|
+
env_file: "https://github.com/deepesdl/cube-gen/blob/main/Permafrost/environment.yml"
|
|
115
|
+
jupyter_notebook_url: "https://github.com/deepesdl/cube-gen/blob/main/Permafrost/Create-CCI-Permafrost-cube-EarthCODE.ipynb"
|
|
116
|
+
contact:
|
|
117
|
+
- name: Tejas Morbagal Harish
|
|
118
|
+
organization: Brockmann Consult GmbH
|
|
119
|
+
links:
|
|
120
|
+
- rel: "about"
|
|
121
|
+
type: "text/html"
|
|
122
|
+
href: "https://www.brockmann-consult.de/"
|
|
123
|
+
```
|
|
@@ -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,21 @@
|
|
|
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
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@click.group()
|
|
13
|
+
def main():
|
|
14
|
+
"""Deep Code CLI."""
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
main.add_command(publish)
|
|
19
|
+
|
|
20
|
+
if __name__ == "__main__":
|
|
21
|
+
main()
|
|
@@ -0,0 +1,21 @@
|
|
|
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 Publisher
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@click.command(name="publish")
|
|
13
|
+
@click.argument("dataset_config", type=click.Path(exists=True))
|
|
14
|
+
@click.argument("workflow_config", type=click.Path(exists=True))
|
|
15
|
+
def publish(dataset_config, workflow_config):
|
|
16
|
+
"""Request publishing a dataset to the open science catalogue.
|
|
17
|
+
"""
|
|
18
|
+
publisher = Publisher(
|
|
19
|
+
dataset_config_path=dataset_config, workflow_config_path=workflow_config
|
|
20
|
+
)
|
|
21
|
+
publisher.publish_all()
|
|
@@ -0,0 +1,31 @@
|
|
|
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/schema.json"
|
|
8
|
+
CF_SCHEMA_URI = "https://stac-extensions.github.io/cf/v0.2.0/schema.json"
|
|
9
|
+
THEMES_SCHEMA_URI = "https://stac-extensions.github.io/themes/v1.0.0/schema.json"
|
|
10
|
+
OSC_THEME_SCHEME = "https://github.com/stac-extensions/osc#theme"
|
|
11
|
+
OSC_REPO_OWNER = "ESA-EarthCODE"
|
|
12
|
+
OSC_REPO_NAME = "open-science-catalog-metadata"
|
|
13
|
+
OSC_BRANCH_NAME = "add-new-collection"
|
|
14
|
+
DEFAULT_THEME_SCHEME = (
|
|
15
|
+
"https://gcmd.earthdata.nasa.gov/kms/concepts/concept_scheme/sciencekeywords"
|
|
16
|
+
)
|
|
17
|
+
OGC_API_RECORD_SPEC = "http://www.opengis.net/spec/ogcapi-records-1/1.0/req/record-core"
|
|
18
|
+
WF_BRANCH_NAME = "add-new-workflow-from-deepesdl"
|
|
19
|
+
VARIABLE_BASE_CATALOG_SELF_HREF = "https://esa-earthcode.github.io/open-science-catalog-metadata/variables/catalog.json"
|
|
20
|
+
PRODUCT_BASE_CATALOG_SELF_HREF = "https://esa-earthcode.github.io/open-science-catalog-metadata/products/catalog.json"
|
|
21
|
+
DEEPESDL_COLLECTION_SELF_HREF = (
|
|
22
|
+
"https://esa-earthcode.github.io/open-science-catalog-metadata/projects/deepesdl"
|
|
23
|
+
"/collection.json"
|
|
24
|
+
)
|
|
25
|
+
BASE_URL_OSC = "https://esa-earthcode.github.io/open-science-catalog-metadata"
|
|
26
|
+
EXPERIMENT_BASE_CATALOG_SELF_HREF = "https://esa-earthcode.github.io/open-science-catalog-metadata/experiments/catalog.json"
|
|
27
|
+
WORKFLOW_BASE_CATALOG_SELF_HREF = (
|
|
28
|
+
"https://esa-earthcode.github.io/open-science-catalog-metadata/workflows/catalog"
|
|
29
|
+
".json"
|
|
30
|
+
)
|
|
31
|
+
PROJECT_COLLECTION_NAME = "deep-earth-system-data-lab"
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from unittest.mock import patch, mock_open, MagicMock
|
|
3
|
+
import json
|
|
4
|
+
import yaml
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import tempfile
|
|
7
|
+
from pystac import Catalog
|
|
8
|
+
|
|
9
|
+
from deep_code.tools.publish import Publisher
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestPublisher(unittest.TestCase):
|
|
13
|
+
@patch("fsspec.open")
|
|
14
|
+
@patch("deep_code.tools.publish.GitHubPublisher")
|
|
15
|
+
def setUp(self, mock_github_publisher, mock_fsspec_open):
|
|
16
|
+
# Mock GitHubPublisher to avoid reading .gitaccess
|
|
17
|
+
self.mock_github_publisher_instance = MagicMock()
|
|
18
|
+
mock_github_publisher.return_value = self.mock_github_publisher_instance
|
|
19
|
+
|
|
20
|
+
# Mock dataset and workflow config files
|
|
21
|
+
self.dataset_config = {
|
|
22
|
+
"collection_id": "test-collection",
|
|
23
|
+
"dataset_id": "test-dataset",
|
|
24
|
+
}
|
|
25
|
+
self.workflow_config = {
|
|
26
|
+
"properties": {"title": "Test Workflow"},
|
|
27
|
+
"workflow_id": "test-workflow",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# Mock fsspec.open for config files
|
|
31
|
+
self.mock_fsspec_open = mock_fsspec_open
|
|
32
|
+
self.mock_fsspec_open.side_effect = [
|
|
33
|
+
mock_open(read_data=yaml.dump(self.dataset_config)).return_value,
|
|
34
|
+
mock_open(read_data=yaml.dump(self.workflow_config)).return_value,
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
# Initialize Publisher
|
|
38
|
+
self.publisher = Publisher(
|
|
39
|
+
dataset_config_path="test-dataset-config.yaml",
|
|
40
|
+
workflow_config_path="test-workflow-config.yaml",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def test_normalize_name(self):
|
|
44
|
+
self.assertEqual(Publisher._normalize_name("Test Name"), "test-name")
|
|
45
|
+
self.assertEqual(Publisher._normalize_name("Test Name"), "test---name")
|
|
46
|
+
self.assertIsNone(Publisher._normalize_name(""))
|
|
47
|
+
self.assertIsNone(Publisher._normalize_name(None))
|
|
48
|
+
|
|
49
|
+
def test_write_to_file(self):
|
|
50
|
+
# Create a temporary file
|
|
51
|
+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
|
52
|
+
file_path = temp_file.name
|
|
53
|
+
|
|
54
|
+
# Test data
|
|
55
|
+
data = {"key": "value"}
|
|
56
|
+
|
|
57
|
+
# Call the method
|
|
58
|
+
Publisher._write_to_file(file_path, data)
|
|
59
|
+
|
|
60
|
+
# Read the file and verify its content
|
|
61
|
+
with open(file_path, "r") as f:
|
|
62
|
+
content = json.load(f)
|
|
63
|
+
self.assertEqual(content, data)
|
|
64
|
+
|
|
65
|
+
# Clean up
|
|
66
|
+
Path(file_path).unlink()
|
|
67
|
+
|
|
68
|
+
def test_update_base_catalog(self):
|
|
69
|
+
# Create a mock Catalog
|
|
70
|
+
catalog = Catalog(id="test-catalog", description="Test Catalog")
|
|
71
|
+
|
|
72
|
+
# Mock file path and item ID
|
|
73
|
+
catalog_path = "test-catalog.json"
|
|
74
|
+
item_id = "test-item"
|
|
75
|
+
self_href = "https://example.com/catalog.json"
|
|
76
|
+
|
|
77
|
+
self.publisher.workflow_title = "Test Workflow"
|
|
78
|
+
|
|
79
|
+
# Mock the Catalog.from_file method
|
|
80
|
+
with patch("pystac.Catalog.from_file", return_value=catalog):
|
|
81
|
+
updated_catalog = self.publisher._update_base_catalog(
|
|
82
|
+
catalog_path, item_id, self_href
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Assertions
|
|
86
|
+
self.assertEqual(updated_catalog.get_self_href(), self_href)
|
|
87
|
+
self.assertIsInstance(updated_catalog, Catalog)
|
|
88
|
+
|
|
89
|
+
def test_read_config_files(self):
|
|
90
|
+
# Mock dataset and workflow config files
|
|
91
|
+
dataset_config = {
|
|
92
|
+
"collection_id": "test-collection",
|
|
93
|
+
"dataset_id": "test-dataset",
|
|
94
|
+
}
|
|
95
|
+
workflow_config = {
|
|
96
|
+
"properties": {"title": "Test Workflow"},
|
|
97
|
+
"workflow_id": "test-workflow",
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# Mock fsspec.open for config files
|
|
101
|
+
self.mock_fsspec_open.side_effect = [
|
|
102
|
+
mock_open(read_data=yaml.dump(dataset_config)).return_value,
|
|
103
|
+
mock_open(read_data=yaml.dump(workflow_config)).return_value,
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
# Assertions
|
|
107
|
+
self.assertEqual(self.publisher.dataset_config, dataset_config)
|
|
108
|
+
self.assertEqual(self.publisher.workflow_config, workflow_config)
|