Skip to content

Commit fd848b9

Browse files
committed
Implemented part of the suggested fixes
1- Updated debug logging env var name to DEBUG_MODE 2- Updated sigil check for selecting the correct settings to be lower cased check 3- Used enum for the keys that handle the state in logging utils
1 parent e06966a commit fd848b9

5 files changed

Lines changed: 15 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ _Coming soon_
4040
4141
### Debug logging
4242
43-
Set the `DIFF_POETRY_LOCK_DEBUG` environment variable to `true` (or `1`, `yes`, `on`) to enable verbose debug logging.
43+
Set the `DEBUG_MODE` environment variable to `true` (or `1`, `yes`, `on`) to enable verbose debug logging.
4444
When unset, only informational and higher level log messages are emitted, reducing noise in CI logs.
4545

4646
## History

diff_poetry_lock/github.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self, repo: str, branch: str) -> None:
3030
super().__init__(msg)
3131

3232

33+
3334
class GithubApi:
3435
def __init__(self, settings: Settings) -> None:
3536
self.s = settings

diff_poetry_lock/logging_utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import logging
22
import os
3+
from enum import Enum
34
from typing import Final
45

5-
DEBUG_ENV_VAR = "DIFF_POETRY_LOCK_DEBUG"
6+
DEBUG_ENV_VAR = "DEBUG_MODE"
67

7-
_STATE: Final[dict[str, bool]] = {"configured": False}
8+
9+
class _StateKey(Enum):
10+
"""Enum for state dictionary keys."""
11+
CONFIGURED = "configured"
12+
13+
14+
_STATE: Final[dict[str, bool]] = {_StateKey.CONFIGURED.value: False}
815

916

1017
def configure_logging() -> None:
1118
"""Configure root logging once, honoring the debug flag env var."""
12-
if _STATE["configured"] or logging.getLogger().handlers:
19+
if _STATE[_StateKey.CONFIGURED.value] or logging.getLogger().handlers:
1320
return
1421

1522
level = logging.DEBUG if _is_debug_enabled() else logging.INFO
1623
logging.basicConfig(level=level, format="%(levelname)s %(name)s - %(funcName)s: %(message)s")
17-
_STATE["configured"] = True
24+
_STATE[_StateKey.CONFIGURED.value] = True
1825

1926

2027
def _is_debug_enabled() -> bool:

diff_poetry_lock/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Settings(ABC):
3737
@classmethod
3838
def matches_env(cls, env: dict[str, str]) -> bool:
3939
"""Check whether this CI's identifying env var is present."""
40-
return any(key == cls.sigil_envvar for key in env)
40+
return any(key.lower() == cls.sigil_envvar.lower() for key in env)
4141

4242

4343
class VelaSettings(BaseSettings, Settings):

diff_poetry_lock/test/test_poetry_diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_settings(monkeypatch: MonkeyPatch) -> None:
4646
def test_settings_not_pr(monkeypatch: MonkeyPatch) -> None:
4747
monkeypatch.setenv("GITHUB_EVENT_NAME", "push")
4848
monkeypatch.setenv("GITHUB_REF", "refs/pull/1/merge")
49-
monkeypatch.setenv("github_repository", "account/repo")
49+
monkeypatch.setenv("GITHUB_REPOSITORY", "account/repo")
5050
monkeypatch.setenv("INPUT_GITHUB_TOKEN", "foobar")
5151
monkeypatch.setenv("GITHUB_BASE_REF", "main")
5252

0 commit comments

Comments
 (0)