Skip to content

feat: add is_debug_mode function to check application debug status#8

Merged
bybatkhuu merged 2 commits intomainfrom
dev
Nov 23, 2025
Merged

feat: add is_debug_mode function to check application debug status#8
bybatkhuu merged 2 commits intomainfrom
dev

Conversation

@bybatkhuu
Copy link
Owner

This pull request introduces a new utility function to check if the application is running in debug mode, and updates the module exports accordingly. The changes improve environment-based configuration handling.

Environment handling:

  • Added the is_debug_mode function in src/potato_util/_base.py to determine debug mode status based on the DEBUG and ENV environment variables. This uses the is_truthy validator for robust value checking.
  • Imported the is_truthy function from src/potato_util/validator.py to support the new debug mode utility.

Module exports:

  • Updated the __all__ list in src/potato_util/_base.py to include is_debug_mode, making it available for import.

@bybatkhuu bybatkhuu self-assigned this Nov 23, 2025
Copilot AI review requested due to automatic review settings November 23, 2025 07:47
@bybatkhuu bybatkhuu added the enhancement New feature or request label Nov 23, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new is_debug_mode utility function to determine if the application is running in debug mode based on the DEBUG and ENV environment variables. The function is exported from the module to make it available for external use.

  • Added is_debug_mode() function that checks DEBUG and ENV environment variables
  • Imported is_truthy validator to support debug mode checking
  • Updated module exports to include the new function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if "DEBUG" in os.environ:
_debug = str(os.getenv("DEBUG")).strip().lower()

if is_truthy(_debug):
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling is_truthy(_debug) with an empty string will raise a ValueError. The is_truthy function only accepts specific string values like "true", "false", "1", "0", etc., and raises an error for invalid strings including empty strings.

Consider checking if _debug is non-empty before calling is_truthy, or handle the potential exception:

if _debug and is_truthy(_debug):
    _is_debug = True
Suggested change
if is_truthy(_debug):
if _debug and is_truthy(_debug):

Copilot uses AI. Check for mistakes.
Comment on lines +91 to +93
_debug = ""
if "DEBUG" in os.environ:
_debug = str(os.getenv("DEBUG")).strip().lower()
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check if "DEBUG" in os.environ is redundant since os.getenv("DEBUG") returns None if the variable doesn't exist. Additionally, wrapping with str() when the value might be None will convert it to the string "None".

Consider simplifying this to:

_debug = os.getenv("DEBUG", "").strip().lower()

This provides a default empty string and eliminates the need for the conditional check.

Suggested change
_debug = ""
if "DEBUG" in os.environ:
_debug = str(os.getenv("DEBUG")).strip().lower()
_debug = os.getenv("DEBUG", "").strip().lower()

Copilot uses AI. Check for mistakes.
Comment on lines +98 to +100
_env = ""
if "ENV" in os.environ:
_env = str(os.getenv("ENV")).strip().lower()
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the DEBUG variable handling, this can be simplified. The check if "ENV" in os.environ is redundant since os.getenv("ENV") returns None if the variable doesn't exist, and wrapping with str() when the value might be None will convert it to the string "None".

Consider simplifying this to:

_env = os.getenv("ENV", "").strip().lower()
Suggested change
_env = ""
if "ENV" in os.environ:
_env = str(os.getenv("ENV")).strip().lower()
_env = os.getenv("ENV", "").strip().lower()

Copilot uses AI. Check for mistakes.
@@ -78,8 +80,34 @@ def get_slug_name(file_path: str | None = None) -> str:
return _slug_name


Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] All other functions in this file (deep_merge, camel_to_snake, get_slug_name) use the @validate_call decorator from pydantic for input validation. Consider adding the decorator to maintain consistency:

@validate_call
def is_debug_mode() -> bool:

Note: Since this function has no parameters, the decorator won't provide runtime validation but maintains code consistency.

Suggested change
@validate_call

Copilot uses AI. Check for mistakes.
@bybatkhuu bybatkhuu merged commit 355f225 into main Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants