From 77befb396cd1a4f2109c912e420e75a75028b2d7 Mon Sep 17 00:00:00 2001
From: Andre Maroneze <andre.maroneze@cea.fr>
Date: Tue, 9 May 2023 10:49:50 +0200
Subject: [PATCH] [machdep] apply some pylint remarks

- sort imports
- avoid top-level import after code
- prefer 'sys.exit' instead of 'exit'
- avoid unnecessary '.keys()'
- '\w' in string is an anomalous backslash (W1401), "might be missing r prefix"
---
 share/machdeps/make_machdep/make_machdep.py | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/share/machdeps/make_machdep/make_machdep.py b/share/machdeps/make_machdep/make_machdep.py
index 5382fcfd39e..a7ae7fe1beb 100755
--- a/share/machdeps/make_machdep/make_machdep.py
+++ b/share/machdeps/make_machdep/make_machdep.py
@@ -39,12 +39,13 @@ by hand afterwards.
 """
 
 import argparse
-import yaml
 from pathlib import Path
 import re
 import subprocess
 import sys
 import warnings
+import yaml
+from yaml.representer import Representer
 
 my_path = Path(sys.argv[0]).parent
 
@@ -131,9 +132,9 @@ if args.from_file:
     orig_file.close()
     if args.check_only:
         if check_machdep(orig_machdep):
-            exit(0)
+            sys.exit(0)
         else:
-            exit(1)
+            sys.exit(1)
     if not "compiler" in orig_machdep or not "cpp_arch_flags" in orig_machdep:
         raise Exception("Missing fields in yaml file")
     args.compiler = orig_machdep["compiler"]
@@ -268,7 +269,7 @@ def cleanup_cpp(output):
 
 
 def find_macros_value(output, is_list=False, entry=None):
-    msg = re.compile("(\w+)_is = ([^;]+);")
+    msg = re.compile(r"(\w+)_is = ([^;]+);")
     if is_list:
         assert entry
         machdep[entry] = {}
@@ -278,7 +279,7 @@ def find_macros_value(output, is_list=False, entry=None):
         if is_list:
             machdep[entry][name] = value
         else:
-            if name in machdep.keys():
+            if name in machdep:
                 if args.verbose:
                     print(f"[INFO] setting {name} to {value}")
                 machdep[name] = value
@@ -291,7 +292,7 @@ def find_macros_value(output, is_list=False, entry=None):
 for (f, typ) in source_files:
     p = my_path / f
     cmd = compilation_command + [str(p)]
-    if typ == "macro" or typ == "macrolist":
+    if typ in ("macro", "macrolist"):
         # We're just interested in expanding a macro,
         # treatment is a bit different than the rest.
         cmd = cmd + ["-E"]
@@ -365,8 +366,6 @@ def change_style(style, representer):
     return new_representer
 
 
-from yaml.representer import Representer
-
 custom_defs_representer = change_style("|", Representer.represent_str)
 
 yaml.add_representer(custom_defs, custom_defs_representer)
-- 
GitLab