Skip to content

Commit

Permalink
Modernize syntax with pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
gdubicki committed Nov 11, 2022
1 parent 6f9f93a commit b576341
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 13 deletions.
10 changes: 7 additions & 3 deletions gitlabform/configuration/core.py
@@ -1,3 +1,5 @@
from typing import Any

import os
import textwrap
from abc import ABC
Expand Down Expand Up @@ -57,7 +59,7 @@ def __init__(self, config_path=None, config_string=None):
# we are NOT checking for the existence of non-empty 'projects_and_groups' key here
# as it would break using GitLabForm as a library

except (FileNotFoundError, IOError):
except (FileNotFoundError, OSError):
raise ConfigFileNotFoundException(config_path)

except Exception as e:
Expand Down Expand Up @@ -110,7 +112,7 @@ def _parse_yaml(source: str, config_string: bool):

return yaml_data

def get(self, path, default=None):
def get(self, path, default=None) -> Any:
"""
:param path: "path" to given element in YAML file, for example for:
Expand Down Expand Up @@ -173,7 +175,9 @@ def is_skipped(self, an_array: list, item: str) -> bool:
pass

@staticmethod
def validate_break_inheritance_flag(config, section_name, parent_key=""):
def validate_break_inheritance_flag(
config: dict, section_name: str, parent_key: str = ""
):
for key, value in config.items():
if "inherit" == key:
parent_key_description = (
Expand Down
2 changes: 1 addition & 1 deletion gitlabform/core.py
Expand Up @@ -42,7 +42,7 @@ class Formatter(
pass


class GitLabForm(object):
class GitLabForm:
def __init__(self, include_archived_projects=True, target=None, config_string=None):

if target and config_string:
Expand Down
2 changes: 1 addition & 1 deletion gitlabform/filter.py
Expand Up @@ -5,7 +5,7 @@
from gitlabform import EXIT_INVALID_INPUT, Groups, Projects


class NonEmptyConfigsProvider(object):
class NonEmptyConfigsProvider:
"""
To speed up the processing of possibly long groups and projects lists we want to quickly remove
the ones that have an empty effective config.
Expand Down
2 changes: 1 addition & 1 deletion gitlabform/processors/project/files_processor.py
Expand Up @@ -273,7 +273,7 @@ def get_commit_message_for_file_change(operation, file, configuration: dict):
skip_build = configuration.get("files|" + file + "|skip_ci")
skip_build_str = " [skip ci]" if skip_build else ""

return "%s%s" % (commit_message, skip_build_str)
return f"{commit_message}{skip_build_str}"

@staticmethod
def get_group(project_and_group):
Expand Down
2 changes: 1 addition & 1 deletion gitlabform/processors/util/branch_protector.py
Expand Up @@ -6,7 +6,7 @@
from gitlabform.gitlab.core import NotFoundException


class BranchProtector(object):
class BranchProtector:
new_api_keys = [
"push_access_level",
"merge_access_level",
Expand Down
2 changes: 1 addition & 1 deletion gitlabform/processors/util/difference_logger.py
Expand Up @@ -11,7 +11,7 @@ def hide(text: str):
return f"<secret {hashlib.sha256(text.encode('utf-8')).hexdigest()[:8]}>"


class DifferenceLogger(object):
class DifferenceLogger:
@staticmethod
def log_diff(
subject,
Expand Down
2 changes: 1 addition & 1 deletion gitlabform/ui.py
Expand Up @@ -215,7 +215,7 @@ def info_project_count(prefix, i: int, n: int, *rest: Token, **kwargs: Any) -> N

def info_count(color, prefix, i: int, n: int, *rest: Token, **kwargs: Any) -> None:
num_digits = len(str(n))
counter_format = "(%{}d/%d)".format(num_digits)
counter_format = f"(%{num_digits}d/%d)"
counter_str = counter_format % (i, n)
info(color, prefix, reset, counter_str, reset, *rest, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/__init__.py
Expand Up @@ -29,7 +29,7 @@
print(f"Trying to read {file_path} ...")
if os.path.isfile(file_path):
try:
with open(file_path, "r") as file:
with open(file_path) as file:
os.environ[env_var] = file.read().strip()
print(f"{env_var} set!")
break
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/premium/test_merge_request_approvers.py
Expand Up @@ -314,11 +314,11 @@ def test__more_than_one_user_and_more_than_one_group(
for rule in rules:
if rule["name"] == APPROVAL_RULE_NAME:
assert len(rule["users"]) == 2
usernames_in_rule = set([user["username"] for user in rule["users"]])
usernames_in_rule = {user["username"] for user in rule["users"]}
assert usernames_in_rule == {user1.name, user2.name}

assert len(rule["groups"]) == 2
groupnames_in_rule = set([group["name"] for group in rule["groups"]])
groupnames_in_rule = {group["name"] for group in rule["groups"]}
assert groupnames_in_rule == {
group_with_one_owner_and_two_developers,
group_with_just_owner,
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/standard/test_group_variables.py
Expand Up @@ -95,7 +95,7 @@ def test__more_variables(self, gitlab, group_for_function):
run_gitlabform(config_more_variables, group_for_function)

variables = gitlab.get_group_variables(group_for_function)
variables_keys = set([variable["key"] for variable in variables])
variables_keys = {variable["key"] for variable in variables}
assert len(variables) == 2
assert variables_keys == {"FOO", "BAR"}

Expand Down

0 comments on commit b576341

Please sign in to comment.