Merge ~paride/autopkgtest-cloud:ci_drop_lint_test into autopkgtest-cloud:master

Proposed by Paride Legovini
Status: Merged
Approved by: Tim Andersson
Approved revision: 10438fa34380da0ae9a6dc7aba9d219e3cfa5dd6
Merged at revision: 10438fa34380da0ae9a6dc7aba9d219e3cfa5dd6
Proposed branch: ~paride/autopkgtest-cloud:ci_drop_lint_test
Merge into: autopkgtest-cloud:master
Diff against target: 154 lines (+0/-138)
2 files modified
.launchpad.yaml (+0/-5)
dev/null (+0/-133)
Reviewer Review Type Date Requested Status
Tim Andersson Approve
Review via email: mp+445774@code.launchpad.net

Commit message

ci: drop lint_test, now fully covered by pre-commit

Also: fix the .launchopad.yaml permission, which for some reason was
chmod 755.

To post a comment you must log in.
Revision history for this message
Tim Andersson (andersson123) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/.launchpad.yaml b/.launchpad.yaml
0old mode 1007550old mode 100755
1new mode 1006441new mode 100644
index ee74e0f..9befb4f
--- a/.launchpad.yaml
+++ b/.launchpad.yaml
@@ -42,8 +42,3 @@ jobs:
42 - name: charmcraft42 - name: charmcraft
43 classic: true43 classic: true
44 run: ./ci/build_charms44 run: ./ci/build_charms
45 lint_test:
46 series: focal
47 architectures: amd64
48 packages: [pylint, python3, shellcheck, yamllint]
49 run: ./ci/lint_test
diff --git a/ci/lint_test b/ci/lint_test
50deleted file mode 10075545deleted file mode 100755
index 3fee7f5..0000000
--- a/ci/lint_test
+++ /dev/null
@@ -1,133 +0,0 @@
1#!/usr/bin/python3
2# pylint: disable = invalid-name, broad-except, subprocess-run-check
3"""
4Script to lint the scripts in the autopkgtest-cloud repository in CI
5"""
6import logging
7import os
8import pathlib
9import subprocess
10import sys
11
12
13def check_for_extension(input_list, output_list, extension):
14 """
15 Checks filepaths in a list for a given extension
16 """
17 for a in input_list:
18 if os.path.isfile(a):
19 # if str(a)[-3:] == extension:
20 if extension in str(a)[-6:]:
21 output_list.append(str(a))
22 return output_list
23
24
25def check_for_shebang(input_list, output_list, shebang):
26 """
27 Checks filepaths in a given list for a given shebang
28 """
29 for b in input_list:
30 if os.path.isfile(b):
31 try:
32 with open(b, "r", encoding="utf-8") as myfile:
33 file = myfile.read()
34 into_list = file.splitlines()
35 if len(into_list) > 1:
36 if into_list[0] == shebang:
37 output_list.append(str(b))
38 except Exception as _:
39 pass
40 return output_list
41
42
43def remove_list_from_list(input_list, remove_list):
44 """
45 Removes elements from remove_list from input_list
46 """
47 for ff in input_list:
48 if os.path.isfile(ff):
49 if str(ff) in remove_list:
50 input_list.remove(ff)
51 return input_list
52
53
54def run_lint_command(files_to_lint, lint_command, arguments=None):
55 """
56 Runs a given lint command over a list of filepaths and stores output
57 and exit code
58 """
59 exit_codes = 0
60 lint_output = ""
61 # check lint command exists
62 for f in files_to_lint:
63 if arguments is None:
64 cmd = [lint_command, f]
65 result = subprocess.run(cmd, stdout=subprocess.PIPE)
66 else:
67 cmd = [lint_command]
68 for arg in arguments.split(" "):
69 cmd.append(arg)
70 cmd.append(f)
71 result = subprocess.run(cmd, stdout=subprocess.PIPE)
72 lint_output += result.stdout.decode("utf-8") + "\n"
73 exit_codes += result.returncode
74 return lint_output, exit_codes
75
76
77if __name__ == "__main__":
78 logging.basicConfig(level=logging.INFO)
79 logger = logging.getLogger("autopkgtest-cloud-linter")
80
81 start_dir = "../"
82 repo_dir = pathlib.Path(start_dir)
83 repo_dir.rglob("*")
84
85 final_list_of_python_files = []
86 all_files = list(repo_dir.rglob("*"))
87
88 data = {
89 "pylint": {
90 "files": [],
91 "extensions": [".py"],
92 "shebangs": ["#!/usr/bin/python3"],
93 "args": None,
94 "output": "",
95 "code": 0,
96 },
97 }
98
99 for key, item in data.items():
100 if item["extensions"] is not None:
101 for extension in item["extensions"]:
102 data[key]["files"] = check_for_extension(
103 all_files, data[key]["files"], extension
104 )
105 all_files = remove_list_from_list(
106 all_files, data[key]["files"]
107 )
108 if item["shebangs"] is not None:
109 for shebang in item["shebangs"]:
110 data[key]["files"] = check_for_shebang(
111 all_files, data[key]["files"], shebang
112 )
113 all_files = remove_list_from_list(
114 all_files, data[key]["files"]
115 )
116 data[key]["output"], data[key]["code"] = run_lint_command(
117 data[key]["files"], key, data[key]["args"]
118 )
119 ecodesum = 0
120 for _, oec in data.items():
121 ecodesum += oec["code"]
122 if ecodesum > 0:
123 for key, item in data.items():
124 if item["code"] > 0:
125 # logger.info("%s output: \n%s", key, item["output"])
126 logger.info("%s failed!", key)
127 # sys.exit(1)
128 # temporary exit code, will be set back to 1 when python and bash scripts have been linted
129 # right now we are just checking yaml files
130 if key == "yamllint" and item["code"] != 0:
131 sys.exit(1)
132 sys.exit(0)
133 sys.exit(0)

Subscribers

People subscribed via source and target branches