Skip to content

Commit d9811db

Browse files
committed
Lint Python files using ruff
1 parent 68e3a10 commit d9811db

File tree

13 files changed

+65
-28
lines changed

13 files changed

+65
-28
lines changed

.config/ruff.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
line-length = 120
2+
3+
target-version = "py39"
4+
5+
src = ["docs-gen", "image/src"]
6+
7+
include = [
8+
"docs-gen/*.py",
9+
"image/src/*.py",
10+
"image/src/setup.py",
11+
"tools/*.py",
12+
]
13+
14+
[lint]
15+
# Allow fix for all enabled rules (when `--fix`) is provided.
16+
fixable = ["ALL"]
17+
unfixable = []
18+
19+
# Allow unused variables when underscore-prefixed.
20+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
21+
22+
[lint.flake8-quotes]
23+
inline-quotes = "single"
24+
multiline-quotes = "single"
25+
docstring-quotes = "double"
26+
27+
[format]
28+
quote-style = "single"
29+
docstring-code-format = true

.github/workflows/test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,7 @@ jobs:
148148
yamllint -c .config/.yamllint.yaml .
149149
150150
V8R_CONFIG_FILE=.config/.v8rrc.yaml npx v8r --ignore-errors
151+
152+
- uses: astral-sh/ruff-action@9828f49eb4cadf267b40eaa330295c412c68c1f9 # v3
153+
with:
154+
args: --config=.config/ruff.toml check

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
/venv/
55
.terraform.lock.hcl
66
.terraform-bin-dir/
7+
.gpg/
8+
build/
9+
__pycache__/
10+
.DS_Store
11+
*.egg-info/

docs-gen/action.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import textwrap
2-
from dataclasses import dataclass, field
2+
import dataclasses
3+
from dataclasses import dataclass
34
from textwrap import indent
45
from typing import Callable, Type
56

@@ -93,9 +94,9 @@ class Output:
9394
description: str
9495
meta_description: str = None
9596
type: str = None
96-
aliases: list[str] = field(default_factory=list)
97+
aliases: list[str] = dataclasses.field(default_factory=list)
9798
meta_output: bool = False
98-
available_in: list[Type[Terraform] | Type[OpenTofu]] = field(default_factory=lambda: [Terraform, OpenTofu])
99+
available_in: list[Type[Terraform] | Type[OpenTofu]] = dataclasses.field(default_factory=lambda: [Terraform, OpenTofu])
99100

100101
def markdown(self, tool: Tool) -> str:
101102
if self.meta_output:
@@ -135,11 +136,11 @@ class Action:
135136
name: str
136137
description: str | Callable[[Tool], str]
137138
meta_description: str = None
138-
inputs: list[Input] = field(default_factory=list)
139+
inputs: list[Input] = dataclasses.field(default_factory=list)
139140
inputs_intro: str = None
140141
environment_variables: list[EnvVar] = None
141142
environment_variables_intro: str = None
142-
outputs: list[Output] = field(default_factory=list)
143+
outputs: list[Output] = dataclasses.field(default_factory=list)
143144
outputs_intro: str = None
144145
extra: str | Callable[[bool], str] = None
145146

@@ -318,4 +319,4 @@ def action_yaml(self, tool: Tool) -> str:
318319
color: purple
319320
''', trailing_blank_line=False)
320321

321-
return productize(s, tool)
322+
return productize(s, tool)

docs-gen/actions/new_workspace.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from action import Action
44
from environment_variables.GITHUB_DOT_COM_TOKEN import GITHUB_DOT_COM_TOKEN
5-
from environment_variables.TERRAFORM_ACTIONS_GITHUB_TOKEN import TERRAFORM_ACTIONS_GITHUB_TOKEN
65
from environment_variables.TERRAFORM_CLOUD_TOKENS import TERRAFORM_CLOUD_TOKENS
76
from environment_variables.TERRAFORM_HTTP_CREDENTIALS import TERRAFORM_HTTP_CREDENTIALS
87
from environment_variables.TERRAFORM_PRE_RUN import TERRAFORM_PRE_RUN

docs-gen/actions/remote_state.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from inputs.backend_config import backend_config
77
from inputs.backend_config_file import backend_config_file
88
from inputs.backend_type import backend_type
9-
from inputs.path import path
109
from inputs.workspace import workspace
1110
from outputs.terraform_outputs import terraform_outputs
1211

image/src/github_pr_comment/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ def format_description(action_inputs: PlanPrInputs, sensitive_variables: List[st
151151
label += f'\nWith backend config files: `{action_inputs["INPUT_BACKEND_CONFIG_FILE"]}`'
152152

153153
if action_inputs["INPUT_VAR"]:
154-
label += f'\n:warning: Using deprecated var input. Use the variables input instead.'
154+
label += '\n:warning: Using deprecated var input. Use the variables input instead.'
155155
if any(var_name in action_inputs["INPUT_VAR"] for var_name in sensitive_variables):
156-
label += f'\nWith vars: (sensitive values)'
156+
label += '\nWith vars: (sensitive values)'
157157
else:
158158
label += f'\nWith vars: `{action_inputs["INPUT_VAR"]}`'
159159

@@ -226,7 +226,7 @@ def graphql() -> Optional[str]:
226226
if response.ok:
227227
try:
228228
return response.json()['data']['viewer']['login']
229-
except Exception as e:
229+
except Exception:
230230
pass
231231

232232
debug('Failed to get current user from graphql')

image/src/plan_renderer/variables.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from textwrap import indent
33

44

5-
class Sensitive: pass
5+
class Sensitive:
6+
pass
67

78

89
def render_argument_list(argument_list: dict[str, Any]) -> str:

image/src/terraform/hcl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def is_loadable(path: Path) -> bool:
3131
debug('TimeoutExpired')
3232
# We found a file that won't parse :(
3333
return False
34-
except:
34+
except Exception:
3535
# If we get an exception, we can still try and load it.
3636
return True
3737

@@ -55,8 +55,8 @@ def loads(hcl: str) -> dict:
5555
if is_loadable(tmp_path):
5656
return hcl2.loads(hcl)
5757

58-
debug(f'Unable to load hcl')
59-
raise ValueError(f'Unable to load hcl')
58+
debug('Unable to load hcl')
59+
raise ValueError('Unable to load hcl')
6060

6161

6262
if __name__ == '__main__':

image/src/terraform/module.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ def get_remote_backend_config(
152152
'workspaces': {}
153153
})
154154

155-
for terraform in module.get('terraform', []):
156-
for backend in terraform.get('backend', []):
155+
for terraform_block in module.get('terraform', []):
156+
for backend in terraform_block.get('backend', []):
157157
if 'remote' not in backend:
158158
return None
159159

@@ -209,8 +209,8 @@ def get_cloud_config(module: TerraformModule, cli_config_path: Path) -> Optional
209209
'workspaces': {}
210210
})
211211

212-
for terraform in module.get('terraform', []):
213-
for cloud in terraform.get('cloud', []):
212+
for terraform_block in module.get('terraform', []):
213+
for cloud in terraform_block.get('cloud', []):
214214

215215
found = True
216216

@@ -245,13 +245,13 @@ def get_backend_type(module: TerraformModule) -> Optional[str]:
245245
:return: The name of the backend used by the module
246246
"""
247247

248-
for terraform in module.get('terraform', []):
249-
for backend in terraform.get('backend', []):
248+
for terraform_block in module.get('terraform', []):
249+
for backend in terraform_block.get('backend', []):
250250
for backend_type in backend:
251251
return str(backend_type)
252252

253-
for terraform in module.get('terraform', []):
254-
if 'cloud' in terraform:
253+
for terraform_block in module.get('terraform', []):
254+
if 'cloud' in terraform_block:
255255
return 'cloud'
256256

257257
return 'local'

0 commit comments

Comments
 (0)