Skip to content

Commit e6f4691

Browse files
committed
casing
1 parent bfcafd6 commit e6f4691

File tree

6 files changed

+40
-28
lines changed

6 files changed

+40
-28
lines changed

microSALT/utils/pubmlst/authentication.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from microSALT import app, logger
99
from microSALT.utils.pubmlst.exceptions import (
10-
PUBMLSTError,
10+
PubMLSTError,
1111
SessionTokenRequestError,
1212
SessionTokenResponseError,
1313
)
@@ -86,12 +86,12 @@ def get_new_session_token(self, db: str):
8686
else:
8787
raise SessionTokenRequestError(db, response.status_code, response.text)
8888

89-
except PUBMLSTError as e:
89+
except PubMLSTError as e:
9090
logger.error(f"Error during token fetching: {e}")
9191
raise
9292
except Exception as e:
9393
logger.error(f"Unexpected error: {e}")
94-
raise PUBMLSTError(
94+
raise PubMLSTError(
9595
f"Unexpected error while fetching session token for database '{db}': {e}"
9696
)
9797

@@ -136,11 +136,11 @@ def load_session_credentials(
136136
)
137137
return self.get_new_session_token(db)
138138

139-
except PUBMLSTError as e:
139+
except PubMLSTError as e:
140140
logger.error(f"PuBMLST-specific error occurred: {e}")
141141
raise
142142
except Exception as e:
143143
logger.error(f"Unexpected error: {e}")
144-
raise PUBMLSTError(
144+
raise PubMLSTError(
145145
f"Unexpected error while loading session token for database '{db}': {e}"
146146
)

microSALT/utils/pubmlst/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from microSALT.utils.pubmlst.constants import HTTPMethod, RequestType, ResponseHandler
99
from microSALT.utils.pubmlst.exceptions import (
1010
InvalidURLError,
11-
PUBMLSTError,
11+
PubMLSTError,
1212
SessionTokenRequestError,
1313
)
1414
from microSALT.utils.pubmlst.helpers import (
@@ -37,7 +37,7 @@ def __init__(self, service: str, database: str = None):
3737
self.session_token, self.session_secret = self.client_auth.load_session_credentials(
3838
self.database
3939
)
40-
except PUBMLSTError as e:
40+
except PubMLSTError as e:
4141
logger.error(f"Failed to initialize {service} client: {e}")
4242
raise
4343

@@ -116,10 +116,10 @@ def _make_request(
116116
) from e
117117
except requests.exceptions.RequestException as e:
118118
logger.error(f"Request failed: {e}")
119-
raise PUBMLSTError(f"Request failed: {e}") from e
119+
raise PubMLSTError(f"Request failed: {e}") from e
120120
except Exception as e:
121121
logger.error(f"Unexpected error during request: {e}")
122-
raise PUBMLSTError(f"An unexpected error occurred: {e}") from e
122+
raise PubMLSTError(f"An unexpected error occurred: {e}") from e
123123

124124
def query_databases(self):
125125
"""Query available databases."""
Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
class PUBMLSTError(Exception):
2-
"""Base exception for PUBMLST utilities."""
1+
class PubMLSTError(Exception):
2+
"""Base exception for PubMLST utilities."""
3+
34
def __init__(self, message=None):
4-
super(PUBMLSTError, self).__init__(f"PUBMLST: {message}")
5+
super(PubMLSTError, self).__init__(f"PubMLST: {message}")
6+
57

8+
class CredentialsFileNotFound(PubMLSTError):
9+
"""Raised when the PubMLST credentials file is not found."""
610

7-
class CredentialsFileNotFound(PUBMLSTError):
8-
"""Raised when the PUBMLST credentials file is not found."""
911
def __init__(self, credentials_file):
1012
message = (
1113
f"Credentials file not found: {credentials_file}. "
@@ -14,8 +16,9 @@ def __init__(self, credentials_file):
1416
super(CredentialsFileNotFound, self).__init__(message)
1517

1618

17-
class InvalidCredentials(PUBMLSTError):
19+
class InvalidCredentials(PubMLSTError):
1820
"""Raised when the credentials file contains invalid or missing fields."""
21+
1922
def __init__(self, missing_fields):
2023
message = (
2124
"Invalid credentials: All fields (CLIENT_ID, CLIENT_SECRET, ACCESS_TOKEN, ACCESS_SECRET) "
@@ -25,8 +28,9 @@ def __init__(self, missing_fields):
2528
super(InvalidCredentials, self).__init__(message)
2629

2730

28-
class PathResolutionError(PUBMLSTError):
31+
class PathResolutionError(PubMLSTError):
2932
"""Raised when the file path cannot be resolved from the configuration."""
33+
3034
def __init__(self, config_key):
3135
message = (
3236
f"Failed to resolve the path for configuration key: '{config_key}'. "
@@ -35,31 +39,38 @@ def __init__(self, config_key):
3539
super(PathResolutionError, self).__init__(message)
3640

3741

38-
class SaveSessionError(PUBMLSTError):
42+
class SaveSessionError(PubMLSTError):
3943
"""Raised when saving the session token fails."""
44+
4045
def __init__(self, db, reason):
4146
message = f"Failed to save session token for database '{db}': {reason}"
4247
super(SaveSessionError, self).__init__(message)
4348

4449

45-
class SessionTokenRequestError(PUBMLSTError):
50+
class SessionTokenRequestError(PubMLSTError):
4651
"""Raised when requesting a session token fails."""
52+
4753
def __init__(self, db, status_code, response_text):
48-
message = f"Failed to fetch session token for database '{db}': {status_code} - {response_text}"
54+
message = (
55+
f"Failed to fetch session token for database '{db}': {status_code} - {response_text}"
56+
)
4957
super(SessionTokenRequestError, self).__init__(message)
5058

5159

52-
class SessionTokenResponseError(PUBMLSTError):
60+
class SessionTokenResponseError(PubMLSTError):
5361
"""Raised when the session token response is invalid."""
62+
5463
def __init__(self, db, reason):
5564
message = f"Invalid session token response for database '{db}': {reason}"
5665
super(SessionTokenResponseError, self).__init__(message)
5766

58-
class InvalidURLError(PUBMLSTError):
67+
68+
class InvalidURLError(PubMLSTError):
5969
"""Raised when the provided URL does not match any known patterns."""
70+
6071
def __init__(self, href):
6172
message = (
62-
f"The provided URL '{href}' does not match any known PUBMLST API patterns. "
73+
f"The provided URL '{href}' does not match any known PubMLST API patterns. "
6374
"Please check the URL for correctness."
6475
)
6576
super(InvalidURLError, self).__init__(message)

microSALT/utils/pubmlst/get_credentials.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from microSALT.utils.pubmlst.helpers import get_path, get_service_config, folders_config
88
from microSALT.utils.pubmlst.constants import CREDENTIALS_KEY
99

10+
1011
def validate_credentials(client_id, client_secret):
1112
"""Ensure client_id and client_secret are not empty."""
1213
if not client_id or not client_id.strip():
@@ -117,7 +118,7 @@ def main(service, species=None):
117118

118119

119120
if __name__ == "__main__":
120-
parser = ArgumentParser(description="Get PUBMLST or Pasteur credentials.")
121+
parser = ArgumentParser(description="Get PubMLST or Pasteur credentials.")
121122
parser.add_argument(
122123
"-s",
123124
"--service",

microSALT/utils/pubmlst/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
CredentialsFileNotFound,
1111
InvalidCredentials,
1212
PathResolutionError,
13-
PUBMLSTError,
13+
PubMLSTError,
1414
SaveSessionError,
1515
)
1616
from microSALT.utils.pubmlst.constants import CREDENTIALS_KEY, URL_MAPS
@@ -138,11 +138,11 @@ def load_auth_credentials(service: str):
138138
raise
139139
except InvalidCredentials:
140140
raise
141-
except PUBMLSTError as e:
141+
except PubMLSTError as e:
142142
logger.error(f"Unexpected error in load_{service}_credentials: {e}")
143143
raise
144144
except Exception as e:
145-
raise PUBMLSTError(f"An unexpected error occurred while loading {service} credentials: {e}")
145+
raise PubMLSTError(f"An unexpected error occurred while loading {service} credentials: {e}")
146146

147147

148148
def save_session_token(service: str, db: str, token: str, secret: str, expiration_date: str):

microSALT/utils/referencer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from Bio import Entrez
1616
import xml.etree.ElementTree as ET
1717
from microSALT.store.db_manipulator import DB_Manipulator
18-
from microSALT.utils.pubmlst.exceptions import InvalidURLError, PUBMLSTError
18+
from microSALT.utils.pubmlst.exceptions import InvalidURLError, PubMLSTError
1919
from microSALT.utils.pubmlst.helpers import get_service_by_url
2020

2121

@@ -233,7 +233,7 @@ def fetch_external(self, force=False):
233233
{"version": last_updated},
234234
)
235235
self.db_access.reload_profiletable(organ)
236-
except PUBMLSTError as e:
236+
except PubMLSTError as e:
237237
self.logger.warning(f"Unable to update pubMLST external data: {e}")
238238
except Exception as e:
239239
self.logger.warning("Unable to update pubMLST external data: {}".format(e))

0 commit comments

Comments
 (0)