lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: python: fix installation of .py files when building in separate dir


From: jonas . hahnfeld
Subject: Re: python: fix installation of .py files when building in separate dir (issue 549810043 by address@hidden)
Date: Mon, 06 Apr 2020 14:11:30 -0700

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 0000000000..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 <module.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/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]