Skip to content
Open
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
21 changes: 3 additions & 18 deletions src/rhiza/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,10 @@ def init(
help="Target Git hosting platform (github or gitlab). Determines which CI/CD files to include. "
"If not provided, will prompt interactively.",
),
language: str = typer.Option(
"python",
"--language",
help="Programming language for the project (python, go, etc.). Defaults to 'python'.",
),
template_repository: str = typer.Option(
None,
"--template-repository",
help=(
"Custom template repository (format: owner/repo). "
"Defaults to 'jebel-quant/rhiza' for Python or 'jebel-quant/rhiza-go' for Go."
),
help=("Custom template repository (format: owner/repo). Defaults to 'jebel-quant/rhiza'."),
),
template_branch: str = typer.Option(
None,
Expand All @@ -124,32 +116,25 @@ def init(
Creates a default `.rhiza/template.yml` configuration file if one
doesn't exist, or validates the existing configuration.

The default template includes common project files based on the language.
The default template includes common project files.
The --git-host option determines which CI/CD configuration to include:
- github: includes .github folder (GitHub Actions workflows)
- gitlab: includes .gitlab-ci.yml (GitLab CI configuration)

The --language option determines the project type and files created:
- python: creates pyproject.toml, src/, and Python project structure
- go: creates minimal structure (you'll need to run 'go mod init')

Examples:
rhiza init
rhiza init --language go
rhiza init --language python --git-host github
rhiza init --git-host gitlab
rhiza init --git-host github
rhiza init --template-repository myorg/my-templates
rhiza init --template-repository myorg/my-templates --template-branch develop
rhiza init /path/to/project
rhiza init .. --language go
"""
if not init_cmd(
target,
project_name=project_name,
package_name=package_name,
with_dev_dependencies=with_dev_dependencies,
git_host=git_host,
language=language,
template_repository=template_repository,
template_branch=template_branch,
):
Expand Down
75 changes: 24 additions & 51 deletions tests/test_commands/test_init_language.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for language-specific init functionality."""
"""Tests for template-repository-based init functionality."""

from unittest.mock import patch

Expand All @@ -7,42 +7,38 @@
from rhiza.commands.init import init


class TestInitWithLanguage:
"""Tests for init command with language parameter."""
class TestInitWithTemplateRepository:
"""Tests for init command with template repository selection."""

def test_init_with_go_language(self, tmp_path):
"""Test that init with go language creates Go-specific structure."""
init(tmp_path, git_host="github", language="go")
@patch("rhiza.commands.init._check_template_repository_reachable", return_value=True)
def test_init_with_go_template_repository(self, mock_check, tmp_path):
"""Test that init with go template repository creates correct config."""
init(tmp_path, git_host="github", template_repository="jebel-quant/rhiza-go")

# Verify template.yml was created with go language
# Verify template.yml was created with go repository
template_file = tmp_path / ".rhiza" / "template.yml"
assert template_file.exists()

with open(template_file) as f:
config = yaml.safe_load(f)

assert config["repository"] == "jebel-quant/rhiza-go"
assert config["language"] == "go"

# Verify Go-specific structure was NOT created (user should run go mod init)
assert not (tmp_path / "go.mod").exists()
assert not (tmp_path / "src").exists()
assert not (tmp_path / "pyproject.toml").exists()

# Only README should be created
assert (tmp_path / "README.md").exists()
# The language parameter defaults to "python" internally; RhizaTemplate.to_yaml()
# omits the language field when it equals the default "python" value.
assert "language" not in config

def test_init_with_python_language_explicit(self, tmp_path):
"""Test that init with explicit python language creates Python structure."""
init(tmp_path, git_host="github", language="python")
def test_init_with_python_template_repository(self, tmp_path):
"""Test that init with default python template repository creates Python structure."""
init(tmp_path, git_host="github")

# Verify template.yml was created WITHOUT language field (it's default)
template_file = tmp_path / ".rhiza" / "template.yml"
with open(template_file) as f:
config = yaml.safe_load(f)

assert config["repository"] == "jebel-quant/rhiza"
# Language field should not be in config (it's the default)
# RhizaTemplate.to_yaml() omits the language field when it equals the
# default "python" value, so no language key is written to the file.
assert "language" not in config

# Verify Python-specific structure
Expand All @@ -51,62 +47,39 @@ def test_init_with_python_language_explicit(self, tmp_path):
assert (tmp_path / "README.md").exists()

def test_init_defaults_to_python(self, tmp_path):
"""Test that init defaults to python when no language specified."""
"""Test that init defaults to python when no template repository specified."""
init(tmp_path, git_host="github")

# Verify Python structure was created
assert (tmp_path / "pyproject.toml").exists()
assert (tmp_path / "src").is_dir()

@patch("rhiza.commands.init._check_template_repository_reachable", return_value=True)
def test_init_go_with_custom_template_repository(self, mock_check, tmp_path):
"""Test that custom template repository works with Go language."""
def test_init_with_custom_template_repository(self, mock_check, tmp_path):
"""Test that custom template repository is stored correctly."""
init(
tmp_path,
git_host="github",
language="go",
template_repository="custom/go-templates",
)

template_file = tmp_path / ".rhiza" / "template.yml"
with open(template_file) as f:
config = yaml.safe_load(f)

# Custom repository should override default
# Custom repository should be set
assert config["repository"] == "custom/go-templates"
assert config["language"] == "go"

def test_init_unknown_language(self, tmp_path):
"""Test that init handles unknown languages gracefully."""
init(tmp_path, git_host="github", language="rust")

# Should create minimal structure
assert (tmp_path / ".rhiza" / "template.yml").exists()
assert (tmp_path / "README.md").exists()

# Should not create language-specific files
assert not (tmp_path / "pyproject.toml").exists()
assert not (tmp_path / "go.mod").exists()

# Verify template.yml
template_file = tmp_path / ".rhiza" / "template.yml"
with open(template_file) as f:
config = yaml.safe_load(f)

assert config["language"] == "rust"
# Should use default Python repository since no mapping exists
assert config["repository"] == "jebel-quant/rhiza"

def test_init_go_language_with_gitlab(self, tmp_path):
"""Test Go init with GitLab hosting."""
init(tmp_path, git_host="gitlab", language="go")
@patch("rhiza.commands.init._check_template_repository_reachable", return_value=True)
def test_init_go_template_repository_with_gitlab(self, mock_check, tmp_path):
"""Test go template repository with GitLab hosting."""
init(tmp_path, git_host="gitlab", template_repository="jebel-quant/rhiza-go")

template_file = tmp_path / ".rhiza" / "template.yml"
with open(template_file) as f:
config = yaml.safe_load(f)

assert config["repository"] == "jebel-quant/rhiza-go"
assert config["language"] == "go"
# Should include gitlab in templates
assert "gitlab" in config["templates"]
assert "github" not in config["templates"]
Loading