From 881472dae3b0fe583a60c0cf18c303307380441a Mon Sep 17 00:00:00 2001 From: David Glick Date: Mon, 15 Apr 2024 16:16:00 -0600 Subject: [PATCH] Make it possible to run the template without docker --- README.md | 2 +- hooks/post_gen_project.py | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fac310f..6ee00e1 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Welcome to **Cookiecutter Plone Starter**! Your one-stop solution to kickstart [ - **pipx**: A handy tool for installing and running Python applications. - **NodeJS & Yarn**: Essential for managing and running JavaScript packages. -- **Docker**: For containerization and easy deployment. +- **Docker**: For containerization and easy deployment. (Optional) ### Installation Guide 🛠️ diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index b6dddb1..ad818d2 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -60,6 +60,19 @@ def _info(msg: str) -> str: ] +def _get_command_version(cmd: str) -> str: + """Get version of a command.""" + try: + raw_version = ( + subprocess.run([cmd, "--version"], capture_output=True) + .stdout.decode() + .strip() + ) + except FileNotFoundError: + raw_version = "" + return raw_version + + def run_cmd(command: str, shell: bool, cwd: str) -> bool: proc = subprocess.run(command, shell=shell, cwd=cwd, capture_output=True) if proc.returncode: @@ -269,9 +282,13 @@ def prepare_backend(): print("Backend codebase") # Clean up unused test folders clean_up_backend_tests() - steps = [ - ["Format generated code in the backend", ["make", "format"], False, "backend"] - ] + if _get_command_version("docker"): + steps = [ + ["Format generated code in the backend", ["make", "format"], False, "backend"] + ] + else: + steps = [] + print(f" - Skipping 'make format' since Docker was not found.") for step in steps: msg, command, shell, cwd = step print(f" - {msg}")