public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Gaius Mulley <gaius@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/modula-2] Documentation tools python3 flake8 style improvements.
Date: Wed,  7 Dec 2022 12:12:22 +0000 (GMT)	[thread overview]
Message-ID: <20221207121222.111123877205@sourceware.org> (raw)

https://gcc.gnu.org/g:442bcd0e9f6650c611fec17c5558637e13c0ac21

commit 442bcd0e9f6650c611fec17c5558637e13c0ac21
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Wed Dec 7 12:11:39 2022 +0000

    Documentation tools python3 flake8 style improvements.
    
    gcc/m2/ChangeLog:
    
            * tools-src/boilerplate.py: Flake8 conformity changes.
            * tools-src/def2doc.py (emit_texinfo_content): Replace
            module method invocation with object method invocation.
            (emit_sphinx_content): Replace
            module method invocation with object method invocation.
            Flake8 conformity changes.
            * tools-src/tidydates.py: Flake8 conformity changes.
    
    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

Diff:
---
 gcc/m2/tools-src/boilerplate.py |  24 ++++-----
 gcc/m2/tools-src/def2doc.py     | 106 ++++++++++++++++++++++------------------
 gcc/m2/tools-src/tidydates.py   |   4 +-
 3 files changed, 72 insertions(+), 62 deletions(-)

diff --git a/gcc/m2/tools-src/boilerplate.py b/gcc/m2/tools-src/boilerplate.py
index f0b266f403f..99596529b4e 100644
--- a/gcc/m2/tools-src/boilerplate.py
+++ b/gcc/m2/tools-src/boilerplate.py
@@ -85,9 +85,9 @@ def analyse_comment(text, f):
             lic = 'GPL'
         elif text.find(GNU_LESSER_GENERAL) > 0:
             lic = 'LGPL'
-        for license in Licenses.keys():
-            if text.find(license) > 0:
-                lic += Licenses[license]
+        for license_ in Licenses.keys():
+            if text.find(license_) > 0:
+                lic += Licenses[license_]
         if text.find(GCC_RUNTIME_LIB_EXC) > 0:
             lic += 'x'
         now = datetime.datetime.now()
@@ -105,7 +105,7 @@ def analyse_comment(text, f):
         i = text.find(basename(f))
         j = text.find('. ', i)
         if j < 0:
-            error('summary of the file does not finish with a '.'')
+            error("summary of the file does not finish with a '.'")
             summary = text[i:]
         else:
             summary = text[i:j]
@@ -175,7 +175,7 @@ def add_stop(sentence):
     return sentence
 
 
-GPLv3 = '''
+GPLv3 = """
 %s
 
 Copyright (C) %s Free Software Foundation, Inc.
@@ -196,9 +196,9 @@ General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with GNU Modula-2; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.
-'''
+"""
 
-GPLv3x = '''
+GPLv3x = """
 %s
 
 Copyright (C) %s Free Software Foundation, Inc.
@@ -224,9 +224,9 @@ You should have received a copy of the GNU General Public License and
 a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.
-'''
+"""
 
-LGPLv3 = '''
+LGPLv3 = """
 %s
 
 Copyright (C) %s Free Software Foundation, Inc.
@@ -246,9 +246,9 @@ Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public License
 along with GNU Modula-2.  If not, see <https://www.gnu.org/licenses/>.
-'''
+"""
 
-BSISO = '''
+BSISO = """
 Library module defined by the International Standard
    Information technology - programming languages
    BS ISO/IEC 10514-1:1996E Part 1: Modula-2, Base Language.
@@ -259,7 +259,7 @@ Library module defined by the International Standard
    It may be freely copied for the purpose of implementation (see page
    707 of the Information technology - Programming languages Part 1:
    Modula-2, Base Language.  BS ISO/IEC 10514-1:1996).
-'''
+"""
 
 templates = {}
 templates['GPLv3'] = GPLv3
diff --git a/gcc/m2/tools-src/def2doc.py b/gcc/m2/tools-src/def2doc.py
index eb29118cc9d..4071410dd88 100755
--- a/gcc/m2/tools-src/def2doc.py
+++ b/gcc/m2/tools-src/def2doc.py
@@ -46,29 +46,39 @@ class state:
     def __init__(self):
         self._state_state = state_none
         self._block = block_none
-    def get_state (self):
+
+    def get_state(self):
         return self._state_state
-    def set_state (self, value):
+
+    def set_state(self, value):
         self._state_state = value
+
     def is_const(self):
         return self._state_state == state_const
+
     def is_type(self):
         return self._state_state == state_type
+
     def is_var(self):
         return self._state_state == state_var
+
     def get_block(self):
         return self._block
+
     def _change_block(self, new_block):
         if self._block != new_block:
             self._block = new_block
             self._emit_block_desc()
+
     def _emit_block_desc(self):
         if self._block == block_code:
             output.write('.. code-block:: modula2\n')
         elif self._block == block_index:
             output.write('.. index::\n')
+
     def to_code(self):
         self._change_block(block_code)
+
     def to_index(self):
         self._change_block(block_index)
 
@@ -169,8 +179,8 @@ def remove_fields(file, line):
     # fields from a comment within the start of a definition module.
     while (line.find('*)') == -1):
         if not removeable_field(line):
-            output.write(str.replace(str.replace(str.rstrip(line),
-                                                 '{', '@{'), '}', '@}') + '\n')
+            line = line.rstrip().replace('{', '@{').replace('}', '@}')
+            output.write(line + '\n')
         line = file.readline()
     output.write(line.rstrip() + '\n')
 
@@ -274,8 +284,8 @@ def emit_texinfo_content(f, line):
         line = line.rstrip()
         check_index(line)
         state_obj.to_code()
-        output.write(str.replace(str.replace(line, '{', '@{'), '}', '@}'))
-        output.write('\n')
+        line = line.replace('{', '@{').replace('}', '@}')
+        output.write(line + '\n')
         line = f.readline()
     return f
 
@@ -327,11 +337,11 @@ def emit_page(need_page):
         output.write('@page\n')
 
 
-def parse_definition(dir, source, build, file, need_page):
+def parse_definition(dir_, source, build, file, need_page):
     # parse_definition reads a definition module and creates
     # indices for procedures, constants, variables and types.
     output.write('\n')
-    with open(find_file(dir, build, source, file), 'r') as f:
+    with open(find_file(dir_, build, source, file), 'r') as f:
         init_state()
         line = f.readline()
         while (line.find('(*') != -1):
@@ -345,22 +355,22 @@ def parse_definition(dir, source, build, file, need_page):
         emit_page(need_page)
 
 
-def parse_modules(up, dir, build, source, list_of_modules):
+def parse_modules(up, dir_, build, source, list_of_modules):
     previous = ''
     i = 0
     if len(list_of_modules) > 1:
-        nxt = dir + '/' + list_of_modules[1][:-4]
+        nxt = dir_ + '/' + list_of_modules[1][:-4]
     else:
         nxt = ''
     while i < len(list_of_modules):
-        emit_node(dir + '/' + list_of_modules[i][:-4], nxt, previous, up)
-        emit_sub_section(dir + '/' + list_of_modules[i][:-4])
-        parse_definition(dir, source, build, list_of_modules[i], True)
+        emit_node(dir_ + '/' + list_of_modules[i][:-4], nxt, previous, up)
+        emit_sub_section(dir_ + '/' + list_of_modules[i][:-4])
+        parse_definition(dir_, source, build, list_of_modules[i], True)
         output.write('\n')
-        previous = dir + '/' + list_of_modules[i][:-4]
+        previous = dir_ + '/' + list_of_modules[i][:-4]
         i = i + 1
         if i+1 < len(list_of_modules):
-            nxt = dir + '/' + list_of_modules[i+1][:-4]
+            nxt = dir_ + '/' + list_of_modules[i+1][:-4]
         else:
             nxt = ''
 
@@ -374,54 +384,54 @@ def do_cat(name):
             line = file.readline()
 
 
-def module_menu(dir, build, source):
+def module_menu(dir_, build, source):
     # module_menu generates a simple menu for all definition modules
     # in dir
     output.write('@menu\n')
     list_of_files = []
-    if os.path.exists(os.path.join(source, dir)):
-        list_of_files += os.listdir(os.path.join(source, dir))
-    if os.path.exists(os.path.join(source, dir)):
-        list_of_files += os.listdir(os.path.join(build, dir))
+    if os.path.exists(os.path.join(source, dir_)):
+        list_of_files += os.listdir(os.path.join(source, dir_))
+    if os.path.exists(os.path.join(source, dir_)):
+        list_of_files += os.listdir(os.path.join(build, dir_))
     list_of_files = list(dict.fromkeys(list_of_files).keys())
     list_of_files.sort()
     for file in list_of_files:
-        if found_file(dir, build, source, file):
+        if found_file(dir_, build, source, file):
             if (len(file) > 4) and (file[-4:] == '.def'):
-                output.write('* ' + dir + '/' + file[:-4] + '::' + file + '\n')
+                output.write('* ' + dir_ + '/' + file[:-4] + '::' + file + '\n')
     output.write('@end menu\n')
     output.write('\n')
 
 
-def check_directory(dir, build, source):
+def check_directory(dir_, build, source):
     # check_directory - returns True if dir exists in either build or source.
-    if os.path.isdir(build) and os.path.exists(os.path.join(build, dir)):
+    if os.path.isdir(build) and os.path.exists(os.path.join(build, dir_)):
         return True
-    elif os.path.isdir(source) and os.path.exists(os.path.join(source, dir)):
+    elif os.path.isdir(source) and os.path.exists(os.path.join(source, dir_)):
         return True
     else:
         return False
 
 
-def found_file(dir, build, source, file):
+def found_file(dir_, build, source, file):
     # found_file return True if file is found in build/dir/file or
     # source/dir/file.
-    name = os.path.join(os.path.join(build, dir), file)
+    name = os.path.join(os.path.join(build, dir_), file)
     if os.path.exists(name):
         return True
-    name = os.path.join(os.path.join(source, dir), file)
+    name = os.path.join(os.path.join(source, dir_), file)
     if os.path.exists(name):
         return True
     return False
 
 
-def find_file(dir, build, source, file):
+def find_file(dir_, build, source, file):
     # find_file return the path to file searching in build/dir/file
     # first then source/dir/file.
-    name1 = os.path.join(os.path.join(build, dir), file)
+    name1 = os.path.join(os.path.join(build, dir_), file)
     if os.path.exists(name1):
         return name1
-    name2 = os.path.join(os.path.join(source, dir), file)
+    name2 = os.path.join(os.path.join(source, dir_), file)
     if os.path.exists(name2):
         return name2
     sys.stderr.write('file cannot be found in either ' + name1)
@@ -429,35 +439,35 @@ def find_file(dir, build, source, file):
     os.sys.exit(1)
 
 
-def display_modules(up, dir, build, source):
+def display_modules(up, dir_, build, source):
     # display_modules walks though the files in dir and parses
     # definition modules and includes README.texi
-    if check_directory(dir, build, source):
+    if check_directory(dir_, build, source):
         if args.texinfo:
-            ext = ".texi"
+            ext = '.texi'
         elif args.sphinx:
-            ext = ".rst"
+            ext = '.rst'
         else:
-            ext = ""
-        if found_file(dir, build, source, 'README' + ext):
-            do_cat(find_file(dir, build, source, 'README' + ext))
-        module_menu(dir, build, source)
+            ext = ''
+        if found_file(dir_, build, source, 'README' + ext):
+            do_cat(find_file(dir_, build, source, 'README' + ext))
+        module_menu(dir_, build, source)
         list_of_files = []
-        if os.path.exists(os.path.join(source, dir)):
-            list_of_files += os.listdir(os.path.join(source, dir))
-        if os.path.exists(os.path.join(source, dir)):
-            list_of_files += os.listdir(os.path.join(build, dir))
+        if os.path.exists(os.path.join(source, dir_)):
+            list_of_files += os.listdir(os.path.join(source, dir_))
+        if os.path.exists(os.path.join(source, dir_)):
+            list_of_files += os.listdir(os.path.join(build, dir_))
         list_of_files = list(dict.fromkeys(list_of_files).keys())
         list_of_files.sort()
         list_of_modules = []
         for file in list_of_files:
-            if found_file(dir, build, source, file):
+            if found_file(dir_, build, source, file):
                 if (len(file) > 4) and (file[-4:] == '.def'):
                     list_of_modules += [file]
         list_of_modules.sort()
-        parse_modules(up, dir, build, source, list_of_modules)
+        parse_modules(up, dir_, build, source, list_of_modules)
     else:
-        line = 'directory ' + dir + ' not found in either '
+        line = 'directory ' + dir_ + ' not found in either '
         line += build + ' or ' + source
         sys.stderr.write(line + '\n')
 
@@ -465,11 +475,11 @@ def display_modules(up, dir, build, source):
 def display_copyright():
     output.write('@c Copyright (C) 2000-2022 Free Software Foundation, Inc.\n')
     output.write('@c This file is part of GNU Modula-2.\n')
-    output.write('''
+    output.write("""
 @c Permission is granted to copy, distribute and/or modify this document
 @c under the terms of the GNU Free Documentation License, Version 1.2 or
 @c any later version published by the Free Software Foundation.
-''')
+""")
 
 
 def collect_args():
diff --git a/gcc/m2/tools-src/tidydates.py b/gcc/m2/tools-src/tidydates.py
index a28c0f1669a..c244066cd40 100644
--- a/gcc/m2/tools-src/tidydates.py
+++ b/gcc/m2/tools-src/tidydates.py
@@ -22,9 +22,9 @@
 # 02110-1301, USA.
 
 import os
-import sys
 import pathlib
 import shutil
+import sys
 
 max_line_length = 60
 
@@ -126,7 +126,7 @@ def handle_header(filename, leader1, leader2):
             for i in lines:
                 if i.find('Copyright (C)') >= 0:
                     outfile, n = handle_copyright(outfile, lines,
-                                                 n, leader1, leader2)
+                                                  n, leader1, leader2)
                     outfile.writelines(lines[n:])
                     outfile.close()
                     print('-> mv tmptidy', filename)

                 reply	other threads:[~2022-12-07 12:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221207121222.111123877205@sourceware.org \
    --to=gaius@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).