Skip to content

Commit 320c554

Browse files
authored
Merge pull request #334 from aldbr/main_FIX_camel-case-job-db
feat(pyproject): add `N` (pep8 naming) rule to ruff config...
2 parents 15a1926 + 7a8ab97 commit 320c554

47 files changed

Lines changed: 550 additions & 515 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

diracx-core/src/diracx/core/config/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from cachetools import Cache, LRUCache, TTLCache, cachedmethod
2222
from pydantic import AnyUrl, BeforeValidator, TypeAdapter, UrlConstraints
2323

24-
from ..exceptions import BadConfigurationVersion
24+
from ..exceptions import BadConfigurationVersionError
2525
from ..extensions import select_from_extension
2626
from .schema import Config
2727

@@ -159,7 +159,9 @@ def latest_revision(self) -> tuple[str, datetime]:
159159
).strip()
160160
modified = datetime.fromtimestamp(int(commit_info), tz=timezone.utc)
161161
except sh.ErrorReturnCode as e:
162-
raise BadConfigurationVersion(f"Error parsing latest revision: {e}") from e
162+
raise BadConfigurationVersionError(
163+
f"Error parsing latest revision: {e}"
164+
) from e
163165
logger.debug("Latest revision for %s is %s with mtime %s", self, rev, modified)
164166
return rev, modified
165167

@@ -176,7 +178,9 @@ def read_raw(self, hexsha: str, modified: datetime) -> Config:
176178
)
177179
raw_obj = yaml.safe_load(blob)
178180
except sh.ErrorReturnCode as e:
179-
raise BadConfigurationVersion(f"Error reading configuration: {e}") from e
181+
raise BadConfigurationVersionError(
182+
f"Error reading configuration: {e}"
183+
) from e
180184

181185
config_class: Config = select_from_extension(group="diracx", name="config")[
182186
0

diracx-core/src/diracx/core/config/schema.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class DIRACConfig(BaseModel):
115115

116116
class JobMonitoringConfig(BaseModel):
117117
GlobalJobsInfo: bool = True
118-
useESForJobParametersFlag: bool = False
119118

120119

121120
class JobSchedulingConfig(BaseModel):

diracx-core/src/diracx/core/exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from http import HTTPStatus
22

33

4-
class DiracHttpResponse(RuntimeError):
4+
class DiracHttpResponseError(RuntimeError):
55
def __init__(self, status_code: int, data):
66
self.status_code = status_code
77
self.data = data
@@ -30,15 +30,15 @@ class ConfigurationError(DiracError):
3030
"""Used whenever we encounter a problem with the configuration."""
3131

3232

33-
class BadConfigurationVersion(ConfigurationError):
33+
class BadConfigurationVersionError(ConfigurationError):
3434
"""The requested version is not known."""
3535

3636

3737
class InvalidQueryError(DiracError):
3838
"""It was not possible to build a valid database query from the given input."""
3939

4040

41-
class JobNotFound(Exception):
41+
class JobNotFoundError(Exception):
4242
def __init__(self, job_id: int, detail: str | None = None):
4343
self.job_id: int = job_id
4444
super().__init__(f"Job {job_id} not found" + (" ({detail})" if detail else ""))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
class DBUnavailable(Exception):
1+
class DBUnavailableError(Exception):
22
pass

diracx-db/src/diracx/db/os/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from diracx.core.exceptions import InvalidQueryError
1818
from diracx.core.extensions import select_from_extension
19-
from diracx.db.exceptions import DBUnavailable
19+
from diracx.db.exceptions import DBUnavailableError
2020

2121
logger = logging.getLogger(__name__)
2222

@@ -25,7 +25,7 @@ class OpenSearchDBError(Exception):
2525
pass
2626

2727

28-
class OpenSearchDBUnavailable(DBUnavailable, OpenSearchDBError):
28+
class OpenSearchDBUnavailableError(DBUnavailableError, OpenSearchDBError):
2929
pass
3030

3131

@@ -152,7 +152,7 @@ async def ping(self):
152152
be ran at every query.
153153
"""
154154
if not await self.client.ping():
155-
raise OpenSearchDBUnavailable(
155+
raise OpenSearchDBUnavailableError(
156156
f"Failed to connect to {self.__class__.__qualname__}"
157157
)
158158

diracx-db/src/diracx/db/sql/auth/db.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ async def get_device_flow(self, device_code: str, max_validity: int):
5858
stmt = select(
5959
DeviceFlows,
6060
(DeviceFlows.creation_time < substract_date(seconds=max_validity)).label(
61-
"is_expired"
61+
"IsExpired"
6262
),
6363
).with_for_update()
6464
stmt = stmt.where(
6565
DeviceFlows.device_code == hashlib.sha256(device_code.encode()).hexdigest(),
6666
)
6767
res = dict((await self.conn.execute(stmt)).one()._mapping)
6868

69-
if res["is_expired"]:
69+
if res["IsExpired"]:
7070
raise ExpiredFlowError()
7171

72-
if res["status"] == FlowStatus.READY:
72+
if res["Status"] == FlowStatus.READY:
7373
# Update the status to Done before returning
7474
await self.conn.execute(
7575
update(DeviceFlows)
@@ -81,10 +81,10 @@ async def get_device_flow(self, device_code: str, max_validity: int):
8181
)
8282
return res
8383

84-
if res["status"] == FlowStatus.DONE:
84+
if res["Status"] == FlowStatus.DONE:
8585
raise AuthorizationError("Code was already used")
8686

87-
if res["status"] == FlowStatus.PENDING:
87+
if res["Status"] == FlowStatus.PENDING:
8888
raise PendingAuthorizationError()
8989

9090
raise AuthorizationError("Bad state in device flow")
@@ -190,7 +190,7 @@ async def authorization_flow_insert_id_token(
190190
stmt = select(AuthorizationFlows.code, AuthorizationFlows.redirect_uri)
191191
stmt = stmt.where(AuthorizationFlows.uuid == uuid)
192192
row = (await self.conn.execute(stmt)).one()
193-
return code, row.redirect_uri
193+
return code, row.RedirectURI
194194

195195
async def get_authorization_flow(self, code: str, max_validity: int):
196196
hashed_code = hashlib.sha256(code.encode()).hexdigest()
@@ -205,7 +205,7 @@ async def get_authorization_flow(self, code: str, max_validity: int):
205205

206206
res = dict((await self.conn.execute(stmt)).one()._mapping)
207207

208-
if res["status"] == FlowStatus.READY:
208+
if res["Status"] == FlowStatus.READY:
209209
# Update the status to Done before returning
210210
await self.conn.execute(
211211
update(AuthorizationFlows)
@@ -215,7 +215,7 @@ async def get_authorization_flow(self, code: str, max_validity: int):
215215

216216
return res
217217

218-
if res["status"] == FlowStatus.DONE:
218+
if res["Status"] == FlowStatus.DONE:
219219
raise AuthorizationError("Code was already used")
220220

221221
raise AuthorizationError("Bad state in authorization flow")
@@ -247,7 +247,7 @@ async def insert_refresh_token(
247247
row = (await self.conn.execute(stmt)).one()
248248

249249
# Return the JWT ID and the creation time
250-
return jti, row.creation_time
250+
return jti, row.CreationTime
251251

252252
async def get_refresh_token(self, jti: str) -> dict:
253253
"""Get refresh token details bound to a given JWT ID."""

diracx-db/src/diracx/db/sql/auth/schema.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ class FlowStatus(Enum):
3939

4040
class DeviceFlows(Base):
4141
__tablename__ = "DeviceFlows"
42-
user_code = Column(String(USER_CODE_LENGTH), primary_key=True)
43-
status = EnumColumn(FlowStatus, server_default=FlowStatus.PENDING.name)
44-
creation_time = DateNowColumn()
45-
client_id = Column(String(255))
46-
scope = Column(String(1024))
47-
device_code = Column(String(128), unique=True) # Should be a hash
48-
id_token = NullColumn(JSON())
42+
user_code = Column("UserCode", String(USER_CODE_LENGTH), primary_key=True)
43+
status = EnumColumn("Status", FlowStatus, server_default=FlowStatus.PENDING.name)
44+
creation_time = DateNowColumn("CreationTime")
45+
client_id = Column("ClientID", String(255))
46+
scope = Column("Scope", String(1024))
47+
device_code = Column("DeviceCode", String(128), unique=True) # Should be a hash
48+
id_token = NullColumn("IDToken", JSON())
4949

5050

5151
class AuthorizationFlows(Base):
5252
__tablename__ = "AuthorizationFlows"
53-
uuid = Column(Uuid(as_uuid=False), primary_key=True)
54-
status = EnumColumn(FlowStatus, server_default=FlowStatus.PENDING.name)
55-
client_id = Column(String(255))
56-
creation_time = DateNowColumn()
57-
scope = Column(String(1024))
58-
code_challenge = Column(String(255))
59-
code_challenge_method = Column(String(8))
60-
redirect_uri = Column(String(255))
61-
code = NullColumn(String(255)) # Should be a hash
62-
id_token = NullColumn(JSON())
53+
uuid = Column("UUID", Uuid(as_uuid=False), primary_key=True)
54+
status = EnumColumn("Status", FlowStatus, server_default=FlowStatus.PENDING.name)
55+
client_id = Column("ClientID", String(255))
56+
creation_time = DateNowColumn("CretionTime")
57+
scope = Column("Scope", String(1024))
58+
code_challenge = Column("CodeChallenge", String(255))
59+
code_challenge_method = Column("CodeChallengeMethod", String(8))
60+
redirect_uri = Column("RedirectURI", String(255))
61+
code = NullColumn("Code", String(255)) # Should be a hash
62+
id_token = NullColumn("IDToken", JSON())
6363

6464

6565
class RefreshTokenStatus(Enum):
@@ -85,13 +85,13 @@ class RefreshTokens(Base):
8585

8686
__tablename__ = "RefreshTokens"
8787
# Refresh token attributes
88-
jti = Column(Uuid(as_uuid=False), primary_key=True)
88+
jti = Column("JTI", Uuid(as_uuid=False), primary_key=True)
8989
status = EnumColumn(
90-
RefreshTokenStatus, server_default=RefreshTokenStatus.CREATED.name
90+
"Status", RefreshTokenStatus, server_default=RefreshTokenStatus.CREATED.name
9191
)
92-
creation_time = DateNowColumn()
93-
scope = Column(String(1024))
92+
creation_time = DateNowColumn("CreationTime")
93+
scope = Column("Scope", String(1024))
9494

9595
# User attributes bound to the refresh token
96-
sub = Column(String(1024))
97-
preferred_username = Column(String(255))
96+
sub = Column("Sub", String(1024))
97+
preferred_username = Column("PreferredUsername", String(255))

diracx-db/src/diracx/db/sql/dummy/db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DummyDB(BaseSQLDB):
2525
async def summary(self, group_by, search) -> list[dict[str, str | int]]:
2626
columns = [Cars.__table__.columns[x] for x in group_by]
2727

28-
stmt = select(*columns, func.count(Cars.licensePlate).label("count"))
28+
stmt = select(*columns, func.count(Cars.license_plate).label("count"))
2929
stmt = apply_search_filters(Cars.__table__.columns.__getitem__, stmt, search)
3030
stmt = stmt.group_by(*columns)
3131

@@ -44,7 +44,7 @@ async def insert_owner(self, name: str) -> int:
4444

4545
async def insert_car(self, license_plate: UUID, model: str, owner_id: int) -> int:
4646
stmt = insert(Cars).values(
47-
licensePlate=license_plate, model=model, ownerID=owner_id
47+
license_plate=license_plate, model=model, owner_id=owner_id
4848
)
4949

5050
result = await self.conn.execute(stmt)

diracx-db/src/diracx/db/sql/dummy/schema.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
class Owners(Base):
1212
__tablename__ = "Owners"
13-
ownerID = Column(Integer, primary_key=True, autoincrement=True)
14-
creation_time = DateNowColumn()
15-
name = Column(String(255))
13+
owner_id = Column("OwnerID", Integer, primary_key=True, autoincrement=True)
14+
creation_time = DateNowColumn("CreationTime")
15+
name = Column("Name", String(255))
1616

1717

1818
class Cars(Base):
1919
__tablename__ = "Cars"
20-
licensePlate = Column(Uuid(), primary_key=True)
21-
model = Column(String(255))
22-
ownerID = Column(Integer, ForeignKey(Owners.ownerID))
20+
license_plate = Column("LicensePlate", Uuid(), primary_key=True)
21+
model = Column("Model", String(255))
22+
owner_id = Column("OwnerID", Integer, ForeignKey(Owners.owner_id))

0 commit comments

Comments
 (0)