From 09746de28295f7ec9ba11be20655a69746e08edb Mon Sep 17 00:00:00 2001 From: tejas Date: Fri, 11 Apr 2025 11:45:53 +0200 Subject: [PATCH 1/2] generate config templates for publication --- deep_code/cli/generate_config.py | 22 +++++++++ deep_code/cli/main.py | 2 + deep_code/cli/publish.py | 3 +- deep_code/tools/new.py | 77 +++++++++++++++++++++++++++++--- 4 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 deep_code/cli/generate_config.py diff --git a/deep_code/cli/generate_config.py b/deep_code/cli/generate_config.py new file mode 100644 index 0000000..ce1c286 --- /dev/null +++ b/deep_code/cli/generate_config.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2025 by Brockmann Consult GmbH +# Permissions are hereby granted under the terms of the MIT License: +# https://opensource.org/licenses/MIT. + +import click + +from deep_code.tools.new import TemplateGenerator + + +@click.command(name="generate-config") +@click.option( + "--output-dir", + "-o", + type=click.Path(exists=True, file_okay=False, writable=True), + default=".", + help="Output directory for templates", +) +def generate_config(output_dir): + TemplateGenerator.generate_workflow_template(f"{output_dir}/workflow_config.yaml") + TemplateGenerator.generate_dataset_template(f"{output_dir}/dataset_config.yaml") diff --git a/deep_code/cli/main.py b/deep_code/cli/main.py index e4f5380..67c30fb 100644 --- a/deep_code/cli/main.py +++ b/deep_code/cli/main.py @@ -6,6 +6,7 @@ import click +from deep_code.cli.generate_config import generate_config from deep_code.cli.publish import publish @@ -16,6 +17,7 @@ def main(): main.add_command(publish) +main.add_command(generate_config) if __name__ == "__main__": main() diff --git a/deep_code/cli/publish.py b/deep_code/cli/publish.py index 39db233..d3c9001 100644 --- a/deep_code/cli/publish.py +++ b/deep_code/cli/publish.py @@ -13,7 +13,8 @@ @click.argument("dataset_config", type=click.Path(exists=True)) @click.argument("workflow_config", type=click.Path(exists=True)) @click.option( - "--environment", "-e", + "--environment", + "-e", type=click.Choice(["production", "staging", "testing"], case_sensitive=False), default="production", help="Target environment for publishing (production, staging, testing)", diff --git a/deep_code/tools/new.py b/deep_code/tools/new.py index 89e62c5..1cfd2e6 100644 --- a/deep_code/tools/new.py +++ b/deep_code/tools/new.py @@ -4,8 +4,75 @@ # Permissions are hereby granted under the terms of the MIT License: # https://opensource.org/licenses/MIT. -"""Logic for initializing repositories - Initialize a GitHub repository with the proposed configurations files, an initial - workflow notebook template (e.g. workflow.ipynb), a template Python package (code and -pyproject.toml), and a template setup for documentation (e.g., using mkdocs), -setup of the build pipeline""" +from typing import Optional + +import yaml + + +class TemplateGenerator: + @staticmethod + def generate_workflow_template(output_path: Optional[str] = None) -> str: + """Generate a complete template with all possible keys and placeholder values""" + + template = { + "workflow_id": "[WORKFLOW_ID]", + "properties": { + "title": "[TITLE]", + "description": "[DESCRIPTION]", + "keywords": ["[KEYWORD1]", "[KEYWORD2]"], + "themes": ["[THEME1]", "[THEME2]"], + "license": "[LICENSE_TYPE]", + "jupyter_kernel_info": { + "name": "[DEEPESDL_KERNEL_NAME]", + "python_version": "[PYTHON_VERSION]", + "env_file": "[ENV_FILE_URL_IN_GIT]", + }, + }, + "jupyter_notebook_url": "[NOTEBOOK_URL]", + "contact": [ + { + "name": "[CONTACT_NAME]", + "organization": "[ORGANIZATION]", + "links": [ + { + "rel": "about", + "type": "text/html", + "href": "[ORGANIZATION_URL]", + } + ], + } + ], + } + + yaml_str = yaml.dump( + template, sort_keys=False, width=1000, default_flow_style=False + ) + + if output_path: + with open(output_path, "w") as f: + f.write("# Complete Workflow Configuration Template\n") + f.write("# Replace all [PLACEHOLDER] values with your actual data\n\n") + f.write(yaml_str) + + @staticmethod + def generate_dataset_template(output_path: Optional[str] = None) -> str: + """Generate a complete dataset template with all possible keys and placeholder values""" + + template = { + "dataset_id": "[DATASET_ID].zarr", + "collection_id": "[COLLECTION_ID]", + "osc_themes": ["[THEME1]", "[THEME2]"], + "osc_region": "[REGION]", + "dataset_status": "[STATUS]", + "documentation_link": "[DOCS_URL]", + } + + yaml_str = yaml.dump( + template, sort_keys=False, width=1000, default_flow_style=False + ) + + if output_path: + with open(output_path, "w") as f: + f.write("# Complete Dataset Configuration Template\n") + f.write("# Replace all [PLACEHOLDER] values with your actual data\n\n") + f.write(yaml_str) From e7703d436efab6a3ec2ac23e9a22d8f20ede82dd Mon Sep 17 00:00:00 2001 From: tejas Date: Fri, 11 Apr 2025 15:25:39 +0200 Subject: [PATCH 2/2] update README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 1661314..d82ecce 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,24 @@ command. github-username: your-git-user github-token: personal access token ``` +### deep-code generate-config + +Generates starter configuration templates for publishing to EarthCODE openscience +catalog. + +#### Usage +``` +deep-code generate-config [OPTIONS] +``` + +#### Options + --output-dir, -o : Output directory (default: current) + +#### Examples: +``` +deep-code generate-config +deep-code generate-config -o ./configs +``` ### deep-code publish