From 6f4d45885505f600656c2c246e8bad9088e288a7 Mon Sep 17 00:00:00 2001 From: James Westman Date: Tue, 7 Jun 2022 11:45:23 -0500 Subject: [PATCH] build: Install to datadir Install the python module to the data directory, not the python install directory that meson gives us. Then, in the main script, try to find the module and add it to the path by assuming the script is installed to (prefix)/bin. Hopefully this will fix the ModuleNotFound errors. --- blueprint-compiler.py | 7 +++++++ meson.build | 2 +- tests/fuzz.py | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/blueprint-compiler.py b/blueprint-compiler.py index 1b9f393..91a8dde 100755 --- a/blueprint-compiler.py +++ b/blueprint-compiler.py @@ -19,6 +19,13 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later +import os, sys + +# Try to find the python module, assuming the current file is installed to (prefix)/bin +dirname = os.path.join(os.path.dirname(os.path.dirname(__file__)), "share", "blueprint-compiler") +if os.path.isdir(os.path.join(dirname, "blueprintcompiler")): + sys.path.insert(0, dirname) + from blueprintcompiler import main if __name__ == "__main__": diff --git a/meson.build b/meson.build index 71b2334..1cba9b0 100644 --- a/meson.build +++ b/meson.build @@ -26,7 +26,7 @@ install_data( meson.override_find_program('blueprint-compiler', find_program('blueprint-compiler.py')) if not meson.is_subproject() - install_subdir('blueprintcompiler', install_dir: py.get_install_dir()) + install_subdir('blueprintcompiler', install_dir: datadir / 'blueprint-compiler') endif subdir('tests') diff --git a/tests/fuzz.py b/tests/fuzz.py index c68d7d7..17f2eeb 100644 --- a/tests/fuzz.py +++ b/tests/fuzz.py @@ -1,5 +1,8 @@ +import os, sys from pythonfuzz.main import PythonFuzz +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) + from blueprintcompiler import tokenizer, parser, decompiler from blueprintcompiler.completions import complete from blueprintcompiler.errors import PrintableError, MultipleErrors, CompileError, CompilerBugError