On 12/6/22 15:47, Gaius Mulley wrote:
> |Hi Martin, here is the revised patch having applied all previous
> recommendations:
> https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603436.html. Is this
> ok now? Thanks for the improvement suggestions.|
Hello.
It looks much better and I'm sending a small patch that resolves the remaining
flake8 issue. I use the following plugins (some listed here:
https://gcc.gnu.org/codingconventions.html#python):
$ flake8 --version
5.0.4 (flake8-bugbear: 22.10.27, flake8-builtins: 1.5.3, flake8-comprehensions:
3.4.0, flake8-import-order: 0.18.1, flake8-quotes: 3.3.1, mccabe: 0.7.0,
pycodestyle: 2.9.1, pyflakes: 2.5.0) CPython 3.10.8 on Linux
and I see:
gcc/m2/tools-src> flake8
./boilerplate.py:108:66: E999 SyntaxError: invalid syntax
./tidydates.py:26:1: I100 Import statements are in the wrong order. 'import
pathlib' should be before 'import sys'
./tidydates.py:129:50: E128 continuation line under-indented for visual indent
./def2doc.py:49:5: E301 expected 1 blank line, found 0
./def2doc.py:49:18: E211 whitespace before '('
./def2doc.py:51:5: E301 expected 1 blank line, found 0
./def2doc.py:51:18: E211 whitespace before '('
./def2doc.py:53:5: E301 expected 1 blank line, found 0
./def2doc.py:55:5: E301 expected 1 blank line, found 0
./def2doc.py:57:5: E301 expected 1 blank line, found 0
./def2doc.py:59:5: E301 expected 1 blank line, found 0
./def2doc.py:61:5: E301 expected 1 blank line, found 0
./def2doc.py:65:5: E301 expected 1 blank line, found 0
./def2doc.py:70:5: E301 expected 1 blank line, found 0
./def2doc.py:72:5: E301 expected 1 blank line, found 0
./def2doc.py:191:80: E501 line too long (81 > 79 characters)
./def2doc.py:330:22: A002 argument "dir" is shadowing a python builtin
./def2doc.py:348:23: A002 argument "dir" is shadowing a python builtin
./def2doc.py:377:17: A002 argument "dir" is shadowing a python builtin
./def2doc.py:396:21: A002 argument "dir" is shadowing a python builtin
./def2doc.py:406:16: A002 argument "dir" is shadowing a python builtin
./def2doc.py:418:15: A002 argument "dir" is shadowing a python builtin
./def2doc.py:432:25: A002 argument "dir" is shadowing a python builtin
./def2doc.py:437:19: Q000 Double quotes found but single quotes preferred
./def2doc.py:439:19: Q000 Double quotes found but single quotes preferred
./def2doc.py:441:19: Q000 Double quotes found but single quotes preferred
./def2doc.py:468:18: Q001 Single quote multiline found but double quotes
preferred
It seems the first one is a real syntax error. Anyway, feel free to apply the
suggested patch.
And I would consider replacing the following static 'str.' calls:
def2doc.py: output.write(str.replace(str.replace(str.rstrip(line),
def2doc.py: output.write(str.replace(str.replace(line, '{', '@{'), '}',
'@}'))
with line.rstrip().replace(...).replace(...)
Cheers,
Martin
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..9ac94e9c979 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)
@@ -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)