Re: python: fix installation of .py files when building in separate dir (issue 549810043 by hanw...@gmail.com)

2020-04-09 Thread hanwenn


commit 2fc91caabe6adb61c89915f659e35f3ec8ba5c62 (py-install)
Author: Han-Wen Nienhuys 
Date:   Sun Apr 5 23:07:56 2020 +0200


https://codereview.appspot.com/549810043/



Re: python: fix installation of .py files when building in separate dir (issue 549810043 by hanw...@gmail.com)

2020-04-08 Thread Han-Wen Nienhuys
On Tue, Apr 7, 2020 at 9:44 PM  wrote:
>
> LGTM. I think you should push this unblock 2.21.0
>
> https://codereview.appspot.com/549810043/

Ack. Pushed.


-- 
Han-Wen Nienhuys - hanw...@gmail.com - http://www.xs4all.nl/~hanwen



Re: python: fix installation of .py files when building in separate dir (issue 549810043 by hanw...@gmail.com)

2020-04-07 Thread jonas . hahnfeld
LGTM. I think you should push this unblock 2.21.0

https://codereview.appspot.com/549810043/



Re: python: fix installation of .py files when building in separate dir (issue 549810043 by hanw...@gmail.com)

2020-04-07 Thread jonas . hahnfeld


https://codereview.appspot.com/549810043/diff/567420043/python/GNUmakefile
File python/GNUmakefile (right):

https://codereview.appspot.com/549810043/diff/567420043/python/GNUmakefile#newcode20
python/GNUmakefile:20: INSTALLATION_OUT_SUFFIXES = 2
please drop entirely

https://codereview.appspot.com/549810043/diff/567420043/python/GNUmakefile#newcode26
python/GNUmakefile:26: INSTALLATION_OUT_FILES2 = $(wildcard
$(outdir)/__pycache__/*.pyc)
Can be INSTALLATION_OUT_DIR and INSTALLATION_OUT_FILES without suffix

https://codereview.appspot.com/549810043/diff/567420043/python/GNUmakefile#newcode29
python/GNUmakefile:29: $(PYTHON) -B $<
I'd propose to leave this out of the patch for now and address this
after releasing 2.21.0

https://codereview.appspot.com/549810043/



Re: python: fix installation of .py files when building in separate dir (issue 549810043 by hanw...@gmail.com)

2020-04-06 Thread jonas . hahnfeld
I could probably be happy with the following:
diff --git a/make/lilypond-vars.make b/make/lilypond-vars.make
index 3f1e992626..3ac59f19a4 100644
--- a/make/lilypond-vars.make
+++ b/make/lilypond-vars.make
@@ -18,6 +18,8 @@ endif
 LANGS=$(shell $(PYTHON) $(top-src-dir)/python/langdefs.py)
 
 export PYTHONPATH:=$(top-src-dir)/python:$(PYTHONPATH)
+# Don't create __pycache__ in the source directory.
+export PYTHONDONTWRITEBYTECODE=1
 
 the-script-dir=$(wildcard $(script-dir))
 
diff --git a/python/GNUmakefile b/python/GNUmakefile
index b541206df3..efe9329038 100644
--- a/python/GNUmakefile
+++ b/python/GNUmakefile
@@ -2,7 +2,7 @@ depth = ..
 
 SUBDIRS=auxiliar
 
-STEPMAKE_TEMPLATES=install-out po
+STEPMAKE_TEMPLATES=install-out install po
 
 PY_MODULES_IN = $(call src-wildcard,*.py)
 OUT_PY_MODULES = $(PY_MODULES_IN:%=$(outdir)/%)
@@ -17,13 +17,11 @@ $(outdir)/%.py: %.py
 
 default: $(OUT_PY_MODULES)
 
-INSTALLATION_OUT_SUFFIXES = 1 2
+INSTALLATION_DIR = $(local_lilypond_datadir)/python
+INSTALLATION_FILES = $(filter-out $(call src-wildcard, *_test.py),
$(PY_MODULES_IN))
 
-INSTALLATION_OUT_DIR1=$(local_lilypond_datadir)/python
-INSTALLATION_OUT_FILES1=$(PY_MODULES_IN)
-
-INSTALLATION_OUT_DIR2 = $(local_lilypond_datadir)/python/__pycache__
-INSTALLATION_OUT_FILES2 = $(wildcard $(outdir)/__pycache__/*.pyc)
+INSTALLATION_OUT_DIR = $(local_lilypond_datadir)/python/__pycache__
+INSTALLATION_OUT_FILES = $(wildcard $(outdir)/__pycache__/*.pyc)
 
 local-test: book_base_test.py
$(PYTHON) $<

Afterwards I can submit a change to avoid copying the .py files over and
have them only in the source directory:
diff --git a/python/GNUmakefile b/python/GNUmakefile
index efe9329038..731fadb8e5 100644
--- a/python/GNUmakefile
+++ b/python/GNUmakefile
@@ -5,17 +5,16 @@ SUBDIRS=auxiliar
 STEPMAKE_TEMPLATES=install-out install po
 
 PY_MODULES_IN = $(call src-wildcard,*.py)
-OUT_PY_MODULES = $(PY_MODULES_IN:%=$(outdir)/%)
 
 include $(depth)/make/stepmake.make
 
-$(outdir)/%.py: %.py
+$(outdir)/%.pyc.dummy: %.py
$(call ly_progress,Making,$@,(py compile))
-   cp $< $@
-   PYTHONOPTIMIZE= $(PYTHON) -c 'import py_compile;
py_compile.compile ("$@", doraise=True)'
-   chmod 755 $@
+   # Do not use buildscript-dir, this has not been traversed yet.
+   $(PYTHON) $(top-src-dir)/scripts/build/compile.py $<
+   touch $@
 
-default: $(OUT_PY_MODULES)
+default: $(PY_MODULES_IN:%.py=$(outdir)/%.pyc.dummy)
 
 INSTALLATION_DIR = $(local_lilypond_datadir)/python
 INSTALLATION_FILES = $(filter-out $(call src-wildcard, *_test.py),
$(PY_MODULES_IN))
diff --git a/scripts/build/compile.py b/scripts/build/compile.py
new file mode 100644
index 00..294abbaf4a
--- /dev/null
+++ b/scripts/build/compile.py
@@ -0,0 +1,14 @@
+#!@PYTHON@
+
+from importlib.util import cache_from_source
+from os.path import basename
+import py_compile
+import sys
+
+if len (sys.argv) != 2:
+print ('Usage: compile.py ')
+sys.exit (1)
+
+src = sys.argv[1]
+cfile = cache_from_source (basename(src))
+py_compile.compile (src, cfile=cfile, doraise=True)

https://codereview.appspot.com/549810043/



Re: python: fix installation of .py files when building in separate dir (issue 549810043 by hanw...@gmail.com)

2020-04-06 Thread jonas . hahnfeld
On 2020/04/06 19:51:11, hanwenn wrote:
> suppress __pycache__

The suppression only works for the test. Running a full build still
gives me python/__pycache__/ in the source directory because PYTHONPATH
points there.

https://codereview.appspot.com/549810043/



python: fix installation of .py files when building in separate dir (issue 549810043 by hanw...@gmail.com)

2020-04-05 Thread jonas . hahnfeld
I think we should rather do https://codereview.appspot.com/575960043

https://codereview.appspot.com/549810043/