Skip to content

Commit

Permalink
chore: Enable Ruff RUF rules
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Aug 16, 2024
1 parent e0a007c commit 933514a
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 104 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ select = [
"UP", # pyupgrade
"FA", # flake8-future-annotations
"SIM", # flake8-simplify
"RUF", # Ruff-specific rules
]
2 changes: 1 addition & 1 deletion tap_github/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def is_valid_token(self) -> bool:
msg = (
f"A token could not be validated. "
f"{response.status_code} Client Error: "
f"{str(response.content)} (Reason: {response.reason})"
f"{response.content!s} (Reason: {response.reason})"
)
if self.logger is not None:
self.logger.warning(msg)
Expand Down
14 changes: 7 additions & 7 deletions tap_github/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import random
import time
from types import FrameType
from typing import Any, Iterable, cast
from typing import Any, ClassVar, Iterable, cast
from urllib.parse import parse_qs, urlparse

import requests
Expand Down Expand Up @@ -49,9 +49,9 @@ def authenticator(self) -> GitHubTokenAuthenticator:
def url_base(self) -> str:
return self.config.get("api_url_base", self.DEFAULT_API_BASE_URL)

primary_keys = ["id"]
primary_keys: ClassVar[list[str]] = ["id"]
replication_key: str | None = None
tolerated_http_errors: list[int] = []
tolerated_http_errors: ClassVar[list[int]] = []

@property
def http_headers(self) -> dict[str, str]:
Expand Down Expand Up @@ -187,7 +187,7 @@ def validate_response(self, response: requests.Response) -> None:
"""
full_path = urlparse(response.url).path
if response.status_code in (
self.tolerated_http_errors + [EMPTY_REPO_ERROR_STATUS]
[*self.tolerated_http_errors, EMPTY_REPO_ERROR_STATUS]
):
msg = (
f"{response.status_code} Tolerated Status Code "
Expand All @@ -199,7 +199,7 @@ def validate_response(self, response: requests.Response) -> None:
if 400 <= response.status_code < 500:
msg = (
f"{response.status_code} Client Error: "
f"{str(response.content)} (Reason: {response.reason}) for path: {full_path}" # noqa: E501
f"{response.content!s} (Reason: {response.reason}) for path: {full_path}" # noqa: E501
)
# Retry on rate limiting
if (
Expand Down Expand Up @@ -236,15 +236,15 @@ def validate_response(self, response: requests.Response) -> None:
elif 500 <= response.status_code < 600:
msg = (
f"{response.status_code} Server Error: "
f"{str(response.content)} (Reason: {response.reason}) for path: {full_path}" # noqa: E501
f"{response.content!s} (Reason: {response.reason}) for path: {full_path}" # noqa: E501
)
raise RetriableAPIError(msg, response)

def parse_response(self, response: requests.Response) -> Iterable[dict]:
"""Parse the response and return an iterator of result rows."""
# TODO - Split into handle_reponse and parse_response.
if response.status_code in (
self.tolerated_http_errors + [EMPTY_REPO_ERROR_STATUS]
[*self.tolerated_http_errors, EMPTY_REPO_ERROR_STATUS]
):
return

Expand Down
14 changes: 7 additions & 7 deletions tap_github/organization_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Any, Iterable
from typing import Any, ClassVar, Iterable

from singer_sdk import typing as th # JSON Schema typing helpers

Expand Down Expand Up @@ -70,11 +70,11 @@ class TeamsStream(GitHubRestStream):
"""

name = "teams"
primary_keys = ["id"]
primary_keys: ClassVar[list[str]] = ["id"]
path = "/orgs/{org}/teams"
ignore_parent_replication_key = True
parent_stream_type = OrganizationStream
state_partitioning_keys = ["org"]
state_partitioning_keys: ClassVar[list[str]] = ["org"]

def get_child_context(self, record: dict, context: dict | None) -> dict:
new_context = {"team_slug": record["slug"]}
Expand Down Expand Up @@ -125,11 +125,11 @@ class TeamMembersStream(GitHubRestStream):
"""

name = "team_members"
primary_keys = ["id", "team_slug"]
primary_keys: ClassVar[list[str]] = ["id", "team_slug"]
path = "/orgs/{org}/teams/{team_slug}/members"
ignore_parent_replication_key = True
parent_stream_type = TeamsStream
state_partitioning_keys = ["team_slug", "org"]
state_partitioning_keys: ClassVar[list[str]] = ["team_slug", "org"]

def get_child_context(self, record: dict, context: dict | None) -> dict:
new_context = {"username": record["login"]}
Expand Down Expand Up @@ -165,9 +165,9 @@ class TeamRolesStream(GitHubRestStream):
name = "team_roles"
path = "/orgs/{org}/teams/{team_slug}/memberships/{username}"
ignore_parent_replication_key = True
primary_keys = ["url"]
primary_keys: ClassVar[list[str]] = ["url"]
parent_stream_type = TeamMembersStream
state_partitioning_keys = ["username", "team_slug", "org"]
state_partitioning_keys: ClassVar[list[str]] = ["username", "team_slug", "org"]

schema = th.PropertiesList(
# Parent keys
Expand Down
Loading

0 comments on commit 933514a

Please sign in to comment.