Re: gnulib-tool.py: Don't use mutable default arguments.

2024-04-13 Thread Bruno Haible
Hi Collin, > Here is a test program to demonstrate: > > > #!/usr/bin/env python3 > > def function(arg1, arg2 = dict()): > arg2[arg1] = 0 > print(arg2) > > function('one') > function('two') > function('three') > > > When

gnulib-tool.py: Don't use mutable default arguments.

2024-04-13 Thread Collin Funk
This patch fixes an interesting warning given by PyCharm. With this line: def __init__(self, config: GLConfig, transformers: dict[str, tuple[re.Pattern, str] | None] = dict()) -> None: Under '= dict()', I see a warning about mutable default arguments. Here is a test program to demonstrate:

Re: hash_delete safe to remove?

2024-04-13 Thread Collin Funk
On 4/13/24 5:50 PM, Bruno Haible wrote: > Has there been an official 'patch' release that includes the change, > already? If not, it's too early: Some people (or distros) like to > take the git checkout of the latest release and rebuild the generated > files with the newest gnulib. There will be so

Re: hash_delete safe to remove?

2024-04-13 Thread Bruno Haible
Collin Funk wrote: > A month or two ago I updated gnulib in GNU patch to fix some build > failures. I also noticed some deprecation warnings from 'hash_delete' > and changed them to 'hash_remove'. > > I forgot to ask here, but should this be removed now? Has there been an official 'patch' release

Re: ./bootstrap --gnulib-srcdir and GNULIB_REVISION

2024-04-13 Thread Bruno Haible
Simon Josefsson wrote: > Alas, GNULIB_REVISION is not documented in doc/gnulib.texi. Yes, that's because the more modern way is to use a git submodule instead. This is documented in https://www.gnu.org/software/gnulib/manual/html_node/VCS-Issues.html https://www.gnu.org/software/gnulib/manual/html

Re: ./bootstrap --gnulib-srcdir and GNULIB_REVISION

2024-04-13 Thread Bruno Haible
Hi Simon, > Bug #2: ./bootstrap writes to the path indicated by --gnulib-srcdir with > the 'git checkout' command, and leaves the --gnulib-srcdir path at that > commit after ./bootstrap is finished. This happens to work in my > example since I pointed it to a writable work tree, but I think alter

Re: ./bootstrap --gnulib-srcdir and GNULIB_REVISION

2024-04-13 Thread Bruno Haible
Hi Simon, After fixing the --help output, I'm changing the 'bootstrap' logic to follow this documentation. Two patches: * 0001 simplifies the logic by removing fallback code for git versions < 1.6.4. Version 1.6.4 was released in 2009, that is, 15 years ago. When encountering such an old versi

hash_delete safe to remove?

2024-04-13 Thread Collin Funk
A month or two ago I updated gnulib in GNU patch to fix some build failures. I also noticed some deprecation warnings from 'hash_delete' and changed them to 'hash_remove'. I forgot to ask here, but should this be removed now? Or bump the date? :) In lib/hash.c: /* Same as hash_remove. This inte

Re: argp --help formatting bug with non-ASCII characters

2024-04-13 Thread Lasse Collin
On 2024-04-12 Bruno Haible wrote: > How to reproduce: > 1. Build GNU tar (1.33 or 1.35, for example). > 2. Install it. > 3. You can see misindentation: > $ LC_ALL=de_DE.UTF-8 src/tar --help > > ... > abzubilden > --mode=ÄNDERUNGEN den (symbolischen) Modus ÄND

Re: Improve 'git diff' of Python files.

2024-04-13 Thread Bruno Haible
Thanks, applied.

Improve 'git diff' of Python files.

2024-04-13 Thread Collin Funk
Hi Bruno, On 4/13/24 11:08 AM, Bruno Haible wrote: > That will be nice, indeed. Please, can you provide a patch (with a ChangeLog > entry)? Sure, I attached a patch. CollinFrom 9e2fcc6d5e8f30b402627cc73b7da1109c047249 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Sat, 13 Apr 2024 11:16:44 -0

Re: .gitattributes

2024-04-13 Thread Bruno Haible
Collin Funk wrote: > Also, I found out that adding '*.py diff=python' to .gitattributes > will give a better diff hunk header [1]: > > diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py > index d44ceedcec..098bbc59ac 100644 > --- a/pygnulib/GLImport.py > +++ b/pygnulib/GLImport.py > @@ -1230

Re: gnulib-tool.py: Fix extra arguments to function call.

2024-04-13 Thread Bruno Haible
Collin Funk wrote: > I see a warning for this section of code because isfile() is called > with two arguments. It looks like the correct way to write this is to > joinpath() the two arguments Yes, I agree. Thanks! Applied. Bruno

Re: ./bootstrap --gnulib-srcdir and GNULIB_REVISION

2024-04-13 Thread Bruno Haible
Simon Josefsson wrote: > My reaction was initially exactly the same as yours, until I found this > piece of --help documentation, which actually is the first (and > presumably highest priority) rule: > > * If the environment variable GNULIB_SRCDIR is set (either as an >environment variable or

Re: gnulib-tool.py: Fix extra arguments to function call.

2024-04-13 Thread Collin Funk
On 4/13/24 10:12 AM, Collin Funk wrote: > diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py > index d44ceedcec..098bbc59ac 100644 > --- a/pygnulib/GLImport.py > +++ b/pygnulib/GLImport.py > @@ -1230,7 +1230,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix Also, I found out that adding '*

gnulib-tool.py: Fix extra arguments to function call.

2024-04-13 Thread Collin Funk
I see a warning for this section of code because isfile() is called with two arguments. It looks like the correct way to write this is to joinpath() the two arguments, since that is what is done in self.assistant.super_update() when not self.config['dryrun']. diff --git a/pygnulib/GLImport.py b/py

gnulib-tool.py: Stop using codecs.open

2024-04-13 Thread Bruno Haible
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]. Let's use this consistently. With newline='\n' in order to match what gnulib-tool.sh does. Specifying encoding='utf-8' is what makes the most sense today. If a p

Re: gnulib-tool.py: Refactor directory tree removals

2024-04-13 Thread Bruno Haible
Hi Collin, > > +try: > > +shutil.rmtree(dest) > > +except FileNotFoundError: > > +pass > > You should be able to use 'shutil.rmtree(dest, ignore_errors=True)' > here [1]. Unless you have a reason for not doing so that I missed. It can be useful to get Perm

Re: gnulib-tool.py: Refactor directory tree removals

2024-04-13 Thread Collin Funk
Hi Bruno, On 4/13/24 3:17 AM, Bruno Haible wrote: > +def rmtree(dest: str) -> None: > +'''Removes the file or directory tree at dest, if it exists.''' > +# These two implementations are nearly equivalent. > +# Speed: 'rm -rf' can be a little faster. > +# Exceptions: shutil.rmtree r

gnulib-tool.py: Refactor directory tree removals

2024-04-13 Thread Bruno Haible
There are two ways to remove a directory tree: via 'rm -rf' and through shutil.rmtree. The former is ca. 10% faster on average. Also, it is more likely to include platform-specific optimizations. So, let's use it. 2024-04-13 Bruno Haible gnulib-tool.py: Refactor directory tree removal