Skip to content

Commit 072a9a8

Browse files
alanbchristiea.b.christie
andauthored
To pyproject (#4)
* build: Switch to pyproject.toml * build: Better pre-commit * fix: Remove Optional & new lock --------- Co-authored-by: a.b.christie <alan.christie@matildapeak.com>
1 parent 3ecb8ed commit 072a9a8

5 files changed

Lines changed: 23 additions & 23 deletions

File tree

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
minimum_pre_commit_version: 3.8.0
2+
minimum_pre_commit_version: 4.5.0
33
exclude: ^src/squeck/VERSION
44

55
repos:
@@ -64,3 +64,5 @@ repos:
6464
args:
6565
- --install-types
6666
- --non-interactive
67+
additional_dependencies:
68+
- textual

src/squeck/access_token.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Gets AS and DM access tokens."""
22

3-
from typing import Optional
43
from squonk2.auth import Auth
54
from squonk2.environment import Environment
65

@@ -10,15 +9,15 @@ class AccessToken:
109

1110
@classmethod
1211
def get_as_access_token(
13-
cls, env: Environment, *, prior_token: Optional[str] = None
14-
) -> Optional[str]:
12+
cls, env: Environment, *, prior_token: str | None = None
13+
) -> str | None:
1514
"""Returns a token for the AS API.
1615
This returns None on error or if the client ID is not defined.
1716
"""
1817
assert env
1918
if not env.keycloak_as_client_id:
2019
return None
21-
access_token: Optional[str] = Auth.get_access_token(
20+
access_token: str | None = Auth.get_access_token(
2221
keycloak_url=env.keycloak_url,
2322
keycloak_realm=env.keycloak_realm,
2423
keycloak_client_id=env.keycloak_as_client_id,
@@ -31,14 +30,14 @@ def get_as_access_token(
3130

3231
@classmethod
3332
def get_dm_access_token(
34-
cls, env: Environment, *, prior_token: Optional[str] = None
35-
) -> Optional[str]:
33+
cls, env: Environment, *, prior_token: str | None = None
34+
) -> str | None:
3635
"""Returns a token for the DM API
3736
or None if a token could not be obtained."""
3837
assert env
3938
if not env.keycloak_dm_client_id:
4039
return None
41-
access_token: Optional[str] = Auth.get_access_token(
40+
access_token: str | None = Auth.get_access_token(
4241
keycloak_url=env.keycloak_url,
4342
keycloak_realm=env.keycloak_realm,
4443
keycloak_client_id=env.keycloak_dm_client_id,

src/squeck/squeck.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import argparse
55
import os
66
import sys
7-
from typing import Optional
7+
from typing import Any
88

99
from squonk2.environment import Environment
1010
from textual.app import App, ComposeResult
@@ -15,7 +15,7 @@
1515

1616
# Users set SQUONK2_LOGFILE to enable logging
1717
# e.g. "export SQUONK2_LOGFILE=./squad.log"
18-
_LOG: Optional[str] = os.environ.get("SQUONK2_LOGFILE")
18+
_LOG: str | None = os.environ.get("SQUONK2_LOGFILE")
1919

2020
# Read the version file
2121
with open(
@@ -24,7 +24,7 @@
2424
__version__ = f.read().strip()
2525

2626

27-
class Squeck(App): # type: ignore
27+
class Squeck(App[Any]):
2828
"""An example of a very simple Textual App"""
2929

3030
def compose(self) -> ComposeResult:
@@ -38,7 +38,7 @@ def compose(self) -> ComposeResult:
3838

3939
def on_mount(self) -> None:
4040
"""App specialisation."""
41-
self.sub_title = f"v{__version__}" # pylint: attribute-defined-outside-init
41+
self.sub_title = f"v{__version__}"
4242

4343

4444
def main() -> int:

src/squeck/widgets/env.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""A textual widget used to display environment information."""
22

33
import random
4-
from typing import Optional
54

65
from rich.panel import Panel
76
from rich.style import Style
@@ -28,26 +27,26 @@
2827
_UI_HOSTNAME_POSTFIX: str = "/data-manager-ui"
2928

3029

31-
class EnvWidget(Static): # type: ignore
30+
class EnvWidget(Static):
3231
"""Displays the environment."""
3332

34-
as_access_token: Optional[str] = None
35-
dm_access_token: Optional[str] = None
33+
as_access_token: str | None = None
34+
dm_access_token: str | None = None
3635

3736
def __init__(self, environment_name: str) -> None:
3837
super().__init__()
3938
self.environment_name = environment_name
4039
self.environment = Environment(environment_name)
4140

42-
self.as_api: Optional[AsApi] = None
41+
self.as_api: AsApi | None = None
4342
if self.environment.as_api:
4443
self.as_api = AsApi()
4544
self.as_api.set_api_url(self.environment.as_api, verify_ssl_cert=False)
46-
self.dm_api: Optional[DmApi] = None
45+
self.dm_api: DmApi | None = None
4746
if self.environment.dm_api:
4847
self.dm_api = DmApi()
4948
self.dm_api.set_api_url(self.environment.dm_api, verify_ssl_cert=False)
50-
self.ui_api: Optional[UiApi] = None
49+
self.ui_api: UiApi | None = None
5150
if self.environment.ui_api:
5251
self.ui_api = UiApi()
5352
self.ui_api.set_api_url(self.environment.ui_api, verify_ssl_cert=False)
@@ -127,7 +126,7 @@ def render(self) -> RenderResult:
127126
kc_host = Text(f"{self.environment.keycloak_hostname}", style=_KEY_VALUE_STYLE)
128127

129128
# The API lines are also dynamically styled.
130-
as_hostname: Optional[str] = self.environment.as_hostname
129+
as_hostname: str | None = self.environment.as_hostname
131130
if as_hostname:
132131
as_hostname_text: Text = Text(f"{as_hostname} ", style=_KEY_VALUE_STYLE)
133132
if self.as_access_token:
@@ -137,7 +136,7 @@ def render(self) -> RenderResult:
137136
else:
138137
as_hostname_text = Text("Undefined", style=_VALUE_ERROR_STYLE)
139138

140-
dm_hostname: Optional[str] = self.environment.dm_hostname
139+
dm_hostname: str | None = self.environment.dm_hostname
141140
if dm_hostname:
142141
dm_hostname_text: Text = Text(f"{dm_hostname} ", style=_KEY_VALUE_STYLE)
143142
if self.dm_access_token:
@@ -147,7 +146,7 @@ def render(self) -> RenderResult:
147146
else:
148147
dm_hostname_text = Text("Undefined", style=_VALUE_ERROR_STYLE)
149148

150-
ui_hostname: Optional[str] = self.environment.ui_hostname
149+
ui_hostname: str | None = self.environment.ui_hostname
151150
if ui_hostname:
152151
ui_hostname_text: Text = Text(
153152
ui_hostname + _UI_HOSTNAME_POSTFIX + " ", style=_KEY_VALUE_STYLE

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)