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

Subscribers

People subscribed via source and target branches