All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] doc: cleanup conf.py script
Date: Thu, 12 Dec 2024 11:33:07 +0100	[thread overview]
Message-ID: <20241212-doc_syscalls_link-v1-1-69a916958ba9@suse.com> (raw)
In-Reply-To: <20241212-doc_syscalls_link-v1-0-69a916958ba9@suse.com>

From: Andrea Cervesato <andrea.cervesato@suse.com>

Cleanup code in the documentation building script which is using
bad patters and overcomplicating certain parts of the code.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 doc/conf.py | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/doc/conf.py b/doc/conf.py
index 789a0db6e726dba450d4089477ffe3d9a5b0a69f..1c6a7f74c9401842c01f33dd34a5171d5328248c 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -5,9 +5,9 @@
 
 import os
 import re
-import sphinx
 import socket
 import urllib.request
+import sphinx
 
 # -- Project information -----------------------------------------------------
 # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
@@ -116,19 +116,19 @@ def generate_syscalls_stats(_):
     ]
 
     # fetch syscalls file
+    syscalls_url = "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/arch/mips/kernel/syscalls"
     error = False
     try:
         socket.setdefaulttimeout(3)
         urllib.request.urlretrieve(
-            "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/arch/mips/kernel/syscalls/syscall_n64.tbl",
-            "syscalls.tbl")
-    except Exception as err:
+            f"{syscalls_url}/syscall_n64.tbl", "syscalls.tbl")
+    except urllib.error.URLError as err:
         error = True
         logger = sphinx.util.logging.getLogger(__name__)
-        msg = "Can't download syscall_n64.tbl from kernel sources"
+        msg = f"Can't download syscall_n64.tbl from kernel sources ({err})"
         logger.warning(msg)
 
-        with open(output, 'w+') as stats:
+        with open(output, 'w+', encoding='utf-8') as stats:
             stats.write(f".. warning::\n\n    {msg}")
 
     if error:
@@ -142,7 +142,7 @@ def generate_syscalls_stats(_):
     # collect all available kernel syscalls
     regexp = re.compile(r'\d+\s+n64\s+(?P<syscall>\w+)\s+\w+')
     ker_syscalls = []
-    with open("syscalls.tbl", 'r') as data:
+    with open("syscalls.tbl", 'r', encoding='utf-8') as data:
         for line in data:
             match = regexp.search(line)
             if match:
@@ -150,7 +150,7 @@ def generate_syscalls_stats(_):
 
     # collect all LTP tested syscalls
     ltp_syscalls = []
-    for root, _, files in os.walk('../testcases/kernel/syscalls'):
+    for _, _, files in os.walk('../testcases/kernel/syscalls'):
         for myfile in files:
             if myfile.endswith('.c'):
                 ltp_syscalls.append(myfile)
@@ -196,41 +196,47 @@ def generate_syscalls_stats(_):
         '    :header-rows: 0\n\n',
     ]
 
+    max_columns = 3
+
     for sysname, tested in syscalls.items():
         if tested:
-            if (index_tested % 3) == 0:
+            if (index_tested % max_columns) == 0:
                 table_tested.append(f'    * - {sysname}\n')
             else:
                 table_tested.append(f'      - {sysname}\n')
 
             index_tested += 1
         else:
-            if (index_untest % 3) == 0:
+            if (index_untest % max_columns) == 0:
                 table_untest.append(f'    * - {sysname}\n')
             else:
                 table_untest.append(f'      - {sysname}\n')
 
             index_untest += 1
 
-    left = index_tested % 3
+    left = index_tested % max_columns
     if left > 0:
-        for index in range(0, 3 - left):
-            table_tested.append(f'      -\n')
+        for _ in range(0, max_columns - left):
+            table_tested.append('      -\n')
 
-    left = index_untest % 3
+    left = index_untest % max_columns
     if left > 0:
-        for index in range(0, 3 - left):
-            table_untest.append(f'      -\n')
+        for _ in range(0, max_columns - left):
+            table_untest.append('      -\n')
 
     text.extend(table_tested)
     text.append('\n')
     text.extend(table_untest)
 
     # write the file
-    with open(output, 'w+') as stats:
+    with open(output, 'w+', encoding='utf-8') as stats:
         stats.writelines(text)
 
 
 def setup(app):
+    """
+    Setup the current documentation, using self generated data and graphics
+    customizations.
+    """
     app.add_css_file('custom.css')
     app.connect('builder-inited', generate_syscalls_stats)

-- 
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-12-12 10:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-12 10:33 [LTP] [PATCH 0/2] doc: support for links in syscalls Andrea Cervesato
2024-12-12 10:33 ` Andrea Cervesato [this message]
2024-12-12 12:59   ` [LTP] [PATCH 1/2] doc: cleanup conf.py script Petr Vorel
2024-12-12 10:33 ` [LTP] [PATCH 2/2] doc: support for clickable syscalls under stats Andrea Cervesato
2024-12-12 13:34   ` Petr Vorel
2024-12-12 14:02     ` Andrea Cervesato via ltp
2024-12-12 14:13 ` [LTP] [PATCH 0/2] doc: support for links in syscalls Andrea Cervesato via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241212-doc_syscalls_link-v1-1-69a916958ba9@suse.com \
    --to=andrea.cervesato@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.