Skip to content

Commit 39db14d

Browse files
committed
Fix Python linter warnings
1 parent b724cea commit 39db14d

4 files changed

Lines changed: 51 additions & 103 deletions

File tree

bin/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ MYPY_ARGS = --strict --disable-error-code no-any-return
2323

2424
PYLINT_DIR = *.py
2525
PYLINT_PIP_PKGS = yamllint
26-
PYLINT_ARGS = --disable=invalid-name,duplicate-code
26+
PYLINT_ARGS = --disable=invalid-name,duplicate-code,consider-using-f-string
2727

2828
PYCODE_ARGS = --max-line-length=100
2929

bin/gen-docs-php-tools.py

Lines changed: 48 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os
55
import re
66
import sys
7-
from collections import OrderedDict
87
from typing import Dict, List, Any
98
import yaml
109

@@ -19,44 +18,30 @@
1918
DOC_FILE = str(os.path.join(REPOSITORY_PATH, "doc", "available-tools.md"))
2019

2120

22-
PHP_VERSIONS = ["5.2", "5.3", "5.4", "5.5", "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
21+
PHP_VERSIONS = [
22+
"5.2",
23+
"5.3",
24+
"5.4",
25+
"5.5",
26+
"5.6",
27+
"7.0",
28+
"7.1",
29+
"7.2",
30+
"7.3",
31+
"7.4",
32+
"8.0",
33+
"8.1",
34+
"8.2",
35+
]
2336

2437
DEFAULT_TOOLS = [
25-
{
26-
"name": "**composer**",
27-
"dir": "../.ansible/group_vars/all/work-help.yml",
28-
"exclude": []
29-
},
30-
{
31-
"name": "**corepack**",
32-
"dir": "../.ansible/group_vars/all/work-help.yml",
33-
"exclude": []
34-
},
35-
{
36-
"name": "**nvm**",
37-
"dir": "../.ansible/group_vars/all/work-help.yml",
38-
"exclude": []
39-
},
40-
{
41-
"name": "**npm**",
42-
"dir": "../.ansible/group_vars/all/work-help.yml",
43-
"exclude": []
44-
},
45-
{
46-
"name": "**node**",
47-
"dir": "../.ansible/group_vars/all/work-help.yml",
48-
"exclude": []
49-
},
50-
{
51-
"name": "**yarn**",
52-
"dir": "../.ansible/group_vars/all/work-help.yml",
53-
"exclude": []
54-
},
55-
{
56-
"name": "**pip**",
57-
"dir": "../.ansible/group_vars/all/work-help.yml",
58-
"exclude": []
59-
}
38+
{"name": "**composer**", "dir": "../.ansible/group_vars/all/work-help.yml", "exclude": []},
39+
{"name": "**corepack**", "dir": "../.ansible/group_vars/all/work-help.yml", "exclude": []},
40+
{"name": "**nvm**", "dir": "../.ansible/group_vars/all/work-help.yml", "exclude": []},
41+
{"name": "**npm**", "dir": "../.ansible/group_vars/all/work-help.yml", "exclude": []},
42+
{"name": "**node**", "dir": "../.ansible/group_vars/all/work-help.yml", "exclude": []},
43+
{"name": "**yarn**", "dir": "../.ansible/group_vars/all/work-help.yml", "exclude": []},
44+
{"name": "**pip**", "dir": "../.ansible/group_vars/all/work-help.yml", "exclude": []},
6045
]
6146

6247

@@ -115,12 +100,11 @@ def get_tools() -> List[Dict[str, Any]]:
115100
data = get_tool_options(item.name)
116101
tools.append(
117102
{
118-
"dir": "../php_tools/"+item.name,
103+
"dir": "../php_tools/" + item.name,
119104
"name": data["name"],
120-
"exclude": [str(x) for x in data["exclude"]]
105+
"exclude": [str(x) for x in data["exclude"]],
121106
}
122107
)
123-
#return tools
124108
return sorted(DEFAULT_TOOLS + tools, key=lambda tool: tool["name"].replace("*", ""))
125109

126110

@@ -131,18 +115,18 @@ def get_tools() -> List[Dict[str, Any]]:
131115

132116
def print_terminal(tools: List[Dict[str, Any]]) -> None:
133117
"""Print directory tools."""
134-
padding=15
118+
padding = 15
135119
# First Row
136-
print('| {name: <{padding}}| '.format(name="Tool", padding=padding), end="")
120+
print("| {name: <{padding}}| ".format(name="Tool", padding=padding), end="")
137121
print(" | ".join(PHP_VERSIONS), end="")
138122
print(" |")
139123
# Second Row
140-
print('|{name:-<{padding}}-|'.format(name="", padding=padding), end="")
124+
print("|{name:-<{padding}}-|".format(name="", padding=padding), end="")
141125
for php in PHP_VERSIONS:
142126
print("-----|", end="")
143127
print()
144128
for tool in tools:
145-
print('| {name: <{padding}}|'.format(name=tool["name"], padding=padding), end="")
129+
print("| {name: <{padding}}|".format(name=tool["name"], padding=padding), end="")
146130
for php in PHP_VERSIONS:
147131
if str(php) in tool["exclude"]:
148132
print(" |", end="")
@@ -151,21 +135,23 @@ def print_terminal(tools: List[Dict[str, Any]]) -> None:
151135
print()
152136

153137

154-
def get_markdown(tools: List[Dict[str, Any]]) -> None:
155-
"""Print directory tools."""
138+
def get_markdown(tools: List[Dict[str, Any]]) -> str:
139+
"""Get markdown tools table."""
156140
padding = 35
157141

158142
# First Row
159-
markdown = '| {name: <{padding}}| '.format(name="Tool", padding=padding)
143+
markdown = "| {name: <{padding}}| ".format(name="Tool", padding=padding)
160144
markdown += " | ".join(PHP_VERSIONS)
161145
markdown += " |\n"
162146
# Second Row
163-
markdown += '|{name:-<{padding}}-|'.format(name="", padding=padding)
147+
markdown += "|{name:-<{padding}}-|".format(name="", padding=padding)
164148
for php in PHP_VERSIONS:
165149
markdown += "-----|"
166150
markdown += "\n"
167151
for tool in tools:
168-
markdown += '| {name: <{padding}}|'.format(name="["+tool["name"]+"][lnk_"+tool["name"]+"]", padding=padding)
152+
markdown += "| {name: <{padding}}|".format(
153+
name="[" + tool["name"] + "][lnk_" + tool["name"] + "]", padding=padding
154+
)
169155
for php in PHP_VERSIONS:
170156
if str(php) in tool["exclude"]:
171157
markdown += " |"
@@ -175,62 +161,18 @@ def get_markdown(tools: List[Dict[str, Any]]) -> None:
175161

176162
markdown += "\n"
177163
for tool in tools:
178-
markdown += "[lnk_"+tool["name"]+"]: "+tool["dir"]+"\n"
164+
markdown += "[lnk_" + tool["name"] + "]: " + tool["dir"] + "\n"
179165

180166
return markdown
181167

182168

183-
184169
# --------------------------------------------------------------------------------------------------
185170
# MAIN FUNCTION
186171
# --------------------------------------------------------------------------------------------------
187-
def print_help() -> None:
188-
"""Show help screen."""
189-
print("Usage:", os.path.basename(__file__), "[options] [PHP-TOOL]...")
190-
print(" ", os.path.basename(__file__), "-h, --help")
191-
print()
192-
print("This script will generate the Ansible group_vars file: .ansible/group_vars/all/work.yml")
193-
print("based on all the tools found in php_tools/ directory.")
194-
print()
195-
print("Positional arguments:")
196-
print(" [PHP-TOOL] Specify None, one or more PHP tools to generate group_vars for.")
197-
print(" When no PHP tool is specified (argument is omitted), group_vars")
198-
print(" for all tools will be genrated.")
199-
print(" When one or more PHP tool are specified, only group_vars for")
200-
print(" these tools will be created.")
201-
print(" only be generated for this single tool (and its dependencies).")
202-
print(" This is useful if you want to test new tools and not build all")
203-
print(" previous tools in the Dockerfile.")
204-
print()
205-
print(" Note: You still need to generate the Dockerfiles via Ansible for")
206-
print(" the changes to take effect, before building the image.")
207-
print("Optional arguments:")
208-
print(" -i Ignore dependent tools.")
209-
print(" By default each tool is checked for dependencies of other")
210-
print(" tools.")
211-
print(" By specifying -i, those dependent tools are not beeing added to")
212-
print(" ansible group_vars. Use at your own risk.")
213172

214173

215-
def main(argv: List[str]) -> None:
174+
def main() -> None:
216175
"""Main entrypoint."""
217-
ignore_dependencies = False
218-
selected_tools = []
219-
if len(argv):
220-
for arg in argv:
221-
if arg in ("-h", "--help"):
222-
print_help()
223-
sys.exit(0)
224-
for arg in argv:
225-
if arg.startswith("-") and arg != "-i":
226-
print("Invalid argument:", arg)
227-
print("Use -h or --help for help")
228-
sys.exit(1)
229-
if arg == "-i":
230-
ignore_dependencies = True
231-
else:
232-
selected_tools.append(arg)
233-
234176
# Get tools in order of dependencies
235177
tools = get_tools()
236178

@@ -246,12 +188,18 @@ def main(argv: List[str]) -> None:
246188
markdown = get_markdown(tools)
247189
print()
248190

249-
with open(DOC_FILE, "r") as f:
191+
with open(DOC_FILE, "r", encoding="utf8") as f:
250192
content = f.read()
251-
content_new = re.sub(r'(\<\!\-\- TOOLS_WORK_START \-\-\>)(.*)(\<\!\-\- TOOLS_WORK_END \-\-\>)', r"\1\n\n"+markdown+r"\n\3", content, flags = re.DOTALL)
252-
253-
with open(DOC_FILE, "w") as f:
193+
content_new = re.sub(
194+
r"(\<\!\-\- TOOLS_WORK_START \-\-\>)(.*)(\<\!\-\- TOOLS_WORK_END \-\-\>)",
195+
r"\1\n\n" + markdown + r"\n\3",
196+
content,
197+
flags=re.DOTALL,
198+
)
199+
200+
with open(DOC_FILE, "w", encoding="utf8") as f:
254201
f.write(content_new)
255202

203+
256204
if __name__ == "__main__":
257-
main(sys.argv[1:])
205+
main()

bin/gen-php-modules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def get_modules(selected_modules: List[str], ignore_dependencies: bool) -> List[
9191
"dir": item.name,
9292
"name": data["name"],
9393
"deps": data["depends_build"],
94-
"exclude": data["exclude"]
94+
"exclude": data["exclude"],
9595
}
9696
)
9797
# Convert list of deps into dict(dir, name, deps)

bin/gen-php-tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def get_tools(selected_tools: List[str], ignore_dependencies: bool) -> List[Dict
8686
"dir": item.name,
8787
"name": data["name"],
8888
"deps": data["depends"],
89-
"exclude": data["exclude"]
89+
"exclude": data["exclude"],
9090
}
9191
)
9292
# Convert list of deps into dict(dir, name, deps)

0 commit comments

Comments
 (0)