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.
This commit is contained in:
James Westman 2022-06-07 11:45:23 -05:00
parent cebd9ecadc
commit 6f4d458855
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
3 changed files with 11 additions and 1 deletions

View file

@ -19,6 +19,13 @@
# #
# SPDX-License-Identifier: LGPL-3.0-or-later # 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 from blueprintcompiler import main
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -26,7 +26,7 @@ install_data(
meson.override_find_program('blueprint-compiler', find_program('blueprint-compiler.py')) meson.override_find_program('blueprint-compiler', find_program('blueprint-compiler.py'))
if not meson.is_subproject() if not meson.is_subproject()
install_subdir('blueprintcompiler', install_dir: py.get_install_dir()) install_subdir('blueprintcompiler', install_dir: datadir / 'blueprint-compiler')
endif endif
subdir('tests') subdir('tests')

View file

@ -1,5 +1,8 @@
import os, sys
from pythonfuzz.main import PythonFuzz from pythonfuzz.main import PythonFuzz
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from blueprintcompiler import tokenizer, parser, decompiler from blueprintcompiler import tokenizer, parser, decompiler
from blueprintcompiler.completions import complete from blueprintcompiler.completions import complete
from blueprintcompiler.errors import PrintableError, MultipleErrors, CompileError, CompilerBugError from blueprintcompiler.errors import PrintableError, MultipleErrors, CompileError, CompilerBugError