Browse Source

Adjust more paths to local cbox

master
Nils 2 years ago
parent
commit
1c7d63f2fd
  1. 36
      template/calfbox/nullbox.py
  2. 16
      template/start.py

36
template/calfbox/nullbox.py

@ -1,18 +1,23 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import importlib
class NullCalfbox(str): #iterable
"""A drop-in replacement for calfboxs python module.
Use this for testing and development.
At the start of your program, first file, insert:
import nullbox
import prefix.calfbox.nullbox
or
from SOMETHING import nullbox
All further
from calfbox import cbox
from prefix.calfbox import cbox
will use the null module.
Even additional
import calfbox
import prefix.calfbox
will use the nullbox module.
"""
@ -55,13 +60,28 @@ class NullCalfbox(str): #iterable
import sys
import nullbox
#Hack 'from calfbox import cbox'
sys.modules["calfbox"] = sys.modules["nullbox"]
import calfbox
try:
import nullbox
except ModuleNotFoundError:
from . import nullbox
for key, value in sys.modules.items():
if "nullbox" in key:
r = key
break
else:
raise ValueError("Nullbox Module not found")
#r is the actual name of the calfbox parent modul. We cannot assume it to be "calfbox".
calfboxModuleName = r[:-len(".nullbox")] #remove suffix
sys.modules[calfboxModuleName] = sys.modules[r] #e.g. sys.modules["calfbox"] is now nullbox
#Hack 'from prefix.calfbox import cbox'
importlib.import_module(calfboxModuleName) #Imported once here, all modules will import this variant later.
#import calfbox
cbox = NullCalfbox("fake cbox null client")
#Hack direct call 'import cbox'
sys.modules["cbox"] = cbox
import cbox
import cbox #Imported once here, all modules will import this variant later.

16
template/start.py

@ -111,20 +111,11 @@ if compiledVersion:
"desktopfile": os.path.join(prefix, "share", "applications", METADATA["shortName"] + ".desktop"), # type: ignore #not ~/Desktop but our desktop file
"share": os.path.join(prefix, "share", METADATA["shortName"]), # type: ignore
"templateShare": os.path.join(prefix, "share", METADATA["shortName"], "template"), # type: ignore
#"lib": os.path.join(prefix, "lib", METADATA["shortName"]), #cbox is found via the PYTHONPATH
}
_root = os.path.dirname(__file__)
_root = os.path.abspath(os.path.join(_root, ".."))
import zipfile
import tempfile
logger.info("Extracting shared library to temporary directory")
zipfilePath = get_script_dir().rstrip("/template")
assert zipfile.is_zipfile(zipfilePath), (zipfilePath) #in our tests this worked. but in lss this results not in a zip file header. linux file also says it is no zip. However, unzip works.
#Extract included .so to tmp dir, tmp dir gets garbage collected at the end of our program.
libsharedDir = tempfile.TemporaryDirectory()
#Not compiled, not installed. Running pure python directly in the source tree.
else:
_root = os.path.dirname(__file__)
@ -136,7 +127,6 @@ else:
"desktopfile": os.path.join(_root, "desktop", "desktop.desktop"), #not ~/Desktop but our desktop file
"share": os.path.join(_root, "engine", "resources"),
"templateShare": os.path.join(_root, "template", "engine", "resources"),
#"lib": "", #use only system paths
}
logger.info("PATHS: {}".format(PATHS))
@ -326,13 +316,9 @@ if args.mute:
Needs adding of the local tree into python search path.
4) impossible: run program installed, calfbox in local tree
"""
#if not compiledVersion:
#import template.calfbox.py
# sys.modules["calfbox"] = sys.modules["template.calfbox.py"]
import template.calfbox.nullbox
logger.info(f"Using {sys.modules['template.calfbox']} as calfbox/nullbox")
else:
import ctypes.util
libname = ctypes.util.find_library("calfbox-lss") #returns something like 'libcalfbox-lss.so.1' without a path, but with "lib"

Loading…
Cancel
Save