Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions deep_code/cli/generate_config.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 2 additions & 0 deletions deep_code/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import click

from deep_code.cli.generate_config import generate_config
from deep_code.cli.publish import publish


Expand All @@ -16,6 +17,7 @@ def main():


main.add_command(publish)
main.add_command(generate_config)

if __name__ == "__main__":
main()
3 changes: 2 additions & 1 deletion deep_code/cli/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
77 changes: 72 additions & 5 deletions deep_code/tools/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)