Could not run generate_unaccent_rules.py script when update unicode
Japin Li <japinli@hotmail.com>
From: Japin Li <japinli@hotmail.com>
To: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2023-09-26T02:43:40Z
Lists: pgsql-hackers
Hi, hackers
When I try to update unicode mapping tables using make update-unicode [1],
I encountered an error about following:
generate_unaccent_rules.py --unicode-data-file ../../src/common/unicode/UnicodeData.txt --latin-ascii-file Latin-ASCII.xml >unaccent.rules
/bin/sh: 1: generate_unaccent_rules.py: not found
make: *** [Makefile:33: unaccent.rules] Error 127
make: *** Deleting file 'unaccent.rules'
The generate_unaccent_rules.py is in contrib/unaccent and the Makefile:
# Allow running this even without --with-python
PYTHON ?= python
$(srcdir)/unaccent.rules: generate_unaccent_rules.py ../../src/common/unicode/UnicodeData.txt Latin-ASCII.xml
$(PYTHON) $< --unicode-data-file $(word 2,$^) --latin-ascii-file $(word 3,$^) >$@
It use python to run generate_unaccent_rules.py, However, the ?= operator in
Makefile only check variable is defined or not, but do not check variable is
empty. Since the PYTHON is defined in src/Makefile.global, so here PYTHON
get empty when without --with-ptyhon.
Here are some examples:
japin@coltd-devel:~$ cat Makefile
PYTHON =
PYTHON ?= python
test:
echo '$(PYTHON)'
japin@coltd-devel:~$ make
echo ''
japin@coltd-devel:~$ cat Makefile
PYTHON = python3
PYTHON ?= python
test:
echo '$(PYTHON)'
japin@coltd-devel:~$ make
echo 'python3'
python3
japin@coltd-devel:~$ cat Makefile
PYTHON =
ifeq ($(PYTHON),)
PYTHON = python
endif
test:
echo '$(PYTHON)'
japin@coltd-devel:~$ make
echo 'python'
python
japin@coltd-devel:~$ cat Makefile
PYTHON = python3
ifeq ($(PYTHON),)
PYTHON = python
endif
test:
echo '$(PYTHON)'
japin@coltd-devel:~$ make
echo 'python3'
python3
Here is a patch to fix this, any thoughts?
diff --git a/contrib/unaccent/Makefile b/contrib/unaccent/Makefile
index 652a3e774c..3ff49ba1e9 100644
--- a/contrib/unaccent/Makefile
+++ b/contrib/unaccent/Makefile
@@ -26,7 +26,9 @@ endif
update-unicode: $(srcdir)/unaccent.rules
# Allow running this even without --with-python
-PYTHON ?= python
+ifeq ($(PYTHON),)
+PYTHON = python
+endif
$(srcdir)/unaccent.rules: generate_unaccent_rules.py ../../src/common/unicode/UnicodeData.txt Latin-ASCII.xml
$(PYTHON) $< --unicode-data-file $(word 2,$^) --latin-ascii-file $(word 3,$^) >$@
[1] https://www.postgresql.org/message-id/MEYP282MB1669AC78EE8374B3DE797A09B6FCA%40MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
--
Regrads,
Japin Li
ChengDu WenWu Information Technology Co., Ltd.
Commits
-
unaccent: Tweak value of PYTHON when building without Python support
- a64b8b03556a 13.13 landed
- e4d7ad30f0aa 14.10 landed
- 8a9e4e84e3cf 15.5 landed
- 641db601b72f 16.1 landed
- 6fc3a138b1e8 17.0 landed