From: Collin Funk <collin.funk1@gmail.com>
To: bug-gnulib@gnu.org
Subject: gnulib-tool.py: Fix reading of 'gl_VC_FILES' in gnulib-cache.m4.
Date: Fri, 29 Mar 2024 20:41:29 -0700 [thread overview]
Message-ID: <6d026466-ef35-4dfd-bdb0-e43ba73489c0@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 4247 bytes --]
This small patch fixes this diff in the import tests:
$ cat ../output.txt
$ diff -u ./test-oath-toolkit-1.result/gl/m4/gnulib-cache.m4 tmp27490-result/gl/m4/gnulib-cache.m4
--- ./test-oath-toolkit-1.result/gl/m4/gnulib-cache.m4 2024-03-29 02:47:03.843697386 -0700
+++ tmp27490-result/gl/m4/gnulib-cache.m4 2024-03-29 20:02:25.589459017 -0700
@@ -37,7 +37,6 @@
# --no-conditional-dependencies \
# --no-libtool \
# --macro-prefix=gl \
-# --no-vc-files \
# autobuild \
# git-version-gen \
# gitlog-to-changelog \
@@ -64,4 +63,3 @@
gl_MACRO_PREFIX([gl])
gl_PO_DOMAIN([])
gl_WITNESS_C_MACRO([])
-gl_VC_FILES([false])
Here is the fix inline because it is useful for explaining things
below:
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index eb382cadac..81298eeca1 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -202,7 +202,7 @@ class GLImport(object):
self.cache.setPoDomain(cleaner(tempdict['gl_PO_DOMAIN']))
if tempdict['gl_WITNESS_C_MACRO']:
self.cache.setWitnessCMacro(cleaner(tempdict['gl_WITNESS_C_MACRO']))
- if tempdict['gl_VC_FILES']:
+ if tempdict['gl_VC_FILES'] != '':
self.cache.setVCFiles(cleaner(tempdict['gl_VC_FILES']))
# Get cached filelist from gnulib-comp.m4.
The tempdict is populated in these lines, where keys is a list of
accepted gl_* m4 macros:
result = dict(pattern.findall(data))
values = cleaner([ result.get(key, '')
for key in keys ])
tempdict = dict(zip(keys, values))
This creates a dictionary mapping the macro to the value inside of it:
gl_MACRO([something-here]) -> { 'gl_MACRO' : 'something-here' }
or for a macro that isn't seen, an empty string is set as the value:
{ 'gl_UNSEEN_MACRO' : '' }
The problem occurs with that conditional because of the 'cleaner'
function:
def cleaner(sequence: str | list[str]) -> str | list[str | bool]:
'''Clean string or list of strings after using regex.'''
if type(sequence) is str:
sequence = sequence.replace('[', '')
sequence = sequence.replace(']', '')
elif type(sequence) is list:
sequence = [ value.replace('[', '').replace(']', '')
for value in sequence]
sequence = [ value.replace('(', '').replace(')', '')
for value in sequence]
sequence = [ False if value == 'false' else value
for value in sequence ]
sequence = [ True if value == 'true' else value
for value in sequence ]
sequence = [ value.strip()
if type(value) is str else value
for value in sequence ]
return sequence
So in the case that 'gnulib-comp.m4' does not contain any
'gl_VC_FILES' invocation, in tempdict we have:
{ 'gl_VC_FILES' : '' }
In this case the default value of None in GLConfig is correct, nothing
needs to be done. When we have 'gl_VC_FILES([true])' or
'gl_VC_FILES([false])':
{ 'gl_VC_FILES' : True }
{ 'gl_VC_FILES' : False }
Therefore, with the previous condition, 'gl_VC_FILES([false])' would
not update the GLConfig. It would be left at the default None, which
is incorrect.
I dislike this section of code. I remember previously 'value.strip()'
would be called in cleaner when value was a bool, which would cause it
to crash.
How about we remove that cleaner function and simply make the regular
expression more strict? It should make it behave more similar to
gnulib-tool.sh anyways. Something like this for an (untested) idea:
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 81298eeca1..55fc87c202 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -121,6 +121,7 @@ class GLImport(object):
# Create regex object and keys.
pattern = re.compile(r'^(gl_.*?)\((.*?)\)$', re.S | re.M)
+ pattern = re.compile(r'^(gl_.*?)\([\[ ]*([^\]"\$`\\\)]*).*$', re.MULTILINE)
keys = \
[
'gl_LOCAL_DIR', 'gl_MODULES', 'gl_AVOID', 'gl_SOURCE_BASE',
Collin
[-- Attachment #2: 0001-gnulib-tool.py-Fix-reading-of-gl_VC_FILES-in-gnulib-.patch --]
[-- Type: text/x-patch, Size: 1562 bytes --]
From afd9fbe4cc59c8b9b45859c7271f5cb12891453e Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.funk1@gmail.com>
Date: Fri, 29 Mar 2024 20:15:24 -0700
Subject: [PATCH] gnulib-tool.py: Fix reading of 'gl_VC_FILES' in
gnulib-cache.m4.
* pygnulib/GLImport.py (GLImport.__init__): Check for an empty string
explicitly in conditional so False is not ignored.
---
ChangeLog | 6 ++++++
pygnulib/GLImport.py | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index eab98607a2..6d31a954c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-03-29 Collin Funk <collin.funk1@gmail.com>
+
+ gnulib-tool.py: Fix reading of 'gl_VC_FILES' in gnulib-cache.m4.
+ * pygnulib/GLImport.py (GLImport.__init__): Check for an empty string
+ explicitly in conditional so False is not ignored.
+
2024-03-29 Paul Eggert <eggert@cs.ucla.edu>
intprops: pacify GCC < 10 -Wsign-compare
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index eb382cadac..81298eeca1 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -202,7 +202,7 @@ class GLImport(object):
self.cache.setPoDomain(cleaner(tempdict['gl_PO_DOMAIN']))
if tempdict['gl_WITNESS_C_MACRO']:
self.cache.setWitnessCMacro(cleaner(tempdict['gl_WITNESS_C_MACRO']))
- if tempdict['gl_VC_FILES']:
+ if tempdict['gl_VC_FILES'] != '':
self.cache.setVCFiles(cleaner(tempdict['gl_VC_FILES']))
# Get cached filelist from gnulib-comp.m4.
--
2.44.0
next reply other threads:[~2024-03-30 3:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-30 3:41 Collin Funk [this message]
2024-03-30 23:22 ` gnulib-tool.py: Fix reading of 'gl_VC_FILES' in gnulib-cache.m4 Bruno Haible
2024-03-31 0:39 ` gnulib-tool test suite updates Collin Funk
2024-03-31 21:52 ` Bruno Haible
2024-03-31 23:07 ` Collin Funk
2024-03-31 23:11 ` Bruno Haible
2024-04-01 0:32 ` Collin Funk
2024-04-01 0:43 ` gnulib-tool.py: Add missing quotation mark to reminder Collin Funk
2024-04-01 0:48 ` Bruno Haible
2024-04-01 1:06 ` gnulib-tool.py: Use case-sensitive sorting for files Collin Funk
2024-04-01 13:06 ` Bruno Haible
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
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6d026466-ef35-4dfd-bdb0-e43ba73489c0@gmail.com \
--to=collin.funk1@gmail.com \
--cc=bug-gnulib@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).