diff --git a/.github/workflows/test_and_deploy.yml b/.github/workflows/test_and_deploy.yml index e96ef885924..18582e96fd9 100644 --- a/.github/workflows/test_and_deploy.yml +++ b/.github/workflows/test_and_deploy.yml @@ -27,6 +27,13 @@ jobs: run: | ./scripts/test.sh format + python-lint: + name: Lint Python code with ruff + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: astral-sh/ruff-action@v3 + python-tests: name: Python ${{ matrix.python-version }} tests runs-on: ubuntu-22.04 @@ -77,7 +84,7 @@ jobs: deploy: name: Generate and push C headers - needs: [format, python-tests, node-tests] + needs: [format, python-lint, python-tests, node-tests] runs-on: ubuntu-22.04 if: github.ref == 'refs/heads/master' env: diff --git a/mavgenerate.py b/mavgenerate.py index bd3b1cac60c..050d36d3340 100755 --- a/mavgenerate.py +++ b/mavgenerate.py @@ -174,14 +174,14 @@ def generateHeaders(self): return # Generate headers - opts = mavgen.Opts(self.out_value.get(), wire_protocol=self.protocol_value.get(), language=self.language_value.get(), validate=self.validate_value.get(), error_limit=error_limit, strict_units=self.strict_units_value.get()); + opts = mavgen.Opts(self.out_value.get(), wire_protocol=self.protocol_value.get(), language=self.language_value.get(), validate=self.validate_value.get(), error_limit=error_limit, strict_units=self.strict_units_value.get()) args = [self.xml_value.get()] try: mavgen.mavgen(opts,args) tkinter.messagebox.showinfo('Successfully Generated Headers', 'Headers generated successfully.') except Exception as ex: - exStr = formatErrorMessage(str(ex)); + exStr = formatErrorMessage(str(ex)) tkinter.messagebox.showerror('Error Generating Headers','{0!s}'.format(exStr)) return @@ -189,10 +189,10 @@ def generateHeaders(self): Format the mavgen exceptions by removing 'ERROR: '. """ def formatErrorMessage(message): - reObj = re.compile(r'^(ERROR):\s+',re.M); - matches = re.findall(reObj, message); + reObj = re.compile(r'^(ERROR):\s+',re.M) + matches = re.findall(reObj, message) prefix = ("An error occurred in mavgen:" if len(matches) == 1 else "Errors occurred in mavgen:\n") - message = re.sub(reObj, '\n', message); + message = re.sub(reObj, '\n', message) return prefix + message diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000000..7c250287646 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,12 @@ +lint.exclude = [ "pymavlink" ] +lint.extend-ignore = [ + "E711", # none-comparison + "E712", # true-false-comparison + "E713", # not-in-test + "E714", # not-is-test + "F401", # unused-import + "F403", # undefined-local-with-import-star + "F405", # undefined-local-with-import-star-usage + "F541", # f-string-missing-placeholders + "F841", # unused-variable +]