Skip to contentSkip to conversation

tools/docs/checktransupdate.py: fix missing prefix in f-string

PATCH Applied LIU Haoyang 3 participants 7 messages Mar 8 – Mar 22

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/docs/checktransupdate.py: fix missing prefix in f-string

Add a f prefix to f-string in checktransupdate.py.

Fixes 63e96ce050e5 ("scripts: fix all issues reported by pylint")
---
 tools/docs/checktransupdate.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/docs/checktransupdate.py +1 -1
index e894652369a5..bf735562aeeb 100755
@@ -131,7 +131,7 @@ def check_per_file(file_path):
     opath = get_origin_path(file_path)
 
     if not os.path.isfile(opath):
-        logging.error("Cannot find the origin path for {file_path}")
+        logging.error(f"Cannot find the origin path for {file_path}")
         return
 
     o_from_head = get_latest_commit_from(opath, "HEAD")
Signature · 1 line
2.53.0
#1 lore raw
Quoted 4 lines · LIU Haoyang

Add a f prefix to f-string in checktransupdate.py.

Fixes 63e96ce050e5 ("scripts: fix all issues reported by pylint")

Hi Haoyang,

could you help fix all the issues mentioned by pylint? There is another issue reported by pylint.

tools/docs/checktransupdate.py:79:4: C0103: Variable name "HASH" doesn't conform to snake_case naming style (invalid-name)

Dongliang Mu

Quoted 17 lines
---
  tools/docs/checktransupdate.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/docs/checktransupdate.py +1 -1
index e894652369a5..bf735562aeeb 100755
@@ -131,7 +131,7 @@ def check_per_file(file_path):
      opath = get_origin_path(file_path)
 
      if not os.path.isfile(opath):
-        logging.error("Cannot find the origin path for {file_path}")
+        logging.error(f"Cannot find the origin path for {file_path}")
          return
 
      o_from_head = get_latest_commit_from(opath, "HEAD")
#2 lore raw

PATCH v2 1/1 tools/docs/checktransupdate.py: fix all issues reported by pylint

In reply to LIU Haoyang

This patch fixes all issues reported by pylint, including:
1. Format issue in logging.
2. Variable name style issue.

Fixes 63e96ce050e5 ("scripts: fix all issues reported by pylint")

---
V1 -> V2: fix variable name style name and keep the format consistent with other logging format

 tools/docs/checktransupdate.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/docs/checktransupdate.py +4 -4
index e894652369a5..cc07cda667fc 100755
@@ -76,11 +76,11 @@ def get_origin_from_trans_smartly(origin_path, t_from_head):
     (2) Update the translation through commit HASH (TITLE)
     """
     # catch flag for 12-bit commit hash
-    HASH = r'([0-9a-f]{12})'
+    hash_re = r'([0-9a-f]{12})'
     # pattern 1: contains "update to commit HASH"
-    pat_update_to = re.compile(rf'update to commit {HASH}')
+    pat_update_to = re.compile(rf'update to commit {hash_re}')
     # pattern 2: contains "Update the translation through commit HASH"
-    pat_update_translation = re.compile(rf'Update the translation through commit {HASH}')
+    pat_update_translation = re.compile(rf'Update the translation through commit {hash_re}')
 
     origin_commit_hash = None
     for line in t_from_head["message"]:
@@ -131,7 +131,7 @@ def check_per_file(file_path):
     opath = get_origin_path(file_path)
 
     if not os.path.isfile(opath):
-        logging.error("Cannot find the origin path for {file_path}")
+        logging.error("Cannot find the origin path for %s", file_path)
         return
 
     o_from_head = get_latest_commit_from(opath, "HEAD")
Signature · 1 line
2.53.0
maintainer
#3 lore raw

Re: [PATCH v2] tools/docs/checktransupdate.py: fix all issues reported by pylint

Quoted 3 lines · Haoyang LIU

This patch fixes all issues reported by pylint, including:
1. Format issue in logging.
2. Variable name style issue.

I'm somewhat unconvinced about that second change. We haven't come up with a coding style for Python code in the kernel, but I think we do want it to look at least a bit like kernel code and not just defer all decisions to tools like pylint. I'm not really opposed to this change either, mind you, but the process of getting there worries me a bit.

Quoted 28 lines
Fixes 63e96ce050e5 ("scripts: fix all issues reported by pylint")

---
V1 -> V2: fix variable name style name and keep the format consistent with other logging format

 tools/docs/checktransupdate.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/docs/checktransupdate.py +3 -3
index e894652369a5..cc07cda667fc 100755
@@ -76,11 +76,11 @@ def get_origin_from_trans_smartly(origin_path, t_from_head):
     (2) Update the translation through commit HASH (TITLE)
     """
     # catch flag for 12-bit commit hash
-    HASH = r'([0-9a-f]{12})'
+    hash_re = r'([0-9a-f]{12})'
     # pattern 1: contains "update to commit HASH"
-    pat_update_to = re.compile(rf'update to commit {HASH}')
+    pat_update_to = re.compile(rf'update to commit {hash_re}')
     # pattern 2: contains "Update the translation through commit HASH"
-    pat_update_translation = re.compile(rf'Update the translation through commit {HASH}')
+    pat_update_translation = re.compile(rf'Update the translation through commit {hash_re}')
 
     origin_commit_hash = None
     for line in t_from_head["message"]:

tools/docs/checktransupdate.py def check_per_file(file_path): · line 134

Quoted 5 lines
tools/docs/checktransupdate.py +1 -1
@@ -131,7 +131,7 @@ def check_per_file(file_path):
     opath = get_origin_path(file_path)
 
     if not os.path.isfile(opath):
-        logging.error("Cannot find the origin path for {file_path}")
+        logging.error("Cannot find the origin path for %s", file_path)

Why was this change made? The first time around, you'd simply added the obviously missing "f", which seems better?

Thanks,

jon

#4 lore raw

Re: [PATCH v2] tools/docs/checktransupdate.py: fix all issues reported by pylint

Quoted 10 lines · Jonathan Corbet
Quoted 3 lines · Haoyang LIU

This patch fixes all issues reported by pylint, including:
1. Format issue in logging.
2. Variable name style issue.

I'm somewhat unconvinced about that second change. We haven't come up with a coding style for Python code in the kernel, but I think we do want it to look at least a bit like kernel code and not just defer all decisions to tools like pylint. I'm not really opposed to this change either, mind you, but the process of getting there worries me a bit.

Dear Jon,

My initial thought was that 'HASH' looks like a global-style constant, while it's actually a local variable. However, the lowercase 'hash' has conflict with python built-in hash function, so I renamed it to hash_re to indicate that it's a regular expression.

Quoted 31 lines
Quoted 31 lines
Fixes 63e96ce050e5 ("scripts: fix all issues reported by pylint")

---
V1 -> V2: fix variable name style name and keep the format consistent with other logging format

  tools/docs/checktransupdate.py | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
tools/docs/checktransupdate.py +3 -3
index e894652369a5..cc07cda667fc 100755
@@ -76,11 +76,11 @@ def get_origin_from_trans_smartly(origin_path, t_from_head):
      (2) Update the translation through commit HASH (TITLE)
      """
      # catch flag for 12-bit commit hash
-    HASH = r'([0-9a-f]{12})'
+    hash_re = r'([0-9a-f]{12})'
      # pattern 1: contains "update to commit HASH"
-    pat_update_to = re.compile(rf'update to commit {HASH}')
+    pat_update_to = re.compile(rf'update to commit {hash_re}')
      # pattern 2: contains "Update the translation through commit HASH"
-    pat_update_translation = re.compile(rf'Update the translation through commit {HASH}')
+    pat_update_translation = re.compile(rf'Update the translation through commit {hash_re}')
 
      origin_commit_hash = None
      for line in t_from_head["message"]:
@@ -131,7 +131,7 @@ def check_per_file(file_path):
      opath = get_origin_path(file_path)
 
Quoted 5 lines

tools/docs/checktransupdate.py def check_per_file(file_path): · line 134

Quoted 3 lines
tools/docs/checktransupdate.py +1 -1
      if not os.path.isfile(opath):
-        logging.error("Cannot find the origin path for {file_path}")
+        logging.error("Cannot find the origin path for %s", file_path)

Why was this change made? The first time around, you'd simply added the obviously missing "f", which seems better?

I used the "%s" style mainly to keep the logging format consistent with the other logging statements in this file, which follow the same pattern. To me, using f-string or lazy format.

Sincerely,
Haoyang

Quoted 4 lines

Thanks,

jon

author
#5 lore raw

Re: [PATCH v2] tools/docs/checktransupdate.py: fix all issues reported by pylint

Sent from my iPhone

Quoted 53 lines · Haoyang Liu



Quoted 11 lines · Jonathan Corbet
Quoted 3 lines · Haoyang LIU

This patch fixes all issues reported by pylint, including:
1. Format issue in logging.
2. Variable name style issue.

I'm somewhat unconvinced about that second change. We haven't come up with a coding style for Python code in the kernel, but I think we do want it to look at least a bit like kernel code and not just defer all decisions to tools like pylint. I'm not really opposed to this change either, mind you, but the process of getting there worries me a bit.

Dear Jon,

My initial thought was that 'HASH' looks like a global-style constant, while it's actually a local variable. However, the lowercase 'hash' has conflict with python built-in hash function, so I renamed it to hash_re to indicate that it's a regular expression.

Quoted 26 lines
Quoted 26 lines
Fixes 63e96ce050e5 ("scripts: fix all issues reported by pylint")

---
V1 -> V2: fix variable name style name and keep the format consistent with other logging format

 tools/docs/checktransupdate.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/docs/checktransupdate.py +3 -3
index e894652369a5..cc07cda667fc 100755
@@ -76,11 +76,11 @@ def get_origin_from_trans_smartly(origin_path, t_from_head):
     (2) Update the translation through commit HASH (TITLE)
     """
     # catch flag for 12-bit commit hash
-    HASH = r'([0-9a-f]{12})'
+    hash_re = r'([0-9a-f]{12})'
     # pattern 1: contains "update to commit HASH"
-    pat_update_to = re.compile(rf'update to commit {HASH}')
+    pat_update_to = re.compile(rf'update to commit {hash_re}')
     # pattern 2: contains "Update the translation through commit HASH"
-    pat_update_translation = re.compile(rf'Update the translation through commit {HASH}')
+    pat_update_translation = re.compile(rf'Update the translation through commit {hash_re}')
       origin_commit_hash = None
Quoted 8 lines

tools/docs/checktransupdate.py def check_per_file(file_path): · line 133

Quoted 6 lines
tools/docs/checktransupdate.py +1 -1
     for line in t_from_head["message"]:
@@ -131,7 +131,7 @@ def check_per_file(file_path):
     opath = get_origin_path(file_path)
       if not os.path.isfile(opath):
-        logging.error("Cannot find the origin path for {file_path}")
+        logging.error("Cannot find the origin path for %s", file_path)

Why was this change made? The first time around, you'd simply added the obviously missing "f", which seems better?

Quoted 1 line

I used the "%s" style mainly to keep the logging format consistent with the other logging statements in this file, which follow the same pattern. To me, using f-string or lazy format.

To me, using f-string or lazy format are the same. ( sorry for the unfinished message)

Haoyang

Quoted 8 lines

Sincerely,
Haoyang

Quoted 4 lines

Thanks,

jon

maintainer Applied
#6 lore raw
In reply to LIU Haoyang
Quoted 13 lines · LIU Haoyang

Add a f prefix to f-string in checktransupdate.py.

Fixes 63e96ce050e5 ("scripts: fix all issues reported by pylint")
---
 tools/docs/checktransupdate.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/docs/checktransupdate.py +0 -0
index e894652369a5..bf735562aeeb 100755

tools/docs/checktransupdate.py def check_per_file(file_path): · line 135

Quoted 6 lines
tools/docs/checktransupdate.py +1 -1
@@ -131,7 +131,7 @@ def check_per_file(file_path):
     opath = get_origin_path(file_path)
 
     if not os.path.isfile(opath):
-        logging.error("Cannot find the origin path for {file_path}")
+        logging.error(f"Cannot find the origin path for {file_path}")
         return

Applied, thanks.

jon