Skip to content

Commit 3b65e06

Browse files
committed
refactor to address comments
1 parent 8abb345 commit 3b65e06

2 files changed

Lines changed: 30 additions & 16 deletions

File tree

deep_code/cli/publish.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# https://opensource.org/licenses/MIT.
66

77
from pathlib import Path
8-
from typing import Literal, Optional, Tuple
8+
from typing import Literal
99

1010
import click
1111
import yaml
@@ -38,11 +38,11 @@
3838

3939

4040
def _validate_inputs(
41-
dataset_config: Optional[str], workflow_config: Optional[str], mode: str
41+
dataset_config: str | None, workflow_config: str | None, mode: str
4242
):
4343
mode = mode.lower()
4444

45-
def ensure_file(path: Optional[str], label: str):
45+
def ensure_file(path: str | None, label: str):
4646
if path is None:
4747
raise click.UsageError(f"{label} is required but was not provided.")
4848
if not Path(path).is_file():
@@ -96,12 +96,12 @@ def _detect_config_type(path: Path) -> Literal["dataset", "workflow"]:
9696

9797

9898
def _assign_configs(
99-
pos_first: Optional[str],
100-
pos_second: Optional[str],
99+
pos_first: str | None,
100+
pos_second: str | None,
101101
mode: Mode,
102-
explicit_dataset: Optional[str],
103-
explicit_workflow: Optional[str],
104-
) -> Tuple[Optional[str], Optional[str]]:
102+
explicit_dataset: str | None,
103+
explicit_workflow: str | None,
104+
) -> tuple[str | None, str | None]:
105105
"""
106106
Decide which file is dataset vs workflow.
107107
Precedence: explicit flags > positional + detection.
@@ -121,7 +121,7 @@ def _assign_configs(
121121
return ds, wf
122122

123123
# Helper to assign a single positional file to the missing slot
124-
def _assign_single(p: str):
124+
def _assign_single(p: str) -> tuple[str | None, str | None]:
125125
nonlocal ds, wf
126126
if ds and wf:
127127
raise click.UsageError(

deep_code/tools/publish.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Copyright (c) 2025 by Brockmann Consult GmbH
33
# Permissions are hereby granted under the terms of the MIT License:
44
# https://opensource.org/licenses/MIT.
5-
65
import copy
76
import logging
87
from datetime import datetime
@@ -63,7 +62,9 @@ def publish_files(
6362
pr_title: str,
6463
pr_body: str,
6564
base_branch: str = "main",
66-
sync_strategy: str = "merge", # 'ff' | 'rebase' | 'merge'
65+
sync_strategy: Literal[
66+
"ff", "rebase", "merge"
67+
] = "merge", # 'ff' | 'rebase' | 'merge'
6768
) -> str:
6869
"""Publish multiple files to a new branch and open a PR.
6970
@@ -73,16 +74,29 @@ def publish_files(
7374
commit_message: Commit message for all changes.
7475
pr_title: Title of the pull request.
7576
pr_body: Description/body of the pull request.
76-
base_branch: base branch, default main
77-
sync_strategy: git sync strategy
77+
base_branch: Base branch to branch from and open the PR against (default: "main")
78+
sync_strategy: How to sync local with the remote base before pushing:
79+
- "ff": Fast-forward only (no merge commits; fails if FF not possible).
80+
- "rebase": Rebase local changes onto the updated base branch.
81+
- "merge": Create a merge commit (default).
7882
7983
Returns:
8084
URL of the created pull request.
85+
86+
Raises:
87+
ValueError: If an unsupported sync_strategy is provided.
8188
"""
89+
90+
if sync_strategy not in {"ff", "rebase", "merge"}:
91+
raise ValueError(
92+
f'Invalid sync_strategy="{sync_strategy}". '
93+
'Accepted values are "ff", "rebase", "merge".'
94+
)
95+
8296
try:
8397
# Ensure local clone and remotes are ready
8498
self.github_automation.clone_sync_repository()
85-
# *** Sync fork with upstream before creating the branch/committing ***
99+
# Sync fork with upstream before creating the branch/committing
86100
self.github_automation.sync_fork_with_upstream(
87101
base_branch=base_branch, strategy=sync_strategy
88102
)
@@ -134,15 +148,15 @@ def __init__(
134148
self.collection_id = ""
135149
self.workflow_title = ""
136150

137-
# Paths to configuration files, may be optional
151+
# Paths to configuration files, can be optional
138152
self.dataset_config_path = dataset_config_path
139153
self.workflow_config_path = workflow_config_path
140154

141155
# Config dicts (loaded lazily)
142156
self.dataset_config: dict[str, Any] = {}
143157
self.workflow_config: dict[str, Any] = {}
144158

145-
# Values that may be set from configs (lazy)
159+
# Values that may be set from configs
146160
self.collection_id: str | None = None
147161
self.workflow_title: str | None = None
148162
self.workflow_id: str | None = None

0 commit comments

Comments
 (0)