Conversation
There was a problem hiding this comment.
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 checksDEBUGandENVenvironment variables - Imported
is_truthyvalidator 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.
src/potato_util/_base.py
Outdated
| if "DEBUG" in os.environ: | ||
| _debug = str(os.getenv("DEBUG")).strip().lower() | ||
|
|
||
| if is_truthy(_debug): |
There was a problem hiding this comment.
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| if is_truthy(_debug): | |
| if _debug and is_truthy(_debug): |
src/potato_util/_base.py
Outdated
| _debug = "" | ||
| if "DEBUG" in os.environ: | ||
| _debug = str(os.getenv("DEBUG")).strip().lower() |
There was a problem hiding this comment.
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.
| _debug = "" | |
| if "DEBUG" in os.environ: | |
| _debug = str(os.getenv("DEBUG")).strip().lower() | |
| _debug = os.getenv("DEBUG", "").strip().lower() |
src/potato_util/_base.py
Outdated
| _env = "" | ||
| if "ENV" in os.environ: | ||
| _env = str(os.getenv("ENV")).strip().lower() |
There was a problem hiding this comment.
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()| _env = "" | |
| if "ENV" in os.environ: | |
| _env = str(os.getenv("ENV")).strip().lower() | |
| _env = os.getenv("ENV", "").strip().lower() |
| @@ -78,8 +80,34 @@ def get_slug_name(file_path: str | None = None) -> str: | |||
| return _slug_name | |||
|
|
|||
|
|
|||
There was a problem hiding this comment.
[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.
| @validate_call |
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:
is_debug_modefunction insrc/potato_util/_base.pyto determine debug mode status based on theDEBUGandENVenvironment variables. This uses theis_truthyvalidator for robust value checking.is_truthyfunction fromsrc/potato_util/validator.pyto support the new debug mode utility.Module exports:
__all__list insrc/potato_util/_base.pyto includeis_debug_mode, making it available for import.