Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pyproject): add N (pep8 naming) rule to ruff config... #334

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions diracx-core/src/diracx/core/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from cachetools import Cache, LRUCache, TTLCache, cachedmethod
from pydantic import AnyUrl, BeforeValidator, TypeAdapter, UrlConstraints

from ..exceptions import BadConfigurationVersion
from ..exceptions import BadConfigurationVersionError
from ..extensions import select_from_extension
from .schema import Config

Expand Down Expand Up @@ -159,7 +159,9 @@
).strip()
modified = datetime.fromtimestamp(int(commit_info), tz=timezone.utc)
except sh.ErrorReturnCode as e:
raise BadConfigurationVersion(f"Error parsing latest revision: {e}") from e
raise BadConfigurationVersionError(

Check warning on line 162 in diracx-core/src/diracx/core/config/__init__.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L162 was not covered by tests
f"Error parsing latest revision: {e}"
) from e
logger.debug("Latest revision for %s is %s with mtime %s", self, rev, modified)
return rev, modified

Expand All @@ -176,7 +178,9 @@
)
raw_obj = yaml.safe_load(blob)
except sh.ErrorReturnCode as e:
raise BadConfigurationVersion(f"Error reading configuration: {e}") from e
raise BadConfigurationVersionError(

Check warning on line 181 in diracx-core/src/diracx/core/config/__init__.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L181 was not covered by tests
f"Error reading configuration: {e}"
) from e

config_class: Config = select_from_extension(group="diracx", name="config")[
0
Expand Down
1 change: 0 additions & 1 deletion diracx-core/src/diracx/core/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class DIRACConfig(BaseModel):

class JobMonitoringConfig(BaseModel):
GlobalJobsInfo: bool = True
useESForJobParametersFlag: bool = False


class JobSchedulingConfig(BaseModel):
Expand Down
6 changes: 3 additions & 3 deletions diracx-core/src/diracx/core/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from http import HTTPStatus


class DiracHttpResponse(RuntimeError):
class DiracHttpResponseError(RuntimeError):
def __init__(self, status_code: int, data):
self.status_code = status_code
self.data = data
Expand Down Expand Up @@ -30,15 +30,15 @@ class ConfigurationError(DiracError):
"""Used whenever we encounter a problem with the configuration."""


class BadConfigurationVersion(ConfigurationError):
class BadConfigurationVersionError(ConfigurationError):
"""The requested version is not known."""


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


class JobNotFound(Exception):
class JobNotFoundError(Exception):
def __init__(self, job_id: int, detail: str | None = None):
self.job_id: int = job_id
super().__init__(f"Job {job_id} not found" + (" ({detail})" if detail else ""))
Expand Down
2 changes: 1 addition & 1 deletion diracx-db/src/diracx/db/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class DBUnavailable(Exception):
class DBUnavailableError(Exception):
pass
6 changes: 3 additions & 3 deletions diracx-db/src/diracx/db/os/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from diracx.core.exceptions import InvalidQueryError
from diracx.core.extensions import select_from_extension
from diracx.db.exceptions import DBUnavailable
from diracx.db.exceptions import DBUnavailableError

logger = logging.getLogger(__name__)

Expand All @@ -25,7 +25,7 @@ class OpenSearchDBError(Exception):
pass


class OpenSearchDBUnavailable(DBUnavailable, OpenSearchDBError):
class OpenSearchDBUnavailableError(DBUnavailableError, OpenSearchDBError):
pass


Expand Down Expand Up @@ -152,7 +152,7 @@ async def ping(self):
be ran at every query.
"""
if not await self.client.ping():
raise OpenSearchDBUnavailable(
raise OpenSearchDBUnavailableError(
f"Failed to connect to {self.__class__.__qualname__}"
)

Expand Down
18 changes: 9 additions & 9 deletions diracx-db/src/diracx/db/sql/auth/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ async def get_device_flow(self, device_code: str, max_validity: int):
stmt = select(
DeviceFlows,
(DeviceFlows.creation_time < substract_date(seconds=max_validity)).label(
"is_expired"
"IsExpired"
),
).with_for_update()
stmt = stmt.where(
DeviceFlows.device_code == hashlib.sha256(device_code.encode()).hexdigest(),
)
res = dict((await self.conn.execute(stmt)).one()._mapping)

if res["is_expired"]:
if res["IsExpired"]:
raise ExpiredFlowError()

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

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

if res["status"] == FlowStatus.PENDING:
if res["Status"] == FlowStatus.PENDING:
raise PendingAuthorizationError()

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

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

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

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

return res

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

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

# Return the JWT ID and the creation time
return jti, row.creation_time
return jti, row.CreationTime

async def get_refresh_token(self, jti: str) -> dict:
"""Get refresh token details bound to a given JWT ID."""
Expand Down
46 changes: 23 additions & 23 deletions diracx-db/src/diracx/db/sql/auth/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ class FlowStatus(Enum):

class DeviceFlows(Base):
__tablename__ = "DeviceFlows"
user_code = Column(String(USER_CODE_LENGTH), primary_key=True)
status = EnumColumn(FlowStatus, server_default=FlowStatus.PENDING.name)
creation_time = DateNowColumn()
client_id = Column(String(255))
scope = Column(String(1024))
device_code = Column(String(128), unique=True) # Should be a hash
id_token = NullColumn(JSON())
user_code = Column("UserCode", String(USER_CODE_LENGTH), primary_key=True)
status = EnumColumn("Status", FlowStatus, server_default=FlowStatus.PENDING.name)
creation_time = DateNowColumn("CreationTime")
client_id = Column("ClientID", String(255))
scope = Column("Scope", String(1024))
device_code = Column("DeviceCode", String(128), unique=True) # Should be a hash
id_token = NullColumn("IDToken", JSON())


class AuthorizationFlows(Base):
__tablename__ = "AuthorizationFlows"
uuid = Column(Uuid(as_uuid=False), primary_key=True)
status = EnumColumn(FlowStatus, server_default=FlowStatus.PENDING.name)
client_id = Column(String(255))
creation_time = DateNowColumn()
scope = Column(String(1024))
code_challenge = Column(String(255))
code_challenge_method = Column(String(8))
redirect_uri = Column(String(255))
code = NullColumn(String(255)) # Should be a hash
id_token = NullColumn(JSON())
uuid = Column("UUID", Uuid(as_uuid=False), primary_key=True)
status = EnumColumn("Status", FlowStatus, server_default=FlowStatus.PENDING.name)
client_id = Column("ClientID", String(255))
creation_time = DateNowColumn("CretionTime")
scope = Column("Scope", String(1024))
code_challenge = Column("CodeChallenge", String(255))
code_challenge_method = Column("CodeChallengeMethod", String(8))
redirect_uri = Column("RedirectURI", String(255))
code = NullColumn("Code", String(255)) # Should be a hash
id_token = NullColumn("IDToken", JSON())


class RefreshTokenStatus(Enum):
Expand All @@ -85,13 +85,13 @@ class RefreshTokens(Base):

__tablename__ = "RefreshTokens"
# Refresh token attributes
jti = Column(Uuid(as_uuid=False), primary_key=True)
jti = Column("JTI", Uuid(as_uuid=False), primary_key=True)
status = EnumColumn(
RefreshTokenStatus, server_default=RefreshTokenStatus.CREATED.name
"Status", RefreshTokenStatus, server_default=RefreshTokenStatus.CREATED.name
)
creation_time = DateNowColumn()
scope = Column(String(1024))
creation_time = DateNowColumn("CreationTime")
scope = Column("Scope", String(1024))

# User attributes bound to the refresh token
sub = Column(String(1024))
preferred_username = Column(String(255))
sub = Column("Sub", String(1024))
preferred_username = Column("PreferredUsername", String(255))
4 changes: 2 additions & 2 deletions diracx-db/src/diracx/db/sql/dummy/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DummyDB(BaseSQLDB):
async def summary(self, group_by, search) -> list[dict[str, str | int]]:
columns = [Cars.__table__.columns[x] for x in group_by]

stmt = select(*columns, func.count(Cars.licensePlate).label("count"))
stmt = select(*columns, func.count(Cars.license_plate).label("count"))
stmt = apply_search_filters(Cars.__table__.columns.__getitem__, stmt, search)
stmt = stmt.group_by(*columns)

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

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

result = await self.conn.execute(stmt)
Expand Down
12 changes: 6 additions & 6 deletions diracx-db/src/diracx/db/sql/dummy/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

class Owners(Base):
__tablename__ = "Owners"
ownerID = Column(Integer, primary_key=True, autoincrement=True)
creation_time = DateNowColumn()
name = Column(String(255))
owner_id = Column("OwnerID", Integer, primary_key=True, autoincrement=True)
creation_time = DateNowColumn("CreationTime")
name = Column("Name", String(255))


class Cars(Base):
__tablename__ = "Cars"
licensePlate = Column(Uuid(), primary_key=True)
model = Column(String(255))
ownerID = Column(Integer, ForeignKey(Owners.ownerID))
license_plate = Column("LicensePlate", Uuid(), primary_key=True)
model = Column("Model", String(255))
owner_id = Column("OwnerID", Integer, ForeignKey(Owners.owner_id))
Loading
Loading