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

chore: Enable Ruff SIM rule #294

Merged
merged 1 commit into from
Aug 16, 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
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ markers = [
[tool.ruff.lint]
ignore = []
select = [
"F", # Pyflakes
"E", # pycodestyle (errors)
"W", # pycodestyle (warnings)
"I", # isort
"UP", # pyupgrade
"FA", # flake8-future-annotations
"F", # Pyflakes
"E", # pycodestyle (errors)
"W", # pycodestyle (warnings)
"I", # isort
"UP", # pyupgrade
"FA", # flake8-future-annotations
"SIM", # flake8-simplify
]
12 changes: 5 additions & 7 deletions tap_github/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ def has_calls_remaining(self) -> bool:
"""
if self.rate_limit_reset is None:
return True
if (
self.rate_limit_used > (self.rate_limit - self.rate_limit_buffer)
and self.rate_limit_reset > datetime.now()
):
return False
return True
return (
self.rate_limit_used <= (self.rate_limit - self.rate_limit_buffer)
or self.rate_limit_reset <= datetime.now()
)


class PersonalTokenManager(TokenManager):
Expand Down Expand Up @@ -283,7 +281,7 @@ def prepare_tokens(self) -> list[TokenManager]:
logging.warn("A token was dismissed.")

# Parse App level private key and generate a token
if "GITHUB_APP_PRIVATE_KEY" in env_dict.keys():
if "GITHUB_APP_PRIVATE_KEY" in env_dict:
# To simplify settings, we use a single env-key formatted as follows:
# "{app_id};;{-----BEGIN RSA PRIVATE KEY-----\n_YOUR_PRIVATE_KEY_\n-----END RSA PRIVATE KEY-----}" # noqa: E501
env_key = env_dict["GITHUB_APP_PRIVATE_KEY"]
Expand Down
7 changes: 2 additions & 5 deletions tap_github/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,11 @@ def get_next_page_token(
return None

# Leverage header links returned by the GitHub API.
if "next" not in response.links.keys():
if "next" not in response.links:
return None

resp_json = response.json()
if isinstance(resp_json, list):
results = resp_json
else:
results = resp_json.get("items")
results = resp_json if isinstance(resp_json, list) else resp_json.get("items")

# Exit early if the response has no items. ? Maybe duplicative the "next" link check. # noqa: E501
if not results:
Expand Down
4 changes: 2 additions & 2 deletions tap_github/repository_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def validate_response(self, response: requests.Response) -> None:
# Also remove repos which do not exist to avoid crashing further down
# the line.
for record in temp_stream.request_records({}):
for item in record.keys():
for item in record:
if item == "rateLimit":
continue
try:
Expand Down Expand Up @@ -1007,7 +1007,7 @@ def get_records(self, context: dict | None = None) -> Iterable[dict[str, Any]]:

def post_process(self, row: dict, context: dict | None = None) -> dict:
row = super().post_process(row, context)
if "issue" in row.keys():
if "issue" in row:
row["issue_number"] = int(row["issue"].pop("number"))
row["issue_url"] = row["issue"].pop("url")
else:
Expand Down
4 changes: 2 additions & 2 deletions tap_github/scraping.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ def scrape_metrics(
# sometimes the dependents section isn't shown on the page either
dependents_node_parent = getattr(dependents_node, "parent", None)
dependents: int = 0
if dependents_node_parent is not None and "href" in dependents_node_parent:
if dependents_node_parent is not None and "href" in dependents_node_parent: # noqa: SIM102
if dependents_node_parent["href"].endswith("/network/dependents"):
dependents = parse_counter(getattr(dependents_node, "next_element", None))

# likewise, handle edge cases with contributors
contributors_node = soup.find(string=contributors_regex)
contributors_node_parent = getattr(contributors_node, "parent", None)
contributors: int = 0
if contributors_node_parent is not None and "href" in contributors_node_parent:
if contributors_node_parent is not None and "href" in contributors_node_parent: # noqa: SIM102
if contributors_node_parent["href"].endswith("/graphs/contributors"):
contributors = parse_counter(
getattr(contributors_node, "next_element", None),
Expand Down
10 changes: 2 additions & 8 deletions tap_github/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ def username_list_config(request):
@pytest.mark.username_list(['ericboucher', 'aaronsteers'])
"""
marker = request.node.get_closest_marker("username_list")
if marker is None:
username_list = ["ericboucher", "aaronsteers"]
else:
username_list = marker.args[0]
username_list = ["ericboucher", "aaronsteers"] if marker is None else marker.args[0]

return {
"metrics_log_level": "warning",
Expand All @@ -72,10 +69,7 @@ def user_id_list_config(request):
@pytest.mark.user_id_list(['ericboucher', 'aaronsteers'])
"""
marker = request.node.get_closest_marker("user_id_list")
if marker is None:
user_id_list = [1, 2]
else:
user_id_list = marker.args[0]
user_id_list = [1, 2] if marker is None else marker.args[0]

return {
"metrics_log_level": "warning",
Expand Down
14 changes: 6 additions & 8 deletions tap_github/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ def test_standard_tap_tests_for_search_mode(search_config): # noqa: F811
tests = get_standard_tap_tests(TapGitHub, config=search_config)
with patch(
"singer_sdk.streams.core.Stream._sync_children", alternative_sync_chidren
):
with nostdout():
for test in tests:
test()
), nostdout():
for test in tests:
test()


def test_standard_tap_tests_for_repo_list_mode(repo_list_config): # noqa: F811
"""Run standard tap tests from the SDK."""
tests = get_standard_tap_tests(TapGitHub, config=repo_list_config)
with patch(
"singer_sdk.streams.core.Stream._sync_children", alternative_sync_chidren
):
with nostdout():
for test in tests:
test()
), nostdout():
for test in tests:
test()


def test_standard_tap_tests_for_username_list_mode(username_list_config): # noqa: F811
Expand Down
2 changes: 1 addition & 1 deletion tap_github/user_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def query(self) -> str:
# Also remove repos which do not exist to avoid crashing further down
# the line.
for record in temp_stream.request_records({}):
for item in record.keys():
for item in record:
if item == "rateLimit":
continue
try:
Expand Down