bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH] gnulib-tool.py: Fix configure.ac output.
@ 2024-02-27 22:31 Collin Funk
  2024-02-27 22:39 ` Bruno Haible
  0 siblings, 1 reply; 5+ messages in thread
From: Collin Funk @ 2024-02-27 22:31 UTC (permalink / raw)
  To: bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 1501 bytes --]

Here is a patch fixing an issue I've noticed in the output of
configure.ac (and configure) created by gnulib.py.

When running the following command,

gnulib-tool.py --create-testdir --dir test-dir-python dummy

creates a configure.ac like so:

gl_source_base='gllib'

\
  m4_ifval(gl_LIBSOURCES_LIST, [
    m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ ||
...
    AC_SUBST([gl_LIBOBJS], [$gl_libobjs])
    AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs])
  ])\n  LIBGNU_LIBDEPS="$gl_libdeps"
...

This causes the 'configure' script to try to execute 'n' twice like
so:

checking for Minix Amsterdam compiler... no
checking for ar... ar
checking for ranlib... ranlib
./configure: line 5004: n: command not found

This seems to be caused by this commit trying to clean up the code:

https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=f00ef30ee0a68bf91cfd081afc784cb8ffd00656

I assume that this string literal was changed to a raw string [1] in
order to avoid having to escape a sed statement. Since it is already
wrapped in triple quotes we can just add a newline in the code and
have the output change instead of using '\n'.

I've also changed the """foo""" quoting to '''foo''' quoting in that
statement. I assume that is also the preferred coding style, feel free
to change it if I misinterpreted. I will have to modify this file a
few times while handling the TODO, so I will fix the other double
quote offenders then.

[1] https://docs.python.org/3/library/re.html#raw-string-notation

Collin

[-- Attachment #2: 0001-gnulib-tool.py-Fix-configure.ac-output.patch --]
[-- Type: text/x-patch, Size: 1681 bytes --]

From a9932bf82e3b5e1526e801a55f743a0c8aeb2331 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.funk1@gmail.com>
Date: Tue, 27 Feb 2024 14:15:10 -0800
Subject: [PATCH] gnulib-tool.py: Fix configure.ac output.

* pygnulib/GLEmiter.py (GLEmiter.initmacro_end): Fix backslash escapes
in raw string.
---
 ChangeLog            | 6 ++++++
 pygnulib/GLEmiter.py | 5 +++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a71c5a771c..7d65e27151 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-02-27  Collin Funk  <collin.funk1@gmail.com>
+
+	gnulib-tool.py: Fix configure.ac output.
+	* pygnulib/GLEmiter.py (GLEmiter.initmacro_end): Fix backslash escapes
+	in raw string.
+
 2024-02-27  Collin Funk  <collin.funk1@gmail.com>
 
 	gnulib-tool.py: Follow gnulib-tool changes, part 31.
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index 56e8156761..d8cc085f59 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -508,7 +508,7 @@ USE_MSGCTXT = no\n"""
         # arguments. The check is performed only when autoconf is run from the
         # directory where the configure.ac resides; if it is run from a different
         # directory, the check is skipped.
-        emit += r"""\
+        emit += r'''
   m4_ifval(%V1%_LIBSOURCES_LIST, [
     m4_syscmd([test ! -d ]m4_defn([%V1%_LIBSOURCES_DIR])[ ||
       for gl_file in ]%V1%_LIBSOURCES_LIST[ ; do
@@ -540,7 +540,8 @@ USE_MSGCTXT = no\n"""
     fi
     AC_SUBST([%V1%_LIBOBJS], [$%V1%_libobjs])
     AC_SUBST([%V1%_LTLIBOBJS], [$%V1%_ltlibobjs])
-  ])\n"""
+  ])
+'''
         emit = emit.replace('%V1%', macro_prefix_arg)
         return emit
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] gnulib-tool.py: Fix configure.ac output.
  2024-02-27 22:31 [PATCH] gnulib-tool.py: Fix configure.ac output Collin Funk
@ 2024-02-27 22:39 ` Bruno Haible
  2024-02-27 23:01   ` Collin Funk
  0 siblings, 1 reply; 5+ messages in thread
From: Bruno Haible @ 2024-02-27 22:39 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Collin Funk

Collin Funk wrote:
> When running the following command,
> 
> gnulib-tool.py --create-testdir --dir test-dir-python dummy
> 
> creates a configure.ac like so:
> 
> gl_source_base='gllib'
> 
> \
>   m4_ifval(gl_LIBSOURCES_LIST, [
>     m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ ||
> ...
>     AC_SUBST([gl_LIBOBJS], [$gl_libobjs])
>     AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs])
>   ])\n  LIBGNU_LIBDEPS="$gl_libdeps"
> ...

Indeed, that's not right.

Thanks for the patch; applied.

> https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=f00ef30ee0a68bf91cfd081afc784cb8ffd00656
> 
> I assume that this string literal was changed to a raw string [1] in
> order to avoid having to escape a sed statement. Since it is already
> wrapped in triple quotes we can just add a newline in the code

I guess I wasn't very familiar with raw strings when I did this change.

Bruno





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gnulib-tool.py: Fix configure.ac output.
  2024-02-27 22:39 ` Bruno Haible
@ 2024-02-27 23:01   ` Collin Funk
  2024-02-27 23:39     ` Bruno Haible
  0 siblings, 1 reply; 5+ messages in thread
From: Collin Funk @ 2024-02-27 23:01 UTC (permalink / raw)
  To: Bruno Haible, bug-gnulib

Hi Bruno,

On 2/27/24 2:39 PM, Bruno Haible wrote:
> I guess I wasn't very familiar with raw strings when I did this change.

No worries, it was pretty easy to find and fix. I remember a professor
in college telling us to always use them for Python regular
expressions. It seems this is also recommended by the Python people,
see the '\' character under this page:

https://docs.python.org/3/library/re.html#regular-expression-syntax

Collin


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gnulib-tool.py: Fix configure.ac output.
  2024-02-27 23:01   ` Collin Funk
@ 2024-02-27 23:39     ` Bruno Haible
  2024-02-28  0:04       ` Collin Funk
  0 siblings, 1 reply; 5+ messages in thread
From: Bruno Haible @ 2024-02-27 23:39 UTC (permalink / raw)
  To: bug-gnulib, Collin Funk

Collin Funk wrote:
> > I guess I wasn't very familiar with raw strings when I did this change.
> 
> No worries, it was pretty easy to find and fix. I remember a professor
> in college telling us to always use them for Python regular
> expressions. It seems this is also recommended by the Python people,
> see the '\' character under this page:
> 
> https://docs.python.org/3/library/re.html#regular-expression-syntax

Indeed, this doc contains the explanation for the 'pycodestyle'
warning that I was seeing. With a plain string instead of a raw string,
I get:

$ pycodestyle *.py
...
GLEmiter.py:535:26: W605 invalid escape sequence '\.'
GLEmiter.py:535:35: W605 invalid escape sequence '\.'
...

which indicates that the Python parser would have eaten up the backslash
before the regular expression engine could see it.

Bruno





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gnulib-tool.py: Fix configure.ac output.
  2024-02-27 23:39     ` Bruno Haible
@ 2024-02-28  0:04       ` Collin Funk
  0 siblings, 0 replies; 5+ messages in thread
From: Collin Funk @ 2024-02-28  0:04 UTC (permalink / raw)
  To: Bruno Haible, bug-gnulib

On 2/27/24 3:39 PM, Bruno Haible wrote:
> $ pycodestyle *.py
> ...
> GLEmiter.py:535:26: W605 invalid escape sequence '\.'
> GLEmiter.py:535:35: W605 invalid escape sequence '\.'
> ...

I discovered it that way too. I like using Eglot from Emacs though. If
you are using Emacs 29+ the `eglot' command should be built-in. In
that case in the following line:

      sed_drop_objext='s/\.o$//;s/\.obj$//'

The '\.o$//;s/\.obj$//' part will be crossed out. Not sure if that is
your perfected way of doing things but I find it useful so I figured
I'd mention it. :)

Collin


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-28  0:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 22:31 [PATCH] gnulib-tool.py: Fix configure.ac output Collin Funk
2024-02-27 22:39 ` Bruno Haible
2024-02-27 23:01   ` Collin Funk
2024-02-27 23:39     ` Bruno Haible
2024-02-28  0:04       ` Collin Funk

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).