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

Evaluating ruff #683

Merged
merged 29 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b4645bb
add ruff
helylle Sep 3, 2024
12e9f7a
update deps
helylle Sep 3, 2024
271671f
remove unused imports
helylle Sep 3, 2024
7e44385
remove superfluous import statements
helylle Sep 3, 2024
e6adae1
add explicit re-export
helylle Sep 3, 2024
01a3e07
make sure strings are f-strings
helylle Sep 3, 2024
16e96e3
make normal strings of f-strings without placeholders
helylle Sep 3, 2024
a9bddd5
ignore rule E741 (names to avoid) for now
helylle Sep 3, 2024
4f39c1a
remove unused variables
helylle Sep 3, 2024
fcaf0ce
use 'is' for comparisons with None
helylle Sep 3, 2024
49832f1
avoid comparisons to boolean literals
helylle Sep 3, 2024
2c80cfe
use 'is' for type comparisons
helylle Sep 3, 2024
b69e2d7
remove unnecessary trailing comma
helylle Sep 3, 2024
ac20eba
remove commented imports
helylle Sep 3, 2024
770b3c2
ruff reformat
helylle Sep 3, 2024
988c8c1
remove double import
helylle Sep 4, 2024
1b65f4c
follow pycodestyle readability, E713
helylle Sep 4, 2024
e188757
do not use bare except
helylle Sep 4, 2024
2a0366b
remove old try/except
helylle Sep 4, 2024
68e4888
make sure mocked function applies to test
helylle Sep 5, 2024
4b22ec6
remove import directory from repository migration work
helylle Sep 5, 2024
5a8043a
Merge branch 'main' into ylle_evaluating_ruff
helylle Sep 5, 2024
d14a576
use ruff for reformat and add lint rule with ruff check
helylle Sep 5, 2024
f83fc2f
clean up imports from linting check
helylle Sep 5, 2024
03a4e50
make reformat
helylle Sep 5, 2024
a0a1ebc
test linting in github workflow
helylle Sep 5, 2024
b1788ba
updates to vscode settings in devcontainer for ruff
helylle Sep 6, 2024
c7425e3
add ruff as isort replacement
helylle Sep 9, 2024
69abb0b
make reformat
helylle Sep 9, 2024
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
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Python 3",
"build": {
"dockerfile": "Dockerfile",
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
Expand All @@ -22,7 +22,8 @@
"streetsidesoftware.code-spell-checker",
"streetsidesoftware.code-spell-checker-swedish",
"ms-vscode.makefile-tools",
"ms-python.isort"
"ms-python.isort",
"charliermarsh.ruff"
]
}
},
Expand Down
1 change: 1 addition & 0 deletions requirements/test_requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pytest-cov
respx
pip-tools
motor-types
ruff
496 changes: 269 additions & 227 deletions requirements/test_requirements.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Set the maximum line length to 120.
line-length = 120
target-version = "py310"
2 changes: 2 additions & 0 deletions src/eduid/common/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

from eduid.common.clients.gnap_client import AsyncGNAPClient, GNAPClient
from eduid.common.clients.scim_client import SCIMClient

__all__ = ['AsyncGNAPClient', 'GNAPClient', 'SCIMClient']
2 changes: 2 additions & 0 deletions src/eduid/common/clients/gnap_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

from eduid.common.clients.gnap_client.async_client import AsyncGNAPClient
from eduid.common.clients.gnap_client.sync_client import GNAPClient

__all__ = ['GNAPClient', 'AsyncGNAPClient']
2 changes: 2 additions & 0 deletions src/eduid/common/clients/scim_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__author__ = "lundberg"

from eduid.common.clients.scim_client.scim_client import SCIMClient

__all__ = ['SCIMClient']
2 changes: 1 addition & 1 deletion src/eduid/common/models/bearer_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum
from typing import Any, Mapping, Optional

from pydantic import BaseModel, Field, StrictInt, field_validator, model_validator, validator
from pydantic import BaseModel, Field, StrictInt, field_validator, model_validator
from pydantic_core.core_schema import ValidationInfo

from eduid.common.config.base import AuthnBearerTokenConfig, DataOwnerName, ScopeName
Expand Down
5 changes: 2 additions & 3 deletions src/eduid/common/models/scim_invite.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from datetime import datetime
from typing import Any, Optional
from typing import Optional
from uuid import UUID

from pydantic import Field, model_validator, root_validator
from pydantic import Field, model_validator
from typing_extensions import Self

from eduid.common.models.scim_base import (
Expand Down
5 changes: 5 additions & 0 deletions src/eduid/graphdb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from eduid.graphdb.db import BaseGraphDB, Neo4jDB

__all__ = [
'BaseGraphDB',
'Neo4jDB',
]

__author__ = "lundberg"
6 changes: 6 additions & 0 deletions src/eduid/graphdb/groupdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
from eduid.graphdb.groupdb.group import Group
from eduid.graphdb.groupdb.user import User

__all__ = [
'GroupDB',
'Group',
'User',
]

__author__ = "lundberg"
2 changes: 1 addition & 1 deletion src/eduid/maccapi/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from eduid.userdb.exceptions import UserDoesNotExist, UserOutOfSync
from eduid.userdb.logs.element import ManagedAccountLogElement
from eduid.userdb.maccapi import ManagedAccount
from eduid.vccs.client import VCCSClient, VCCSClientHTTPError, VCCSPasswordFactor, VCCSRevokeFactor
from eduid.vccs.client import VCCSClientHTTPError, VCCSPasswordFactor, VCCSRevokeFactor


class UnableToCreateUniqueEppn(Exception):
Expand Down
4 changes: 2 additions & 2 deletions src/eduid/maccapi/middleware.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruff wanted to remove e as an unused variable as the f-strings were just strings

Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -
try:
token.validate_auth_source()
except RequestedAccessDenied as e:
self.context.logger.error("Access denied: {e}")
self.context.logger.error(f"Access denied: {e}")
return return_error_response(
status_code=status.HTTP_401_UNAUTHORIZED, detail="Authentication source or assurance level invalid"
)

try:
data_owner = token.get_data_owner()
except RequestedAccessDenied as e:
self.context.logger.error("Access denied: {e}")
self.context.logger.error(f"Access denied: {e}")
return return_error_response(
status_code=status.HTTP_401_UNAUTHORIZED, detail="Data owner requested in access token denied"
)
Expand Down
3 changes: 1 addition & 2 deletions src/eduid/maccapi/testing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import unittest
from typing import Any, Optional, cast
from typing import Any, cast

import pkg_resources
from starlette.testclient import TestClient
Expand All @@ -9,7 +9,6 @@
from eduid.maccapi.app import init_api
from eduid.maccapi.config import MAccApiConfig
from eduid.maccapi.context import Context
from eduid.userdb.maccapi import ManagedAccount
from eduid.userdb.testing import MongoTemporaryInstance
from eduid.vccs.client import VCCSClient
from eduid.webapp.common.authn.testing import MockVCCSClient
Expand Down
2 changes: 0 additions & 2 deletions src/eduid/maccapi/util.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import logging
import math
from uuid import uuid4

from jwcrypto import jwk
from pwgen import pwgen

from eduid.common.config.exceptions import BadConfiguration
from eduid.maccapi.config import MAccApiConfig
Expand Down
9 changes: 9 additions & 0 deletions src/eduid/queue/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
from eduid.queue.db.payload import Payload, RawPayload, TestPayload
from eduid.queue.db.queue_item import QueueItem, SenderInfo

__all__ = [
'QueueDB',
'Payload',
'RawPayload',
'TestPayload',
'QueueItem',
'SenderInfo',
]

__author__ = "lundberg"
6 changes: 6 additions & 0 deletions src/eduid/queue/db/message/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from eduid.queue.db.message.db import MessageDB
from eduid.queue.db.message.payload import EduidInviteEmail, EduidSignupEmail

__all__ = [
'MessageDB',
'EduidInviteEmail',
'EduidSignupEmail',
]

__author__ = "lundberg"
1 change: 0 additions & 1 deletion src/eduid/scimapi/models/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import datetime
from typing import Any, Optional
from uuid import UUID

Expand Down
26 changes: 23 additions & 3 deletions src/eduid/userdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
__license__ = "BSD"
__authors__ = ["Fredrik Thulin"]

import eduid.userdb.exceptions
import eduid.userdb.mail
import eduid.userdb.phone
#import eduid.userdb.exceptions
#import eduid.userdb.mail
#import eduid.userdb.phone
from eduid.userdb.db import MongoDB
from eduid.userdb.event import EventList
from eduid.userdb.identity import EIDASIdentity, NinIdentity, SvipeIdentity
Expand All @@ -26,3 +26,23 @@
from eduid.userdb.tou import ToUEvent
from eduid.userdb.user import User
from eduid.userdb.userdb import AmDB, UserDB

__all__ = [
'User',
'UserDB',
'AmDB',
'EventList',
'ToUEvent',
'Profile',
'Nin',
'NinIdentity',
'SvipeIdentity',
'EIDASIdentity',
'MailAddress',
'PhoneNumber',
'OidcIdToken',
'OidcAuthorization',
'Orcid',
'LockedIdentityList',
'MongoDB',
]
5 changes: 5 additions & 0 deletions src/eduid/userdb/actions/tou/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

from .user import ToUUser
from .userdb import ToUUserDB

__all__ = [
"ToUUser",
"ToUUserDB",
]
10 changes: 10 additions & 0 deletions src/eduid/userdb/credentials/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
from eduid.userdb.credentials.fido import U2F, FidoCredential, Webauthn
from eduid.userdb.credentials.list import CredentialList
from eduid.userdb.credentials.password import Password

__all__ = [
'Credential',
'CredentialList',
'Password',
'U2F',
'FidoCredential',
'Webauthn',
'CredentialProofingMethod',
]
7 changes: 7 additions & 0 deletions src/eduid/userdb/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@

# Keep existing imports working
from eduid.userdb.db.sync_db import BaseDB, MongoDB, SaveResult, TUserDbDocument

__all__ = [
'BaseDB',
'MongoDB',
'SaveResult',
'TUserDbDocument',
]
6 changes: 6 additions & 0 deletions src/eduid/userdb/group_management/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from eduid.userdb.group_management.db import GroupManagementInviteStateDB
from eduid.userdb.group_management.state import GroupInviteState, GroupRole

__all__ = [
'GroupManagementInviteStateDB',
'GroupInviteState',
'GroupRole',
]

__author__ = "lundberg"
5 changes: 5 additions & 0 deletions src/eduid/userdb/idp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
from .db import IdPUserDb
from .user import IdPUser

__all__ = [
'IdPUser',
'IdPUserDb',
]
14 changes: 14 additions & 0 deletions src/eduid/userdb/logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,18 @@
TeleAdressProofingRelation,
)

__all__ = [
'ProofingLog',
'LetterProofing',
'MailAddressProofing',
'MFATokenProofing',
'OrcidProofing',
'PhoneNumberProofing',
'SeLegProofing',
'SeLegProofingFrejaEid',
'SwedenConnectProofing',
'TeleAdressProofing',
'TeleAdressProofingRelation',
]

__author__ = "lundberg"
5 changes: 5 additions & 0 deletions src/eduid/userdb/maccapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from eduid.userdb.maccapi.userdb import ManagedAccount, ManagedAccountDB

__all__ = [
'ManagedAccount',
'ManagedAccountDB',
]
5 changes: 5 additions & 0 deletions src/eduid/userdb/personal_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from eduid.userdb.personal_data.db import PersonalDataUserDB
from eduid.userdb.personal_data.user import PersonalDataUser

__all__ = [
'PersonalDataUserDB',
'PersonalDataUser',
]

__author__ = "lundberg"
27 changes: 27 additions & 0 deletions src/eduid/userdb/proofing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
PhoneProofingStateDB,
PhoneProofingUserDB,
)



from eduid.userdb.proofing.element import EmailProofingElement, NinProofingElement, PhoneProofingElement
from eduid.userdb.proofing.state import (
EmailProofingState,
Expand All @@ -21,3 +24,27 @@
PhoneProofingState,
)
from eduid.userdb.proofing.user import ProofingUser

__all__ = [
'EidasProofingUserDB',
'EmailProofingStateDB',
'EmailProofingUserDB',
'LetterProofingStateDB',
'LetterProofingUserDB',
'LookupMobileProofingUserDB',
'OidcProofingStateDB',
'OidcProofingUserDB',
'OrcidProofingStateDB',
'OrcidProofingUserDB',
'PhoneProofingStateDB',
'PhoneProofingUserDB',
'ProofingUser',
'LetterProofingState',
'EmailProofingState',
'OidcProofingState',
'OrcidProofingState',
'PhoneProofingState',
'EmailProofingElement',
'NinProofingElement',
'PhoneProofingElement',
]
9 changes: 9 additions & 0 deletions src/eduid/userdb/reset_password/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
ResetPasswordState,
)
from eduid.userdb.reset_password.user import ResetPasswordUser

__all__ = [
'ResetPasswordStateDB',
'ResetPasswordUserDB',
'ResetPasswordState',
'ResetPasswordEmailState',
'ResetPasswordEmailAndPhoneState',
'ResetPasswordUser',
]
19 changes: 19 additions & 0 deletions src/eduid/userdb/scimapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,22 @@
)
from eduid.userdb.scimapi.groupdb import GroupExtensions, ScimApiGroup, ScimApiGroupDB
from eduid.userdb.scimapi.userdb import ScimApiUser, ScimApiUserDB

__all__ = [
'ScimApiUser',
'ScimApiUserDB',
'ScimApiGroup',
'ScimApiGroupDB',
'ScimApiEvent',
'ScimApiEventDB',
'ScimApiEventResource',
'ScimApiResourceBase',
'ScimApiName',
'ScimApiEmail',
'ScimApiPhoneNumber',
'ScimApiProfile',
'ScimApiLinkedAccount',
'EventLevel',
'EventStatus',
'GroupExtensions',
]
9 changes: 9 additions & 0 deletions src/eduid/userdb/security/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
from eduid.userdb.security.state import PasswordResetEmailAndPhoneState, PasswordResetEmailState, PasswordResetState
from eduid.userdb.security.user import SecurityUser

__all__ = [
'PasswordResetState',
'PasswordResetEmailState',
'PasswordResetEmailAndPhoneState',
'PasswordResetStateDB',
'SecurityUser',
'SecurityUserDB',
]

__author__ = "lundberg"
Loading