Skip to content

Commit

Permalink
chore: Upgrade ruff to 0.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
aahung committed May 28, 2024
1 parent 68ea186 commit ab87b24
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ black-check:
make format-check

lint:
ruff samtranslator bin schema_source integration tests
ruff check samtranslator bin schema_source integration tests
# mypy performs type check
mypy --strict samtranslator bin schema_source
# cfn-lint to make sure generated CloudFormation makes sense
bin/run_cfn_lint.sh

lint-fix:
ruff --fix samtranslator bin schema_source integration tests
ruff check --fix samtranslator bin schema_source integration tests

prepare-companion-stack:
pytest -v --no-cov integration/setup -m setup
Expand Down
10 changes: 5 additions & 5 deletions integration/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# black formatter takes care of the line length
line-length = 999

# Mininal python version we support is 3.8
target-version = "py38"

# The code quality of tests can be a bit lower compared to samtranslator
select = [
lint.select = [
"E", # Pyflakes
"F", # Pyflakes
"PL", # pylint
Expand All @@ -15,10 +18,7 @@ select = [
"UP", # pyupgrade
]

# Mininal python version we support is 3.8
target-version = "py38"

[per-file-ignores]
[lint.per-file-ignores]

# The code quality of tests can be a bit lower:
"**/*.py" = [
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pytest-xdist>=2.5,<4
pytest-env>=0.6,<1
pytest-rerunfailures>=9.1,<12
pyyaml~=6.0
ruff~=0.1.0
ruff~=0.4.5

# Test requirements
pytest>=6.2,<8
Expand Down
14 changes: 7 additions & 7 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# black formatter takes care of the line length
line-length = 999

select = [
# Mininal python version we support is 3.8
target-version = "py38"

lint.select = [
"E", # pycodestyle
"W", # pycodestyle
"F", # Pyflakes
Expand All @@ -27,7 +30,7 @@ select = [
"T20", # flake8-print
]

ignore = [
lint.ignore = [
"UP006", # https://github.com/charliermarsh/ruff/pull/4427
"UP007", # https://github.com/charliermarsh/ruff/pull/4427
# Mutable class attributes should be annotated with `typing.ClassVar`
Expand All @@ -37,10 +40,7 @@ ignore = [
"G004",
]

# Mininal python version we support is 3.8
target-version = "py38"

[per-file-ignores]
[lint.per-file-ignores]
# python scripts in bin/ needs some python path configurations before import
"bin/*.py" = [
# E402: module-import-not-at-top-of-file
Expand All @@ -53,5 +53,5 @@ target-version = "py38"
"T201",
]

[pylint]
[lint.pylint]
max-args = 6 # We have many functions reaching 6 args
3 changes: 1 addition & 2 deletions samtranslator/model/api/http_api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,7 @@ def _get_authorizers(
if "OpenIdConnectUrl" in authorizer:
raise InvalidResourceException(
self.logical_id,
"'OpenIdConnectUrl' is no longer a supported property for authorizer '%s'. Please refer to the AWS SAM documentation."
% (authorizer_name),
f"'OpenIdConnectUrl' is no longer a supported property for authorizer '{authorizer_name}'. Please refer to the AWS SAM documentation.",
)
authorizers[authorizer_name] = ApiGatewayV2Authorizer( # type: ignore[no-untyped-call]
api_logical_id=self.logical_id,
Expand Down
12 changes: 6 additions & 6 deletions samtranslator/model/eventsources/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def _depend_on_lambda_permissions_using_tag(
dependency, so CloudFormation will automatically wait once it reaches that function, the same
as if you were using a DependsOn.
"""
properties = bucket.get("Properties", None)
properties = bucket.get("Properties")
if properties is None:
properties = {}
bucket["Properties"] = properties
Expand Down Expand Up @@ -576,14 +576,14 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def]
sqs_subscription: Dict[str, Any] = sam_expect(
self.SqsSubscription, self.relative_id, "SqsSubscription", is_sam_event=True
).to_be_a_map()
queue_arn = sqs_subscription.get("QueueArn", None)
queue_url = sqs_subscription.get("QueueUrl", None)
queue_arn = sqs_subscription.get("QueueArn")
queue_url = sqs_subscription.get("QueueUrl")
if not queue_arn or not queue_url:
raise InvalidEventException(self.relative_id, "No QueueARN or QueueURL provided.")

queue_policy_logical_id = sqs_subscription.get("QueuePolicyLogicalId", None)
batch_size = sqs_subscription.get("BatchSize", None)
enabled = sqs_subscription.get("Enabled", None)
queue_policy_logical_id = sqs_subscription.get("QueuePolicyLogicalId")
batch_size = sqs_subscription.get("BatchSize")
enabled = sqs_subscription.get("Enabled")

queue_policy = self._inject_sqs_queue_policy( # type: ignore[no-untyped-call]
self.Topic, queue_arn, queue_url, function, queue_policy_logical_id
Expand Down
4 changes: 2 additions & 2 deletions samtranslator/model/intrinsics.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ def make_shorthand(intrinsic_dict: Dict[str, Any]) -> str:
:raises NotImplementedError: For intrinsic functions that don't support shorthands.
"""
if "Ref" in intrinsic_dict:
return "${%s}" % intrinsic_dict["Ref"]
return "${{{}}}".format(intrinsic_dict["Ref"])
if "Fn::GetAtt" in intrinsic_dict:
return "${%s}" % ".".join(intrinsic_dict["Fn::GetAtt"])
return "${{{}}}".format(".".join(intrinsic_dict["Fn::GetAtt"]))
raise NotImplementedError("Shorthanding is only supported for Ref and Fn::GetAtt")


Expand Down
4 changes: 2 additions & 2 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def resources_to_link(self, resources: Dict[str, Any]) -> Dict[str, Any]:
raise InvalidResourceException(self.logical_id, e.message) from e

@cw_timer
def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: PLR0912, PLR0915
def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: PLR0915
"""Returns the Lambda function, role, and event resources to which this SAM Function corresponds.
:param dict kwargs: already-converted resources that may need to be modified when converting this \
Expand Down Expand Up @@ -1914,7 +1914,7 @@ def to_cloudformation(self, **kwargs: Any) -> List[Resource]:

raise InvalidResourceException(self.logical_id, "'Destination' is an empty list")

def generate_resources( # noqa: PLR0912
def generate_resources(
self,
source: ConnectorResourceReference,
destination: ConnectorResourceReference,
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/sdk/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def add_default_parameter_values(self, sam_template: Dict[str, Any]) -> Any:
:return dict: Merged parameter values
"""

parameter_definition = sam_template.get("Parameters", None)
parameter_definition = sam_template.get("Parameters")
if not parameter_definition or not isinstance(parameter_definition, dict):
return self.parameter_values

Expand Down
8 changes: 4 additions & 4 deletions samtranslator/sdk/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def __init__(self, resource_dict: Dict[str, Any]) -> None:

self.resource_dict = resource_dict
self.type = resource_dict.get("Type")
self.condition = resource_dict.get("Condition", None)
self.deletion_policy = resource_dict.get("DeletionPolicy", None)
self.update_replace_policy = resource_dict.get("UpdateReplacePolicy", None)
self.ignore_globals: Optional[Union[str, List[str]]] = resource_dict.get("IgnoreGlobals", None)
self.condition = resource_dict.get("Condition")
self.deletion_policy = resource_dict.get("DeletionPolicy")
self.update_replace_policy = resource_dict.get("UpdateReplacePolicy")
self.ignore_globals: Optional[Union[str, List[str]]] = resource_dict.get("IgnoreGlobals")

# Properties is *not* required. Ex: SimpleTable resource has no required properties
self.properties = resource_dict.get("Properties", {})
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/third_party/py27hash/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def hash(value): # type: ignore[no-untyped-def]
if isinstance(value, int):
return hash(value)

raise TypeError("unhashable type: '%s'" % (type(value).__name__))
raise TypeError(f"unhashable type: '{type(value).__name__}'")

@staticmethod
def thash(value): # type: ignore[no-untyped-def]
Expand Down
8 changes: 4 additions & 4 deletions samtranslator/utils/py27hash_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,14 @@ def __str__(self) -> str:
for i, key in enumerate(self):
string += ", " if i > 0 else ""
if isinstance(key, ("".__class__, bytes)):
string += "%s: " % key.__repr__()
string += f"{key.__repr__()}: "
else:
string += "%s: " % key
string += f"{key}: "

if isinstance(self[key], ("".__class__, bytes)):
string += "%s" % self[key].__repr__()
string += str(self[key].__repr__())
else:
string += "%s" % self[key]
string += str(self[key])

string += "}"
return string
Expand Down
2 changes: 1 addition & 1 deletion tests/model/api/test_http_api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_auth_iam_not_enabled_with_unsupported_values(self):
}
self.kwargs["definition_body"] = OpenApiEditor.gen_skeleton()
http_api = HttpApiGenerator(**self.kwargs)._construct_http_api()
self.assertNotIn("components", http_api.Body, "EnableIamAuthorizer value: %s" % val)
self.assertNotIn("components", http_api.Body, f"EnableIamAuthorizer value: {val}")

def test_auth_novalue_default_does_not_raise(self):
self.kwargs["auth"] = self.authorizers
Expand Down
10 changes: 5 additions & 5 deletions tests/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# black formatter takes care of the line length
line-length = 999

# Mininal python version we support is 3.8
target-version = "py38"

# The code quality of tests can be a bit lower compared to samtranslator
select = [
lint.select = [
"E", # Pyflakes
"F", # Pyflakes
"PL", # pylint
Expand All @@ -15,10 +18,7 @@ select = [
"UP", # pyupgrade
]

# Mininal python version we support is 3.8
target-version = "py38"

[per-file-ignores]
[lint.per-file-ignores]

# The code quality of tests can be a bit lower:
"**/*.py" = [
Expand Down

0 comments on commit ab87b24

Please sign in to comment.