From cbe01131ddef31ff31bf31dbbe6d25c53171f248 Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Mon, 17 Jul 2023 19:47:04 +0100 Subject: [PATCH] Use _conf_data --- _conf_data.py.in | 2 ++ fract4d/fractconfig.py | 9 ++++++--- fract4d/options.py | 6 ++++-- meson.build | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 _conf_data.py.in diff --git a/_conf_data.py.in b/_conf_data.py.in new file mode 100644 index 000000000..664445a17 --- /dev/null +++ b/_conf_data.py.in @@ -0,0 +1,2 @@ +APP_DATADIR = "@app_datadir@" +VERSION = "@version@" diff --git a/fract4d/fractconfig.py b/fract4d/fractconfig.py index ff9a9d250..6a931944b 100644 --- a/fract4d/fractconfig.py +++ b/fract4d/fractconfig.py @@ -3,6 +3,11 @@ import os import sys +try: + from ._conf_data import APP_DATADIR +except ImportError: + APP_DATADIR = ".." + CONFIG_FILE = "~/.gnofract4d" @@ -132,9 +137,7 @@ def ensure_contains(self, section, required_item): def get_data_path(subpath=""): # find where data files are present. # use share path one level up from module location - moduledir = os.path.dirname(sys.modules[__name__].__file__) - path = os.path.normpath(os.path.join( - moduledir, "../../../../share/gnofract4d", subpath)) + path = os.path.join(APP_DATADIR, subpath) #print("Looking in %s" % path) return path diff --git a/fract4d/options.py b/fract4d/options.py index 197da3104..e37024d04 100644 --- a/fract4d/options.py +++ b/fract4d/options.py @@ -4,8 +4,10 @@ import sys from . import fractal as fract4d_fractal -# version of Gnofract 4D -VERSION = '4.3' +try: + from ._conf_data import VERSION +except ImportError: + VERSION = "dev" POSITION_ARGUMENTS = ("xcenter", "ycenter", "zcenter", "wcenter", "xyangle", "xzangle", "xwangle", "yzangle", "ywangle", "zwangle", diff --git a/meson.build b/meson.build index 9c67d29f2..399ebf7da 100644 --- a/meson.build +++ b/meson.build @@ -47,6 +47,16 @@ foreach p : packages ) endforeach +conf_data = configuration_data() +conf_data.set('app_datadir', get_option('prefix') / project_datadir) +conf_data.set('version', meson.project_version()) +conf_file = configure_file(input : '_conf_data.py.in', + output : '_conf_data.py', + configuration : conf_data, + install : true, + install_dir: py.get_install_dir() / 'fract4d', +) + # Application Data install_subdir('help', @@ -114,6 +124,14 @@ custom_target('cp_gresource', build_by_default : true, depends: gresource, ) +custom_target('cp_confdata', + command : [cp, + conf_file, + meson.project_source_root() / 'fract4d/', + ], + output : 'none3', + build_by_default : true, +) test('testing', find_program('pytest'),