Hi Bruno,
On 4/13/24 4:08 AM, Bruno Haible wrote:
> It seems that codecs.open is frowned upon, nowadays [1],
> and that the Python 3 way of opening a file is a built-in function 'open' [2].
Thanks for this patch. When I started working on gnulib-tool.py I
didn't even know the codecs module existed, since I had never used
Python 2.
> Let's use this consistently. With newline='\n' in order to match what
> gnulib-tool.sh does.
Sounds good. You mentioned removing the constants.nlconvert() stuff in
an earlier email [1]. How about these two patches?
Patch 0001 removes nlconvert and all of its calls. That should make
sure gnulib-tool.py and gnulib-tool.sh deal with newlines the same
way.
Patch 0002 removes the 'NL' constant. I assume this was to match
gnulib-tool.sh's use of "$nl"? But there it is used to expand to a
newline character without breaking lines right? For example, this:
func_append license_incompatibilities "$module $license$nl"
vs. this:
func_append license_incompatibilities "$module $license
"
Since we use a mix of '\n' and constants.NL, I would just like to use
'\n' everwhere consistently.
> Specifying encoding='utf-8' is what makes the most sense today. If a package
> still has a configure.ac or Makefile.am in ISO-8859-1 encoding, this will
> probably fail. Let's see if people report a problem with this; it should be
> very rare.
Sounds good.
[1] https://lists.gnu.org/archive/html/bug-gnulib/2024-03/msg00370.html
Collin
From fbdd4e7783b8a4b6e637bac2b392024b0e880622 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 14 Apr 2024 10:18:03 -0700
Subject: [PATCH 1/2] gnulib-tool.py: Don't perform newline conversions.
* pygnulib/constants.py (nlconvert): Remove function. Remove unused
platform import.
* pygnulib/GLImport.py (GLImport.gnulib_cache): Remove calls to
nlconvert().
* pygnulib/GLModuleSystem.py
(GLModule.getAutomakeSnippet_Unconditional): Likewise.
* pygnulib/GLTestDir.py (GLTestDir.execute, GLMegaTestDir.execute):
Likewise.
---
ChangeLog | 12 ++++++++++++
pygnulib/GLImport.py | 2 +-
pygnulib/GLModuleSystem.py | 1 -
pygnulib/GLTestDir.py | 6 ------
pygnulib/constants.py | 10 ----------
5 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9b40f3d9d8..b5c16eae4e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-04-14 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Don't perform newline conversions.
+ * pygnulib/constants.py (nlconvert): Remove function. Remove unused
+ platform import.
+ * pygnulib/GLImport.py (GLImport.gnulib_cache): Remove calls to
+ nlconvert().
+ * pygnulib/GLModuleSystem.py
+ (GLModule.getAutomakeSnippet_Unconditional): Likewise.
+ * pygnulib/GLTestDir.py (GLTestDir.execute, GLMegaTestDir.execute):
+ Likewise.
+
2024-04-14 Collin Funk <collin.fu...@gmail.com>
gnulib-tool.py: Remove some unused variables.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index eadf45828d..eaff520fa4 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -598,7 +598,7 @@ def gnulib_cache(self) -> str:
if vc_files != None:
# Convert Python bools to shell (True -> true).
emit += 'gl_VC_FILES([%s])\n' % str(vc_files).lower()
- return constants.nlconvert(emit)
+ return emit
def gnulib_comp(self, filetable: dict[str, list[str]], gentests: bool) -> str:
'''Emit the contents of generated $m4base/gnulib-comp.m4 file.
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index 2551e316e1..11cd6ef78a 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -645,7 +645,6 @@ def getAutomakeSnippet_Unconditional(self) -> str:
for filename in buildaux_files.split(constants.NL) ]
result += 'EXTRA_DIST += %s' % ' '.join(buildaux_files)
result += '\n\n'
- result = constants.nlconvert(result)
self.cache['makefile-unconditional'] = result
return self.cache['makefile-unconditional']
diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index dc70e8d304..a7709a1259 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -404,7 +404,6 @@ def execute(self) -> None:
if file.startswith('m4/'):
file = constants.substart('m4/', '', file)
emit += 'EXTRA_DIST += %s\n' % file
- emit = constants.nlconvert(emit)
with open(destfile, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
@@ -522,7 +521,6 @@ def execute(self) -> None:
emit += 'AH_TOP([#include \"../config.h\"])\n\n'
emit += 'AC_CONFIG_FILES([Makefile])\n'
emit += 'AC_OUTPUT\n'
- emit = constants.nlconvert(emit)
path = joinpath(self.testdir, testsbase, 'configure.ac')
with open(path, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
@@ -539,7 +537,6 @@ def execute(self) -> None:
emit += 'AUTOMAKE_OPTIONS = 1.14 foreign\n\n'
emit += 'SUBDIRS = %s\n\n' % ' '.join(subdirs)
emit += 'ACLOCAL_AMFLAGS = -I %s\n' % m4base
- emit = constants.nlconvert(emit)
path = joinpath(self.testdir, 'Makefile.am')
with open(path, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
@@ -989,7 +986,6 @@ def execute(self) -> None:
emit += ' ) 2>&1 | { if test -n "$AUTOBUILD_SUBST"; then '
emit += 'sed -e "$AUTOBUILD_SUBST"; else cat; fi; } > logs/$safemodule\n'
emit += 'done\n'
- emit = constants.nlconvert(emit)
path = joinpath(self.megatestdir, 'do-autobuild')
with open(path, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
@@ -999,7 +995,6 @@ def execute(self) -> None:
emit += 'AUTOMAKE_OPTIONS = 1.14 foreign\n\n'
emit += 'SUBDIRS = %s\n\n' % ' '.join(megasubdirs)
emit += 'EXTRA_DIST = do-autobuild\n'
- emit = constants.nlconvert(emit)
path = joinpath(self.megatestdir, 'Makefile.am')
with open(path, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
@@ -1014,7 +1009,6 @@ def execute(self) -> None:
emit += 'AC_CONFIG_SUBDIRS([%s])\n' % ' '.join(megasubdirs)
emit += 'AC_CONFIG_FILES([Makefile])\n'
emit += 'AC_OUTPUT\n'
- emit = constants.nlconvert(emit)
path = joinpath(self.megatestdir, 'configure.ac')
with open(path, mode='w', newline='\n', encoding='utf-8') as file:
file.write(emit)
diff --git a/pygnulib/constants.py b/pygnulib/constants.py
index 70381164be..2eedad40eb 100644
--- a/pygnulib/constants.py
+++ b/pygnulib/constants.py
@@ -25,7 +25,6 @@
import os
import sys
import stat
-import platform
import shutil
import tempfile
import subprocess as sp
@@ -522,15 +521,6 @@ def subend(orig: str, repl: str, data: str) -> str:
return result
-def nlconvert(text: str) -> str:
- '''Convert line-endings to specific for this platform.'''
- system = platform.system().lower()
- text = text.replace('\r\n', '\n')
- if system == 'windows':
- text = text.replace('\n', '\r\n')
- return text
-
-
def remove_trailing_slashes(text: str) -> str:
'''Remove trailing slashes from a file name, except when the file name
consists only of slashes.'''
--
2.44.0
From 279bd8ac9a2fa6a617ba11ffd5f8be0ff40bb03d Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 14 Apr 2024 10:31:34 -0700
Subject: [PATCH 2/2] gnulib-tool.py: Write newlines consistently.
* pygnulib/constants.py (NL): Remove variable.
* pygnulib/GLImport.py (GLImport.gnulib_comp): Use '\n' instead of
constants.NL.
* pygnulib/GLModuleSystem.py
(GLModule.getAutomakeSnippet_Unconditional): Likewise.
* pygnulib/main.py (main_with_exception_handling): Likewise.
---
ChangeLog | 10 ++++++++++
pygnulib/GLImport.py | 2 +-
pygnulib/GLModuleSystem.py | 18 +++++++++---------
pygnulib/constants.py | 2 --
pygnulib/main.py | 4 ++--
5 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b5c16eae4e..80e361f04f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-04-14 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Write newlines consistently.
+ * pygnulib/constants.py (NL): Remove variable.
+ * pygnulib/GLImport.py (GLImport.gnulib_comp): Use '\n' instead of
+ constants.NL.
+ * pygnulib/GLModuleSystem.py
+ (GLModule.getAutomakeSnippet_Unconditional): Likewise.
+ * pygnulib/main.py (main_with_exception_handling): Likewise.
+
2024-04-14 Collin Funk <collin.fu...@gmail.com>
gnulib-tool.py: Don't perform newline conversions.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index eaff520fa4..c6a4693c90 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -649,7 +649,7 @@ def gnulib_comp(self, filetable: dict[str, list[str]], gentests: bool) -> str:
emit += ' # Code from module %s:\n' % str(module)
snippet = module.getAutoconfEarlySnippet()
lines = [ line
- for line in snippet.split(constants.NL)
+ for line in snippet.split('\n')
if line != '' ]
if lines:
emit += ' %s\n' % '\n '.join(lines)
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index 11cd6ef78a..82b3c2f6e5 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -592,11 +592,11 @@ def getAutomakeSnippet_Unconditional(self) -> str:
# *-tests module live in tests/, not lib/.
# Synthesize an EXTRA_DIST augmentation.
files = self.getFiles()
- extra_files = filter_filelist(constants.NL, files,
+ extra_files = filter_filelist('\n', files,
'tests/', '', 'tests/', '')
if extra_files != '':
- result += 'EXTRA_DIST += %s' % ' '.join(extra_files.split(constants.NL))
- result += constants.NL * 2
+ result += 'EXTRA_DIST += %s' % ' '.join(extra_files.split('\n'))
+ result += '\n' * 2
else: # if not tests module
# Synthesize an EXTRA_DIST augmentation.
snippet = self.getAutomakeSnippet_Conditional()
@@ -609,10 +609,10 @@ def getAutomakeSnippet_Unconditional(self) -> str:
for line in mentioned_files
for filename in line.split() }
all_files = self.getFiles()
- lib_files = filter_filelist(constants.NL, all_files,
+ lib_files = filter_filelist('\n', all_files,
'lib/', '', 'lib/', '')
if lib_files != '':
- lib_files = set(lib_files.split(constants.NL))
+ lib_files = set(lib_files.split('\n'))
else:
lib_files = set()
# Remove mentioned_files from lib_files.
@@ -632,17 +632,17 @@ def getAutomakeSnippet_Unconditional(self) -> str:
# a .c file is preprocessed into another .c file for BUILT_SOURCES -,
# automake will generate a useless dependency; this is harmless.
if str(self) != 'relocatable-prog-wrapper' and str(self) != 'pt_chown':
- extra_files = filter_filelist(constants.NL, extra_files,
+ extra_files = filter_filelist('\n', extra_files,
'', '.c', '', '')
if extra_files != '':
- result += 'EXTRA_lib_SOURCES += %s' % ' '.join(extra_files.split(constants.NL))
+ result += 'EXTRA_lib_SOURCES += %s' % ' '.join(extra_files.split('\n'))
result += '\n\n'
# Synthesize an EXTRA_DIST augmentation also for the files in build-aux
- buildaux_files = filter_filelist(constants.NL, all_files,
+ buildaux_files = filter_filelist('\n', all_files,
'build-aux/', '', 'build-aux/', '')
if buildaux_files != '':
buildaux_files = [ os.path.join('$(top_srcdir)', joinpath(auxdir, filename))
- for filename in buildaux_files.split(constants.NL) ]
+ for filename in buildaux_files.split('\n') ]
result += 'EXTRA_DIST += %s' % ' '.join(buildaux_files)
result += '\n\n'
self.cache['makefile-unconditional'] = result
diff --git a/pygnulib/constants.py b/pygnulib/constants.py
index 2eedad40eb..899ba46efd 100644
--- a/pygnulib/constants.py
+++ b/pygnulib/constants.py
@@ -55,8 +55,6 @@
ENCS = dict() # Encodings
MODES = dict() # Modes
TESTS = dict() # Tests
-NL = '''
-''' # Newline character
# Set ENCS dictionary
if not hasattr(interpreter, '__file__'):
diff --git a/pygnulib/main.py b/pygnulib/main.py
index b24db139b5..fd39cf07a6 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -1414,11 +1414,11 @@ def main_with_exception_handling() -> None:
message += 'missing --lib option'
elif errno == 11:
incompatibilities = ''
- message += 'incompatible license on modules:%s' % constants.NL
+ message += 'incompatible license on modules:\n'
for pair in errinfo:
incompatibilities += pair[0]
incompatibilities += ' %s' % pair[1]
- incompatibilities += constants.NL
+ incompatibilities += '\n'
tempname = mktemp()
with open(tempname, mode='w', newline='\n', encoding='utf-8') as file:
file.write(incompatibilities)
--
2.44.0