diff --git a/djinit/cli.py b/djinit/cli.py index 4fb821c..98b5a25 100644 --- a/djinit/cli.py +++ b/djinit/cli.py @@ -84,7 +84,7 @@ class Cli: try: with progress: - for step_number, (description, step_func) in enumerate(steps, 1): + for step_number, (_, step_func) in enumerate(steps, 1): step_func() progress.update(task, advance=1, description=f"Step {step_number}/{total_steps}") diff --git a/djinit/services/project.py b/djinit/services/project.py index 606e526..3aef59b 100644 --- a/djinit/services/project.py +++ b/djinit/services/project.py @@ -58,11 +58,13 @@ class ProjectManager: if not os.path.exists(base_settings_path): from djinit.utils.exceptions import ConfigError + raise ConfigError("Could not find base.py settings file") content = read_base_settings(self.project_root, self.module_name) if content is None: from djinit.utils.exceptions import ConfigError + raise ConfigError("Could not read base.py settings file") app_module_paths = calculate_app_module_paths(self.app_names, self.metadata) @@ -77,6 +79,7 @@ class ProjectManager: updated_content = insert_apps_into_user_defined_apps(content, apps_to_add) if not updated_content: from djinit.utils.exceptions import ConfigError + raise ConfigError("Could not update USER_DEFINED_APPS in base.py") with open(base_settings_path, "w") as f: @@ -149,6 +152,7 @@ class ProjectManager: UIFormatter.print_error("Project structure validation failed:") for file_path in missing_files: UIFormatter.print_error(f" Missing: {file_path}") - + from djinit.utils.exceptions import ConfigError + raise ConfigError("Project structure validation failed", details=f"Missing files: {missing_files}") diff --git a/djinit/utils/common.py b/djinit/utils/common.py index ff43dc2..cbc04d7 100644 --- a/djinit/utils/common.py +++ b/djinit/utils/common.py @@ -24,7 +24,7 @@ def create_file_with_content(filename: str, content: str, success_message: str, with open(filename, "w") as file: file.write(content) except OSError as e: - raise FileError(f"Failed to write file: {filename}", details=str(e)) + raise FileError(f"Failed to write file: {filename}", details=str(e)) from e if should_format: format_file(filename) @@ -43,7 +43,8 @@ def create_file_from_template( content = template_engine.render_template(template_path, context) except Exception as e: from djinit.utils.exceptions import TemplateError - raise TemplateError(f"Failed to render template: {template_path}", details=str(e)) + + raise TemplateError(f"Failed to render template: {template_path}", details=str(e)) from e create_file_with_content(file_path, content, success_message, should_format=should_format) diff --git a/djinit/utils/django.py b/djinit/utils/django.py index 216dd03..519d8a0 100644 --- a/djinit/utils/django.py +++ b/djinit/utils/django.py @@ -7,7 +7,6 @@ This module provides functions to create Django projects and apps without requir import os from djinit.core.config import DJANGO_VERSION -from djinit.ui.console import UIFormatter from djinit.utils.common import ( create_directory_with_init, create_file_from_template, @@ -55,7 +54,8 @@ class DjangoHelper: except Exception as e: from djinit.utils.exceptions import DjinitError - raise DjinitError(f"Error creating Django project: {e}", details=str(e)) + + raise DjinitError(f"Error creating Django project: {e}", details=str(e)) from e @staticmethod def startapp(app_name: str, directory: str) -> None: @@ -85,4 +85,5 @@ class DjangoHelper: except Exception as e: from djinit.utils.exceptions import DjinitError - raise DjinitError(f"Error creating Django app: {e}", details=str(e)) + + raise DjinitError(f"Error creating Django app: {e}", details=str(e)) from e diff --git a/djinit/utils/exceptions.py b/djinit/utils/exceptions.py index 1f3c4ba..f8e8b65 100644 --- a/djinit/utils/exceptions.py +++ b/djinit/utils/exceptions.py @@ -14,14 +14,17 @@ class DjinitError(Exception): class ConfigError(DjinitError): """Raised when there is a configuration or metadata error.""" + pass class FileError(DjinitError): """Raised when a file operation fails.""" + pass class TemplateError(DjinitError): """Raised when template rendering fails.""" + pass diff --git a/pyproject.toml b/pyproject.toml index 8f66bc9..b9bdf12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "djinitx" -version = "0.2.1" +version = "0.3.0" description = "A CLI tool to setup Django project" readme = "README.md" requires-python = ">=3.13" diff --git a/setup.py b/setup.py index 3e24726..2185139 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import find_packages, setup setup( name="djinitx", - version="0.2.1", + version="0.3.0", description="A CLI tool to setup Django projects", long_description=open("README.md").read(), long_description_content_type="text/markdown", diff --git a/uv.lock b/uv.lock index 52fddce..d5f9c35 100644 --- a/uv.lock +++ b/uv.lock @@ -43,7 +43,7 @@ wheels = [ [[package]] name = "djinitx" -version = "0.2.1" +version = "0.3.0" source = { virtual = "." } dependencies = [ { name = "click" },