diff --git a/builder/builder-post-process.c b/builder/builder-post-process.c index f3e01af7..6b2efe59 100644 --- a/builder/builder-post-process.c +++ b/builder/builder-post-process.c @@ -197,7 +197,9 @@ fixup_python_time_stamp (const char *path, if (lstat (py_path, &stbuf) != 0) { - remove_pyc = TRUE; + /* pyc file without .py file, this happens for binary-only deployments. + * Accept it as-is. */ + return TRUE; } else if (pyc_mtime == OSTREE_TIMESTAMP) { diff --git a/tests/Makefile.am.inc b/tests/Makefile.am.inc index 19d76b96..d0ea77f8 100644 --- a/tests/Makefile.am.inc +++ b/tests/Makefile.am.inc @@ -98,6 +98,7 @@ dist_installed_test_data = \ tests/session.conf.in \ tests/0001-Add-test-logo.patch \ tests/org.test.Python.json \ + tests/org.test.Python2.json \ tests/importme.py \ tests/importme2.py \ $(NULL) diff --git a/tests/libtest.sh b/tests/libtest.sh index d0618f2b..bb26c4c7 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -215,8 +215,8 @@ setup_sdk_repo () { setup_python2_repo () { REPONAME=${1:-test} - GPGARGS="${GPGARGS:-${FL_GPGARGS}}" . $(dirname $0)/make-test-runtime.sh ${REPONAME} org.test.PythonPlatform bash python2 ls cat echo readlink > /dev/null - GPGARGS="${GPGARGS:-${FL_GPGARGS}}" . $(dirname $0)/make-test-runtime.sh ${REPONAME} org.test.PythonSdk python2 bash ls cat echo readlink make mkdir cp touch > /dev/null + GPGARGS="${GPGARGS:-${FL_GPGARGS}}" . $(dirname $0)/make-test-runtime.sh ${REPONAME} org.test.PythonPlatform bash python2 ls cat echo rm readlink > /dev/null + GPGARGS="${GPGARGS:-${FL_GPGARGS}}" . $(dirname $0)/make-test-runtime.sh ${REPONAME} org.test.PythonSdk python2 bash ls cat echo rm readlink make mkdir cp touch > /dev/null update_repo $REPONAME } diff --git a/tests/org.test.Python2.json b/tests/org.test.Python2.json new file mode 100644 index 00000000..bf4e1a0c --- /dev/null +++ b/tests/org.test.Python2.json @@ -0,0 +1,37 @@ +{ + "app-id": "org.test.Python2", + "runtime": "org.test.PythonPlatform", + "sdk": "org.test.PythonSdk", + "command": "testpython.py", + "modules": [ + { + "name": "compiled-python", + "post-install": [ + "mkdir /app/bin", + "cp testpython.py /app/bin", + "cp importme.py /app/bin", + /* Compile importme.py */ + "/app/bin/testpython.py", + /* Remove .py file, but keep .pyc */ + "rm /app/bin/importme.py", + /* Make sure it still works */ + "/app/bin/testpython.py" + ], + "sources": [ + { + "type": "file", + "path": "empty-configure", + "dest-filename": "configure" + }, + { + "type": "file", + "path": "testpython.py" + }, + { + "type": "file", + "path": "importme.py" + } + ] + } + ] +} diff --git a/tests/test-builder-python.sh b/tests/test-builder-python.sh index 1223b430..6d6beedb 100755 --- a/tests/test-builder-python.sh +++ b/tests/test-builder-python.sh @@ -25,7 +25,7 @@ skip_without_bwrap skip_without_user_xattrs skip_without_python2 -echo "1..1" +echo "1..2" setup_repo install_repo @@ -37,6 +37,7 @@ REPO=`pwd`/repo cd $TEST_DATA_DIR/ cp $(dirname $0)/org.test.Python.json . +cp $(dirname $0)/org.test.Python2.json . cp -a $(dirname $0)/empty-configure . cp -a $(dirname $0)/testpython.py . cp $(dirname $0)/importme.py . @@ -51,3 +52,14 @@ flatpak-builder --run appdir org.test.Python.json testpython.py > testpython.out assert_file_has_content testpython.out ^modified$ echo "ok handled pyc rewriting multiple times" + +flatpak-builder --force-clean appdir org.test.Python2.json + +assert_not_has_file appdir/files/bin/importme.py +assert_has_file appdir/files/bin/importme.pyc + +flatpak-builder --run appdir org.test.Python2.json testpython.py > testpython.out + +assert_file_has_content testpython.out "^first $" + +echo "ok handled .pyc without .py"