Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of '--replay-file' #24

Merged
merged 1 commit into from
May 16, 2024
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
29 changes: 18 additions & 11 deletions cookieplone/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from cookieplone.exceptions import GeneratorException
from cookieplone.generator import generate
from cookieplone.repository import get_base_repository, get_template_options
from cookieplone.utils import console, internal
from cookieplone.utils import console, files, internal


def validate_extra_context(value: list[str] | None = None) -> list[str]:
Expand Down Expand Up @@ -116,6 +116,8 @@ def cli(
if version:
console.base_print(internal.version_info())
raise typer.Exit()

configure_logger(stream_level="DEBUG" if verbose else "INFO", debug_file=debug_file)
repository = os.environ.get(settings.REPO_LOCATION)
if not repository:
repository = "gh:plone/cookieplone-templates"
Expand All @@ -127,19 +129,22 @@ def cli(
else:
console.welcome_screen()

if replay_file:
replay = replay_file
passwd = os.environ.get(
settings.REPO_PASSWORD, os.environ.get("COOKIECUTTER_REPO_PASSWORD")
)
if not output_dir:
output_dir = Path().cwd()
configure_logger(stream_level="DEBUG" if verbose else "INFO", debug_file=debug_file)
# Annotate extra_context
extra_context = parse_extra_content(extra_context)
extra_context["__generator_signature"] = internal.signature_md(repo_path)
extra_context["__cookieplone_repository_path"] = f"{repo_path}"
extra_context["__cookieplone_template"] = f"{template}"

replay_file = files.resolve_path(replay_file) if replay_file else replay_file
if replay_file and replay_file.exists():
# Use replay_file
replay = replay_file
else:
# Annotate extra_context
extra_context = parse_extra_content(extra_context)
extra_context["__generator_signature"] = internal.signature_md(repo_path)
extra_context["__cookieplone_repository_path"] = f"{repo_path}"
extra_context["__cookieplone_template"] = f"{template}"
# Run generator
try:
generate(
Expand All @@ -157,10 +162,12 @@ def cli(
skip_if_file_exists,
keep_project_on_failure,
)
except GeneratorException:
except GeneratorException as exc:
console.error(exc.message)
# TODO: Handle error
raise typer.Exit(1) # noQA:B904
except Exception:
except Exception as exc:
console.error(exc)
# TODO: Handle error
raise typer.Exit(1) # noQA:B904

Expand Down
7 changes: 7 additions & 0 deletions cookieplone/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
from cookiecutter.utils import rmtree


def resolve_path(path: Path | str) -> Path:
"""Resolve a path, including home user expansion."""
if f"{path}".startswith("~"):
path = path.expanduser()
return path.resolve()


def remove_files(base_path: Path, paths: list[str]):
"""Remove files."""
for filepath in paths:
Expand Down
1 change: 1 addition & 0 deletions news/23.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix usage of `--replay-file` [@ericof]