Re: gnulib-tool.py in jugtail

2024-04-12 Thread Collin Funk
Hi Bruno,

On 4/12/24 3:28 PM, Bruno Haible wrote:
> I am applying these two refactorings. Hope it makes this piece of code
> easier to understand.

Thanks!

It looks like you got all the cache tests passing. Nice work.

Collin



Re: gnulib-tool.py in jugtail

2024-04-12 Thread Bruno Haible
Collin Funk wrote:
> Then only set it to the cache or
> default in GLImport.__init__(). But that section of code is already
> sort of difficult to follow...

I am applying these two refactorings. Hope it makes this piece of code
easier to understand.

>From 27c5b31a42ccd5353ccff09d46dbaa0d105f0f0b Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sat, 13 Apr 2024 00:10:44 +0200
Subject: [PATCH 1/2] gnulib-tool.py: Optimize.

* pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Avoid
useless cloning of dictionaries.
---
 ChangeLog|  6 ++
 pygnulib/GLConfig.py | 24 +++-
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b25819a4aa..212a78b305 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-12  Bruno Haible  
+
+	gnulib-tool.py: Optimize.
+	* pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Avoid
+	useless cloning of dictionaries.
+
 2024-04-12  Bruno Haible  
 
 	gnulib-tool.py: Implement --no-conditional-dependencies correctly.
diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py
index e938b30a5e..515047d3f0 100644
--- a/pygnulib/GLConfig.py
+++ b/pygnulib/GLConfig.py
@@ -275,21 +275,27 @@ class GLConfig:
 if type(dictionary) is not GLConfig:
 raise TypeError('dictionary must be a GLConfig, not %s'
 % type(dictionary).__name__)
-dictionary = dict(dictionary.table)
+dictionary = dictionary.table
 result = dict()
 for key in dictionary:
 src = self.table[key]
 dest = dictionary[key]
-result[key] = src
-if src != dest:
+# Merge src and dest into a single value.
+if src == dest:
+value = src
+else:
 if self.isdefault(key, src):
-result[key] = dest
+value = dest
 else:  # if not self.isdefault(key, src)
-if not self.isdefault(key, dest):
+if self.isdefault(key, dest):
+value = src
+else:  # if not self.isdefault(key, dest)
 if key in ['modules', 'avoids', 'tests']:
-dest = sorted(set(src + dest))
-result[key] = dest
-self.table = dict(result)
+value = sorted(set(src + dest))
+else:
+value = dest
+result[key] = value
+self.table = result
 
 def update_key(self, dictionary: GLConfig, key: str) -> None:
 '''Update the given key using value from the given dictionary.'''
@@ -297,7 +303,7 @@ class GLConfig:
 if type(dictionary) is not GLConfig:
 raise TypeError('dictionary must be a GLConfig, not %s'
 % type(dictionary).__name__)
-dictionary = dict(dictionary.table)
+dictionary = dictionary.table
 self.table[key] = dictionary[key]
 else:  # if key not in self.table
 raise KeyError('GLConfig does not contain key: %s' % repr(key))
-- 
2.34.1

>From 48f615b71b7299e7416ca46db076b7e61820a2f2 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sat, 13 Apr 2024 00:24:52 +0200
Subject: [PATCH 2/2] gnulib-tool.py: Refactor.

* pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Improve
variable names and comments.
* pygnulib/GLImport.py (GLImport.__init__): Improve comments.
---
 ChangeLog|  7 +++
 pygnulib/GLConfig.py | 24 
 pygnulib/GLImport.py | 30 +++---
 3 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 212a78b305..4d5725f843 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-04-12  Bruno Haible  
+
+	gnulib-tool.py: Refactor.
+	* pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Improve
+	variable names and comments.
+	* pygnulib/GLImport.py (GLImport.__init__): Improve comments.
+
 2024-04-12  Bruno Haible  
 
 	gnulib-tool.py: Optimize.
diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py
index 515047d3f0..ab1cb218be 100644
--- a/pygnulib/GLConfig.py
+++ b/pygnulib/GLConfig.py
@@ -270,12 +270,12 @@ class GLConfig:
 table = copy.deepcopy(self)
 return table
 
-def update(self, dictionary: GLConfig) -> None:
-'''Specify the dictionary whose keys will be used to update config.'''
-if type(dictionary) is not GLConfig:
-raise TypeError('dictionary must be a GLConfig, not %s'
-% type(dictionary).__name__)
-dictionary = dictionary.table
+def update(self, other_config: GLConfig) -> None:
+'''Merges all non-default values from other_config into this config.'''
+if type(other_config) is not GLConfig:
+raise 

Re: gnulib-tool.py in jugtail

2024-04-12 Thread Collin Funk
On 4/12/24 5:08 AM, Bruno Haible wrote:
> OK, if you want to rework this part, we need unit tests for it first.
> I have now added unit tests for the gnulib-cache.m4 handling; essentially,
> one test for each possible option.
> 
> Before dealing with the 'jugtail' package, it would be good to make
> these tests work. Currently, a number of them fails:

Sounds good. Thanks for adding them.

Collin



Re: gnulib-tool.py in jugtail

2024-04-12 Thread Bruno Haible
Hi Collin,

> It looks like the reading of gnulib-cache.m4 will need to be reworked.

OK, if you want to rework this part, we need unit tests for it first.
I have now added unit tests for the gnulib-cache.m4 handling; essentially,
one test for each possible option.

Before dealing with the 'jugtail' package, it would be good to make
these tests work. Currently, a number of them fails:

$ ./test-all.sh PASS: test-hello-c-gnulib-1.sh
PASS: test-hello-c-gnulib-automakesubdir-1.sh
PASS: test-hello-c-gnulib-automakesubdir-withtests-1.sh
PASS: test-hello-c-gnulib-conddeps-1.sh
PASS: test-hello-c-gnulib-nonrecursive-1.sh
PASS: test-cache-1-1.sh
PASS: test-cache-1-2.sh
PASS: test-cache-1-3.sh
PASS: test-cache-1-4.sh
PASS: test-cache-1-5.sh
PASS: test-cache-1-6.sh
Files ./test-cache-1-7.result/m4/gnulib-cache.m4 and 
tmp3074241-result/m4/gnulib-cache.m4 differ
FAIL: gnulib-tool's result has unexpected differences.
FAIL: test-cache-1-7.sh
Files ./test-cache-1-8.result/lib/Makefile.am and 
tmp3074263-result/lib/Makefile.am differ
Files ./test-cache-1-8.result/m4/gnulib-cache.m4 and 
tmp3074263-result/m4/gnulib-cache.m4 differ
FAIL: gnulib-tool's result has unexpected differences.
FAIL: test-cache-1-8.sh
PASS: test-cache-1-9.sh
PASS: test-cache-1-10.sh
PASS: test-cache-1-11.sh
PASS: test-cache-1-12.sh
PASS: test-cache-1-13.sh
PASS: test-cache-1-14.sh
PASS: test-cache-1-15.sh
PASS: test-cache-1-16.sh
PASS: test-cache-1-17.sh
PASS: test-cache-1-18.sh
PASS: test-cache-1-19.sh
PASS: test-cache-1-20.sh
PASS: test-cache-1-21.sh
PASS: test-cache-1-22.sh
PASS: test-cache-1-23.sh
PASS: test-cache-1-24.sh
PASS: test-cache-1-25.sh
PASS: test-cache-1-26.sh
PASS: test-cache-1-27.sh
PASS: test-cache-1-28.sh
PASS: test-cache-1-29.sh
PASS: test-cache-1-30.sh
./test-cache-1-31.err tmp3074843-err differ: byte 1, line 1
--- ./test-cache-1-31.err   2024-04-12 00:02:39.013521019 +0200
+++ tmp3074843-err  2024-04-12 14:03:20.355689866 +0200
@@ -1 +1 @@
-gnulib-tool: warning: --po-domain has no effect without a --po-base option
+.../gnulib-tool.py: warning: --po-domain has no effect without a --po-base 
option
FAIL: gnulib-tool's error output has unexpected differences.
FAIL: test-cache-1-31.sh
PASS: test-cache-1-32.sh
PASS: test-cache-1-33.sh
PASS: test-cache-1-34.sh
Only in tmp3074942-result/lib: Makefile.am
Only in ./test-cache-2-1.result/lib: Makefile.gnulib
Files ./test-cache-2-1.result/m4/gnulib-cache.m4 and 
tmp3074942-result/m4/gnulib-cache.m4 differ
Only in tmp3074942-result: support
Only in tmp3074942-result/tests: Makefile.am
Only in ./test-cache-2-1.result/tests: Makefile.gnulib
FAIL: gnulib-tool's result has unexpected differences.
FAIL: test-cache-2-1.sh
Only in tmp3074970-result/lib: Makefile.am
Only in ./test-cache-2-2.result/lib: Makefile.gnulib
Files ./test-cache-2-2.result/m4/gnulib-cache.m4 and 
tmp3074970-result/m4/gnulib-cache.m4 differ
Only in tmp3074970-result: support
Only in tmp3074970-result/tests: Makefile.am
Only in ./test-cache-2-2.result/tests: Makefile.gnulib
FAIL: gnulib-tool's result has unexpected differences.
FAIL: test-cache-2-2.sh
Only in tmp3074998-result/lib: Makefile.am
Only in ./test-cache-2-3.result/lib: Makefile.gnulib
Files ./test-cache-2-3.result/m4/gnulib-cache.m4 and 
tmp3074998-result/m4/gnulib-cache.m4 differ
Only in tmp3074998-result: support
Only in tmp3074998-result/tests: Makefile.am
Only in ./test-cache-2-3.result/tests: Makefile.gnulib
FAIL: gnulib-tool's result has unexpected differences.
FAIL: test-cache-2-3.sh
Only in tmp3075026-result/lib: Makefile.am
Only in ./test-cache-2-4.result/lib: Makefile.gnulib
Files ./test-cache-2-4.result/m4/gnulib-cache.m4 and 
tmp3075026-result/m4/gnulib-cache.m4 differ
Only in tmp3075026-result: support
Only in tmp3075026-result/tests: Makefile.am
Only in ./test-cache-2-4.result/tests: Makefile.gnulib
FAIL: gnulib-tool's result has unexpected differences.
FAIL: test-cache-2-4.sh
Only in tmp3075054-result/lib: Makefile.am
Only in ./test-cache-2-5.result/lib: Makefile.gnulib
Only in ./test-cache-2-5.result/m4: ansi-c++.m4
Only in ./test-cache-2-5.result/m4: assert_h.m4
Only in ./test-cache-2-5.result/m4: c-bool.m4
Only in ./test-cache-2-5.result/m4: codeset.m4
Files ./test-cache-2-5.result/m4/gnulib-cache.m4 and 
tmp3075054-result/m4/gnulib-cache.m4 differ
Files ./test-cache-2-5.result/m4/gnulib-comp.m4 and 
tmp3075054-result/m4/gnulib-comp.m4 differ
Only in ./test-cache-2-5.result/m4: inttypes.m4
Only in ./test-cache-2-5.result/m4: limits-h.m4
Only in ./test-cache-2-5.result/m4: locale-fr.m4
Only in ./test-cache-2-5.result/m4: multiarch.m4
Only in ./test-cache-2-5.result/m4: std-gnu11.m4
Only in ./test-cache-2-5.result/m4: stdalign.m4
Only in ./test-cache-2-5.result/m4: stdint.m4
Only in ./test-cache-2-5.result/m4: stdlib_h.m4
Only in ./test-cache-2-5.result/m4: wchar_h.m4
Only in ./test-cache-2-5.result/m4: wint_t.m4
Only in tmp3075054-result: support
Only in ./test-cache-2-5.result: tests
FAIL: gnulib-tool's result has unexpected 

Re: gnulib-tool.py in jugtail

2024-04-11 Thread Collin Funk
On 4/10/24 7:23 PM, Bruno Haible wrote:
> $ cat ../glpyFfCgil-sh-err
> .../gnulib-tool.sh: *** missing --doc-base option. --doc-base has been 
> introduced on 2006-07-11; if your last invocation of 'gnulib-tool 
> --import' is before that date, you need to run 'gnulib-tool --import' 
> once, with a --doc-base option.
> .../gnulib-tool.sh: *** Stop.
> $ cat ../glpyFfCgil-py-err
> gnulib-tool: warning: module malloc doesn't exist

I just started looking at this. It looks like the reading of
gnulib-cache.m4 will need to be reworked.

In gnulib-tool.sh line 5203:

# The docbase defaults to the cached one.
if test -z "$docbase"; then
  docbase="$cached_docbase"
  if test -z "$docbase"; then
 # Long error message here.
  fi
fi

The corresponding section would be GLImport.__init__(), but we set the
default docbase in main.py line 943, before creating the GLImport:

if not docbase:
docbase = 'doc'

So we can't check for the empty string. I guess we docbase an empty
string if --docbase isn't used. Then only set it to the cache or
default in GLImport.__init__(). But that section of code is already
sort of difficult to follow...

Collin