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
61 changes: 48 additions & 13 deletions src/core/project_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
update_workflow_files,
)

DEFAULT_TEMPLATE_URL = "https://github.com/SeamusMullan/PluginTemplate.git"


class ProjectWorker(QObject):
"""Worker class that handles project generation in a separate thread"""
Expand Down Expand Up @@ -61,21 +63,41 @@ def run(self):
self.finished.emit()

except Exception as e:
self._cleanup_on_failure()
self.error.emit(f"Project generation failed: {e!s}")
self.finished.emit()

def _cleanup_on_failure(self) -> None:
"""Remove a partially-created output directory after a generation failure."""
output_dir = self.params.get("output_directory", "")
if output_dir and os.path.exists(output_dir):
try:
shutil.rmtree(output_dir, onerror=self.remove_readonly)
self.progress.emit("Cleaned up partial output directory")
except Exception:
pass
Comment on lines +77 to +78

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_cleanup_on_failure() suppresses all exceptions during shutil.rmtree(...) with a bare except Exception: pass. If cleanup fails (permissions, locked files, etc.) it will be silently ignored, leaving partial output behind with no visibility. Consider at least emitting a progress/error message (or logging) with the exception details so failures are diagnosable.

Suggested change
except Exception:
pass
except Exception as e:
self.error.emit(
f"Failed to clean up partial output directory '{output_dir}': {e!s}"
)

Copilot uses AI. Check for mistakes.

def clone_template_repo(self):
"""Clone the template repository"""
output_dir = self.params.get("output_directory", "")
if not output_dir:
raise RuntimeError("Output directory is not specified")

if os.path.exists(output_dir):
raise RuntimeError(f"Output directory already exists: {output_dir}")

fork_url = self.params.get("fork_url", "") or DEFAULT_TEMPLATE_URL

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fork_url falls back to DEFAULT_TEMPLATE_URL only when the param is falsy. A whitespace-only value (e.g. " ") will bypass the fallback and be passed to git clone, which will fail. Consider normalizing with .strip() (similar to plugin_code/version) before applying the default URL.

Suggested change
fork_url = self.params.get("fork_url", "") or DEFAULT_TEMPLATE_URL
fork_url = str(self.params.get("fork_url", "")).strip() or DEFAULT_TEMPLATE_URL

Copilot uses AI. Check for mistakes.

try:
self.progress.emit(f"Cloning template repository: {self.params['fork_url']}")
self.progress.emit(f"Cloning template repository: {fork_url}")
self.progress_value.emit(5)

subprocess.run(
[
"git",
"clone",
self.params["fork_url"],
self.params["output_directory"],
fork_url,
output_dir,
],
check=True,
capture_output=True,
Expand Down Expand Up @@ -158,16 +180,18 @@ def fetch_optional_submodules(self):

def prepare_project_variables(self):
"""Prepare variables for template substitution"""
# Read version from file if it exists
version_path = os.path.join(self.params["output_directory"], "VERSION")
if os.path.exists(version_path):
with open(version_path) as f:
version = f.read().strip()
else:
version = "0.0.1"

# Generate unique plugin code
plugin_code = generate_plugin_id()
# Use version from params if provided; fall back to VERSION file or default.
version = self.params.get("version", "").strip()
if not version:
version_path = os.path.join(self.params["output_directory"], "VERSION")
if os.path.exists(version_path):
with open(version_path) as f:
version = f.read().strip()
else:
version = "0.0.1"

# Use plugin code from params if provided, otherwise generate a unique one.
plugin_code = (self.params.get("plugin_code", "") or "").strip() or generate_plugin_id()

# Format selection
formats = []
Expand All @@ -179,6 +203,8 @@ def prepare_project_variables(self):
formats.append("AU")
if self.options.get("auv3", False):
formats.append("AUv3")
if self.options.get("clap", False):
formats.append("CLAP")

# Format string for CMake
formats_string = f"FORMATS {' '.join(formats)}"
Expand Down Expand Up @@ -297,6 +323,14 @@ def init_git_repo(self):
text=True,
)

# Provide fallback git author info for CI or clean environments that
# have no global git user.name / user.email configured.
env = os.environ.copy()
env.setdefault("GIT_AUTHOR_NAME", "Plugin Configurator")
env.setdefault("GIT_AUTHOR_EMAIL", "noreply@direktdsp.com")
env.setdefault("GIT_COMMITTER_NAME", "Plugin Configurator")
env.setdefault("GIT_COMMITTER_EMAIL", "noreply@direktdsp.com")

# Commit
subprocess.run(
[
Expand All @@ -309,6 +343,7 @@ def init_git_repo(self):
check=True,
capture_output=True,
text=True,
env=env,
)

self.progress.emit("Git repository initialized successfully")
Expand Down
Loading
Loading