Skip to content

Commit 2473314

Browse files
committed
Do not require settings environment vars to just run linting
1 parent e993969 commit 2473314

File tree

7 files changed

+16
-21
lines changed

7 files changed

+16
-21
lines changed

jbi/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323

2424
import jbi
2525
import jbi.queue
26-
from jbi.configuration import ACTIONS
26+
from jbi.configuration import get_actions
2727
from jbi.environment import get_settings
2828
from jbi.log import CONFIG
2929
from jbi.router import router
3030

3131
SRC_DIR = Path(__file__).parent
3232
APP_DIR = Path(__file__).parents[1]
3333

34+
ACTIONS = get_actions()
3435
settings = get_settings()
3536
version_info: dict[str, str] = get_version(APP_DIR)
3637
VERSION: str = version_info["version"]

jbi/bugzilla/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
from .models import (
2-
Bug,
3-
BugId,
4-
WebhookEvent,
5-
WebhookRequest,
6-
)
7-
from .service import BugzillaService, get_service

jbi/configuration.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from jbi import environment
1111
from jbi.models import Actions
1212

13-
settings = environment.get_settings()
1413
logger = logging.getLogger(__name__)
1514

1615

@@ -30,9 +29,9 @@ def get_actions_from_file(jbi_config_file: str) -> Actions:
3029
raise ConfigError("Errors exist.") from exception
3130

3231

33-
def get_actions(env=settings.env):
32+
def get_actions(env=None):
3433
"""Load actions from file determined by ENV name"""
34+
if env is None:
35+
settings = environment.get_settings()
36+
env = settings.env
3537
return get_actions_from_file(f"config/config.{env}.yaml")
36-
37-
38-
ACTIONS = get_actions()

jbi/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
field_validator,
1818
)
1919

20-
from jbi import Operation, steps
21-
from jbi.bugzilla import Bug, BugId, WebhookEvent
20+
from jbi import Operation
21+
from jbi.bugzilla.models import Bug, BugId, WebhookEvent
2222

2323
logger = logging.getLogger(__name__)
2424

@@ -51,6 +51,7 @@ class ActionSteps(BaseModel, frozen=True):
5151
@classmethod
5252
def validate_steps(cls, function_names: list[str]):
5353
"""Validate that all configure step functions exist in the steps module"""
54+
from jbi import steps
5455

5556
invalid_functions = [
5657
func_name for func_name in function_names if not hasattr(steps, func_name)

jbi/retry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dockerflow.logging import JsonLogFormatter, request_id_context
99

1010
import jbi.runner as runner
11-
from jbi.configuration import ACTIONS
11+
from jbi.configuration import get_actions
1212
from jbi.errors import IgnoreInvalidRequestError
1313
from jbi.queue import get_dl_queue
1414

@@ -22,6 +22,8 @@
2222
lsh.setFormatter(JsonLogFormatter(logger_name=__name__))
2323
logger.addHandler(lsh)
2424

25+
ACTIONS = get_actions()
26+
2527

2628
async def retry_failed(item_executor=runner.execute_action, queue=get_dl_queue()):
2729
min_event_timestamp = datetime.now(UTC) - timedelta(days=int(RETRY_TIMEOUT_DAYS))

jbi/router.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
from fastapi.templating import Jinja2Templates
1414

1515
from jbi import bugzilla, jira
16-
from jbi.configuration import ACTIONS
16+
from jbi.configuration import get_actions
1717
from jbi.environment import Settings, get_settings
1818
from jbi.models import Actions
1919
from jbi.queue import DeadLetterQueue, get_dl_queue
2020
from jbi.runner import execute_or_queue
2121

2222
SettingsDep = Annotated[Settings, Depends(get_settings)]
23-
ActionsDep = Annotated[Actions, Depends(lambda: ACTIONS)]
23+
ActionsDep = Annotated[Actions, Depends(get_actions)]
2424
BugzillaServiceDep = Annotated[bugzilla.BugzillaService, Depends(bugzilla.get_service)]
2525
JiraServiceDep = Annotated[jira.JiraService, Depends(jira.get_service)]
2626

jbi/steps.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Each step takes an `ActionContext` and a list of arbitrary parameters.
55
"""
66

7-
# This import is needed (as of Pyhon 3.11) to enable type checking with modules
7+
# This import is needed (as of Python 3.11) to enable type checking with modules
88
# imported under `TYPE_CHECKING`
99
# https://docs.python.org/3/whatsnew/3.7.html#pep-563-postponed-evaluation-of-annotations
1010
# https://docs.python.org/3/whatsnew/3.11.html#pep-563-may-not-be-the-future
@@ -19,8 +19,6 @@
1919
from jbi import Operation
2020
from jbi.environment import get_settings
2121

22-
settings = get_settings()
23-
2422

2523
class StepStatus(Enum):
2624
"""
@@ -99,6 +97,7 @@ def add_link_to_jira(
9997
context: ActionContext, *, bugzilla_service: BugzillaService
10098
) -> StepResult:
10199
"""Add the URL to the Jira issue in the `see_also` field on the Bugzilla ticket"""
100+
settings = get_settings()
102101
jira_url = f"{settings.jira_base_url}browse/{context.jira.issue}"
103102
logger.info(
104103
"Link %r on Bug %s",

0 commit comments

Comments
 (0)