[PATCH] 16/19 modula2 front end: bootstrap and documentation tools
This patch set contains the bootstrap linking tool as well as python3 scripts to automatically generate texi libraries section of the gm2 documentation. In the fullness of time this will be changed to emit sphinx. --8<--8<--8<--8<--8<--8< diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py --- /dev/null 2022-08-24 16:22:16.88870 +0100 +++ gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py 2022-10-07 20:21:18.682097332 +0100 @@ -0,0 +1,184 @@ +#!/usr/bin/env python3 + +# utility to tidy dates and detect lack of copyright. + +# Copyright (C) 2016-2022 Free Software Foundation, Inc. +# +# This file is part of GNU Modula-2. +# +# GNU Modula-2 is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Modula-2 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU 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 COPYING. If not, write to the +# Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +import os, sys + +maxLineLength = 60 + + +# +# visitDir - call func for each file below, dir, matching extension, ext. +# + +def visitDir (dir, ext, func): +listOfFiles = os.listdir(dir) +listOfFiles.sort() +for file in listOfFiles: +if os.path.isfile(os.path.join(dir, file)): +l = len(ext) +if (len(file)>l) and (file[-l:] == ext): +func(os.path.join(dir, file)) +elif os.path.isdir(os.path.join(dir, file)): +visitDir(os.path.join(dir, file), ext, func) + +# +# isYear - returns True if, year, is legal. +# + +def isYear (year): +if len(year)==5: +year = year[:-1] +for c in year: +if not c.isdigit(): +return False +return True + + +# +# handleCopyright - +# + +def handleCopyright (outfile, lines, n, leader1, leader2): +global maxLineLength +i = lines[n] +c = i.find('Copyright (C) ')+len('Copyright (C)') +outfile.write(i[:c]) +d = i[c:].split() +start = c +seenDate = True +years = [] +while seenDate: +if d == []: +n += 1 +i = lines[n] +d = i[2:].split() +else: +e = d[0] +punctuation = "" +if len(d)==1: +d = [] +else: +d = d[1:] + +if c>maxLineLength: +outfile.write('\n') +outfile.write(leader1) +outfile.write(leader2) +outfile.write(' '*(start-2)) +c = start + +if isYear(e): +if (e[-1]=='.') or (e[-1]==','): +punctuation = e[-1] +e = e[:-1] +else: +punctuation = "" +else: +seenDate = False +if seenDate: +if not (e in years): +c += len(e) + len(punctuation) +outfile.write(' ') +outfile.write(e) +outfile.write(punctuation) +years += [e] +else: +if start < c: +outfile.write('\n') +outfile.write(leader1) +outfile.write(leader2) +outfile.write(' '*(start-2)) + +outfile.write(' ') +outfile.write(e) +outfile.write(punctuation) +for w in d: +outfile.write(' ') +outfile.write(w) + +outfile.write('\n') +return outfile, n+1 + +# +# handleHeader - reads in the header of a file and inserts +# a line break around the Copyright dates. +# + +def handleHeader (file, leader1, leader2): +print("--") +l = open(file, 'r').readlines() +if len(l)>20: +outfile = open('tmptidy', 'w') +n = 0 +for i in l: +if i.find('Copyright (C)')>=0: +outfile, n = handleCopyright(outfile, l, n, leader1, leader2) +outfile.writelines(l[n:]) +outfile.close() +print("-> mv tmptidy", file) +command = "mv tmptidy %s" % file +os.system(command) +return +else: +outfile.write(l[n]) +n += 1 +outfile.close() +sys.stdout.write("%s:1:1 needs a Copyright notice..\n" % file) + + +# +# bashTidy - tidy up dates using '#' comment +# + +def bashTidy
Re: [PATCH] 16/19 modula2 front end: bootstrap and documentation tools
On 10/10/22 17:31, Gaius Mulley via Gcc-patches wrote: > > Hi! > This patch set contains the bootstrap linking tool as well as python3 > scripts to automatically generate texi libraries section of the gm2 > documentation. In the fullness of time this will be changed to emit > sphinx. Yep, looking forward to it. I'm going to write an email with Sphinx transition schedule once Sphinx 5.3 gets released (should happen during the upcoming weekend). I have general comments about the Python scripts: 1) please follow the Python coding style and not the GCC one (I'm going to document it in https://gcc.gnu.org/codingconventions.html under a new Python section). The easiest approach is using flake8 and the following plugins: python3-flake8, python3-flake8-builtins, python3-flake8-bugbear, python3-flake8-import-order, python3-flake8-quotes plus, you might want to come up with a setup.cfg like we have in: ./maintainer-scripts/setup.cfg > > > --8<--8<--8<--8<--8<--8< > diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py > --- /dev/null 2022-08-24 16:22:16.88870 +0100 > +++ gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py 2022-10-07 > 20:21:18.682097332 +0100 > @@ -0,0 +1,184 @@ > +#!/usr/bin/env python3 > + > +# utility to tidy dates and detect lack of copyright. > + > +# Copyright (C) 2016-2022 Free Software Foundation, Inc. > +# > +# This file is part of GNU Modula-2. > +# > +# GNU Modula-2 is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3, or (at your option) > +# any later version. > +# > +# GNU Modula-2 is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU 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 COPYING. If not, write to the > +# Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA > +# 02110-1301, USA. > + > +import os, sys > + > +maxLineLength = 60 > + > + > +# > +# visitDir - call func for each file below, dir, matching extension, ext. > +# > + > +def visitDir (dir, ext, func): > +listOfFiles = os.listdir(dir) > +listOfFiles.sort() > +for file in listOfFiles: > +if os.path.isfile(os.path.join(dir, file)): > +l = len(ext) > +if (len(file)>l) and (file[-l:] == ext): > +func(os.path.join(dir, file)) please use pathlib.Path(...).stem > +elif os.path.isdir(os.path.join(dir, file)): > +visitDir(os.path.join(dir, file), ext, func) > + > +# > +# isYear - returns True if, year, is legal. > +# > + > +def isYear (year): > +if len(year)==5: > +year = year[:-1] > +for c in year: > +if not c.isdigit(): > +return False > +return True > + > + > +# > +# handleCopyright - > +# > + > +def handleCopyright (outfile, lines, n, leader1, leader2): > +global maxLineLength > +i = lines[n] > +c = i.find('Copyright (C) ')+len('Copyright (C)') > +outfile.write(i[:c]) > +d = i[c:].split() > +start = c > +seenDate = True > +years = [] > +while seenDate: > +if d == []: > +n += 1 > +i = lines[n] > +d = i[2:].split() > +else: > +e = d[0] > +punctuation = "" Please unify "" and '', you only apostrophes. > +if len(d)==1: > +d = [] > +else: > +d = d[1:] > + > +if c>maxLineLength: > +outfile.write('\n') > +outfile.write(leader1) > +outfile.write(leader2) > +outfile.write(' '*(start-2)) > +c = start > + > +if isYear(e): > +if (e[-1]=='.') or (e[-1]==','): > +punctuation = e[-1] > +e = e[:-1] > +else: > +punctuation = "" > +else: > +seenDate = False > +if seenDate: > +if not (e in years): > +c += len(e) + len(punctuation) > +outfile.write(' ') > +outfile.write(e) > +outfile.write(punctuation) > +years += [e] > +else: > +if start < c: > +outfile.write('\n') > +outfile.write(leader1) > +outfile.write(leader2) > +outfile.write(' '*(start-2)) > + > +outfile.write(' ') > +outfile.write(e) > +outfile.write(punctuation) > +for w in d: > +
Re: [PATCH] 16/19 modula2 front end: bootstrap and documentation tools
Martin Liška writes: >> This patch set contains the bootstrap linking tool as well as python3 >> scripts to automatically generate texi libraries section of the gm2 >> documentation. In the fullness of time this will be changed to emit >> sphinx. > > Yep, looking forward to it. I'm going to write an email with Sphinx transition > schedule once Sphinx 5.3 gets released (should happen during the upcoming > weekend). > > I have general comments about the Python scripts: > > 1) please follow the Python coding style and not the GCC one (I'm going to > document > it in https://gcc.gnu.org/codingconventions.html under a new Python section). > The easiest approach is using flake8 and the following plugins: > > python3-flake8, python3-flake8-builtins, python3-flake8-bugbear, > python3-flake8-import-order, python3-flake8-quotes Hi Martin, many thanks for the pointers to the style tool and python lint - I'll reformat the code accordingly. > plus, you might want to come up with a setup.cfg like we have in: > ./maintainer-scripts/setup.cfg yes sounds sensible. Thanks for the detailed observations/suggestions/improvements below - I agree with them all and will fix/change the code and then repost the patch regards, Gaius >> --8<--8<--8<--8<--8<--8< >> diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py >> --- /dev/null2022-08-24 16:22:16.88870 +0100 >> +++ gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py 2022-10-07 >> 20:21:18.682097332 +0100 >> @@ -0,0 +1,184 @@ >> +#!/usr/bin/env python3 >> + >> +# utility to tidy dates and detect lack of copyright. >> + >> +# Copyright (C) 2016-2022 Free Software Foundation, Inc. >> +# >> +# This file is part of GNU Modula-2. >> +# >> +# GNU Modula-2 is free software; you can redistribute it and/or modify >> +# it under the terms of the GNU General Public License as published by >> +# the Free Software Foundation; either version 3, or (at your option) >> +# any later version. >> +# >> +# GNU Modula-2 is distributed in the hope that it will be useful, >> +# but WITHOUT ANY WARRANTY; without even the implied warranty of >> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> +# GNU 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 COPYING. If not, write to the >> +# Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA >> +# 02110-1301, USA. >> + >> +import os, sys >> + >> +maxLineLength = 60 >> + >> + >> +# >> +# visitDir - call func for each file below, dir, matching extension, ext. >> +# >> + >> +def visitDir (dir, ext, func): >> +listOfFiles = os.listdir(dir) >> +listOfFiles.sort() >> +for file in listOfFiles: >> +if os.path.isfile(os.path.join(dir, file)): >> +l = len(ext) >> +if (len(file)>l) and (file[-l:] == ext): >> +func(os.path.join(dir, file)) > > please use pathlib.Path(...).stem > >> +elif os.path.isdir(os.path.join(dir, file)): >> +visitDir(os.path.join(dir, file), ext, func) >> + >> +# >> +# isYear - returns True if, year, is legal. >> +# >> + >> +def isYear (year): >> +if len(year)==5: >> +year = year[:-1] >> +for c in year: >> +if not c.isdigit(): >> +return False >> +return True >> + >> + >> +# >> +# handleCopyright - >> +# >> + >> +def handleCopyright (outfile, lines, n, leader1, leader2): >> +global maxLineLength >> +i = lines[n] >> +c = i.find('Copyright (C) ')+len('Copyright (C)') >> +outfile.write(i[:c]) >> +d = i[c:].split() >> +start = c >> +seenDate = True >> +years = [] >> +while seenDate: >> +if d == []: >> +n += 1 >> +i = lines[n] >> +d = i[2:].split() >> +else: >> +e = d[0] >> +punctuation = "" > > Please unify "" and '', you only apostrophes. > >> +if len(d)==1: >> +d = [] >> +else: >> +d = d[1:] >> + >> +if c>maxLineLength: >> +outfile.write('\n') >> +outfile.write(leader1) >> +outfile.write(leader2) >> +outfile.write(' '*(start-2)) >> +c = start >> + >> +if isYear(e): >> +if (e[-1]=='.') or (e[-1]==','): >> +punctuation = e[-1] >> +e = e[:-1] >> +else: >> +punctuation = "" >> +else: >> +seenDate = False >> +if seenDate: >> +if not (e in years): >> +c += len(e) + len(punctuation) >> +outfile.write(' ') >> +outfile.write(e) >> +outfile.write(punctuation) >> +years += [e] >> +
Re: [PATCH] 16/19 modula2 front end: bootstrap and documentation tools
Hello. I noticed the devel/modula-2 branch contains the following dead links: - http://www.gccsummit.org/2006 - http://www.gccsummit.org/2010/speakers.php?types=LIGHTNING - http://floppsie.comp.glam.ac.uk/Papers/paper23/gaius-mulley-gnu-m2.pdf - http://floppsie.comp.glam.ac.uk/Papers/paper15/mulley-proc.pdf - http://floppsie.comp.glam.ac.uk/Papers/paper22/gaius-gcc-cauldron-2016.pdf Thanks, Martin
Re: [PATCH] 16/19 modula2 front end: bootstrap and documentation tools
Martin Liška writes: > Hello. > > I noticed the devel/modula-2 branch contains the following dead links: > > - http://www.gccsummit.org/2006 > - http://www.gccsummit.org/2010/speakers.php?types=LIGHTNING > - http://floppsie.comp.glam.ac.uk/Papers/paper23/gaius-mulley-gnu-m2.pdf > - http://floppsie.comp.glam.ac.uk/Papers/paper15/mulley-proc.pdf > - http://floppsie.comp.glam.ac.uk/Papers/paper22/gaius-gcc-cauldron-2016.pdf > > Thanks, > Martin many thanks - I will remove these, regards, Gaius