From eac45bdeb3c429244cfccd1b0bd031f22e0a697e Mon Sep 17 00:00:00 2001 From: Brian Wiborg Date: Sat, 27 Sep 2025 23:16:57 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Replace=20os.mkdirs=20in?= =?UTF-8?q?=20favor=20of=20Path.mkdir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ohmyapi/core/scaffolding.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ohmyapi/core/scaffolding.py b/src/ohmyapi/core/scaffolding.py index b725f0e..c7d7943 100644 --- a/src/ohmyapi/core/scaffolding.py +++ b/src/ohmyapi/core/scaffolding.py @@ -1,4 +1,3 @@ -import os from pathlib import Path from jinja2 import Environment, FileSystemLoader @@ -11,7 +10,7 @@ def render_template_file(template_path: Path, context: dict, output_path: Path): """Render a single Jinja2 template file to disk.""" template = env.get_template(str(template_path.relative_to(TEMPLATE_DIR)).replace("\\", "/")) content = template.render(**context) - os.makedirs(output_path.parent, exist_ok=True) + output_path.parent.mkdir(exist_ok=True) with open(output_path, "w", encoding="utf-8") as f: f.write(content) @@ -22,7 +21,7 @@ def render_template_dir(template_subdir: str, target_dir: Path, context: dict, s If subdir_name is given, files are placed inside target_dir/subdir_name. """ template_dir = TEMPLATE_DIR / template_subdir - for root, _, files in os.walk(template_dir): + for root, _, files in template_dir.walk(): root_path = Path(root) rel_root = root_path.relative_to(template_dir) # path relative to template_subdir @@ -45,7 +44,7 @@ def render_template_dir(template_subdir: str, target_dir: Path, context: dict, s def startproject(name: str): """Create a new project: flat structure, all project templates go into /""" target_dir = Path(name).resolve() - os.makedirs(target_dir, exist_ok=True) + target_dir.mkdir(exist_ok=True) render_template_dir("project", target_dir, {"project_name": name}) print(f"✅ Project '{name}' created successfully.") print(f"🔧 Next, configure your project in {target_dir / 'settings.py'}") @@ -54,7 +53,7 @@ def startproject(name: str): def startapp(name: str, project: str): """Create a new app inside a project: templates go into //""" target_dir = Path(project) - os.makedirs(target_dir, exist_ok=True) + target_dir.makedirs(exist_ok=True) render_template_dir("app", target_dir, {"project_name": target_dir.resolve().name, "app_name": name}, subdir_name=name) print(f"✅ App '{name}' created in project '{target_dir}' successfully.") print(f"🔧 Remember to add '{name}' to your INSTALLED_APPS!")