Hi Bruno,
On 3/16/24 9:22 AM, Bruno Haible wrote:
> I don't know. Maybe it is related to
> https://stackoverflow.com/questions/16981921/relative-imports-in-python-3 ?
The import stuff always caused me issues in the past when I used
Python. The way we have it now works so I will continue to use it.
Might be something I look into in the future though.
> This typically requires experimentation. (Same problem as in other
> programming languages/environments.) ...
> It depends. If you can get away with catching a smaller set of exceptions,
> it's better.
I see, thanks. I am most comfortable with C so the exception stuff is
sort of new to me. I've used Java and C++ a few years ago but not for
anything complex.
> This idiom is more widely applicable, indeed: It works also for commands
> that may produce warnings.
I've submitted a new patch that tries to copy the behavior of
gnulib-tool.sh. In my original patch I had a misunderstanding of
'git update-index --refresh'.
$ git update-index --refresh
gnulib-tool.py: needs update
$ echo $?
1
For some reason I thought that the message was stderr and the exit
code was zero. Now that I have corrected that misunderstanding, I
don't think there is a need to do fancy subprocess module stuff:
if copymode == classes.CopyAction.Hardlink or lcopymode ==
classes.CopyAction.Hardlink:
# Setting hard links modifies the ctime of files in the gnulib checkout.
# This disturbs the result of the next "gitk" invocation.
# Workaround: Let git scan the files. This can be done through
# "git update-index --refresh" or "git status" or "git diff".
if isdir(joinpath(APP['root'], '.git')):
try:
sp.run(['git', 'update-index', '--refresh'],
cwd=APP['root'], stdout=sp.DEVNULL)
except FileNotFoundError:
# No 'git' program was found.
pass
I've fixed the condition from the original patch, since we only care
if hard links were used. Then the subprocess documentation says the
most common exception is 'OSError' [1]. This is a parent class to many
different exceptions corresponding to 'errno' values [2]. From
experimenting, I've confirmed that calling an invalid program will
throw 'FileNotFoundError'. Other errors should fail loudly so they are
not ignored.
[1] https://docs.python.org/3/library/subprocess.html#exceptions
[2] https://docs.python.org/3/library/exceptions.html#os-exceptions
CollinFrom 878c52bcf02018a9e85b19b796e85b067a486caf Mon Sep 17 00:00:00 2001
From: Collin Funk <[email protected]>
Date: Sat, 16 Mar 2024 11:47:05 -0700
Subject: [PATCH] gnulib-tool.py: Fix 'git update-index' call when using hard
links.
* pygnulib/main.py: Fix conditional used to check whether 'git
update-index' should be called. Only catch FileNotFoundError exceptions
thrown when no 'git' program exists.
---
ChangeLog | 7 +++++++
pygnulib/main.py | 8 ++++----
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 44ff5a5475..9f78456440 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-03-16 Collin Funk <[email protected]>
+
+ gnulib-tool.py: Fix 'git update-index' call when using hard links.
+ * pygnulib/main.py: Fix conditional used to check whether 'git
+ update-index' should be called. Only catch FileNotFoundError exceptions
+ thrown when no 'git' program exists.
+
2024-03-16 Collin Funk <[email protected]>
gnulib-tool.py: Coding style: Avoid not().
diff --git a/pygnulib/main.py b/pygnulib/main.py
index a3db7bb7c7..5d88d0115a 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -1279,7 +1279,7 @@ def main():
sys.stderr.write(message)
sys.exit(1)
- if copymode != classes.CopyAction.Copy or lcopymode != classes.CopyAction.Copy:
+ if copymode == classes.CopyAction.Hardlink or lcopymode == classes.CopyAction.Hardlink:
# Setting hard links modifies the ctime of files in the gnulib checkout.
# This disturbs the result of the next "gitk" invocation.
# Workaround: Let git scan the files. This can be done through
@@ -1287,9 +1287,9 @@ def main():
if isdir(joinpath(APP['root'], '.git')):
try:
sp.run(['git', 'update-index', '--refresh'],
- cwd=APP['root'], stdout=sp.DEVNULL, stderr=sp.DEVNULL)
- except Exception:
- # We did our best...
+ cwd=APP['root'], stdout=sp.DEVNULL)
+ except FileNotFoundError:
+ # No 'git' program was found.
pass
--
2.44.0