Browse Source

adjust paths to local cbox

master
Nils 3 years ago
parent
commit
a09601639d
  1. 2
      engine/api.py
  2. 4
      engine/input_apcmini.py
  3. 4
      engine/main.py
  4. 5
      engine/pattern.py
  5. 36
      template/calfbox/nullbox.py
  6. 16
      template/start.py

2
engine/api.py

@ -26,7 +26,7 @@ import logging; logger = logging.getLogger(__name__); logger.info("import")
from typing import List, Set, Dict, Tuple
#Third Party Modules
from calfbox import cbox
from template.calfbox import cbox
#Template Modules
import template.engine.api #we need direct access to the module to inject data in the provided structures. but we also need the functions directly. next line:

4
engine/input_apcmini.py

@ -25,10 +25,8 @@ import logging; logging.info("import {}".format(__file__))
#Python Standard Library
import atexit
#Third Party Modules
from calfbox import cbox
#Template Modules
from template.calfbox import cbox
from template.engine.input_midi import MidiInput
#Our Modules

4
engine/main.py

@ -23,10 +23,8 @@ import logging; logger = logging.getLogger(__name__); logger.info("import")
#Standard Library Modules
#Third Party Modules
from calfbox import cbox
#Template Modules
from template.calfbox import cbox
from template.engine.data import Data as TemplateData
import template.engine.sequencer
from template.engine.sequencer import SequencerInterface #group tracks

5
engine/pattern.py

@ -26,8 +26,8 @@ from typing import List, Set, Dict, Tuple
from warnings import warn
from statistics import median
#Third Party Modules
from calfbox import cbox
#Template Modules
from template.calfbox import cbox
DEFAULT_VELOCITY = 90
@ -426,4 +426,3 @@ class Pattern(object):
return self
#No export. Track uses pattern data directly in its own export.

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