Skip to content

Commit 542948a

Browse files
committed
Ver(1.6): Fix findLibary function (won't work on Linux)
1 parent 7583fc4 commit 542948a

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

hachiko_bapu/funutils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ def flatMap(f, xs):
2323
for ys in map(f, xs):
2424
for y in ys: yield y
2525

26+
def takePipeIf(p, transform, value):
27+
res = transform(value)
28+
return res if p(res) else value
29+
2630
def findLibrary(name, lib_names, solver=lambda name: [f"./{name}.dll"]) -> str:
2731
paths = filter(isNotNone, map(find_library, lib_names))
2832
for dlls in map(solver, lib_names):
2933
paths = chain(paths, filter(isfile, dlls))
3034

3135
path = next(paths, None) #< appended dll scan
3236
if path == None: raise ImportError(f"couldn't find the {name} library")
33-
else: return abspath(str(path))
37+
else: return takePipeIf(isfile, abspath, str(path)) #< only if found file, not libname in PATH
3438

3539
def createLibrary(path, mode = 1):
3640
lib = CDLL(path)

hachiko_bapu/hachi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from .hachitools import *
1616
from .synthesize import NoteSynth
17+
from pkg_resources import resource_filename
1718

1819
def splitAs(type, transform = int, delim = ","):
1920
return lambda it: type(transform(s) for s in it.split(delim))
@@ -27,7 +28,7 @@ def splitAs(type, transform = int, delim = ","):
2728
askMethod = env("ASK_METHOD", str, "tk")
2829
playDuration = env("PLAY_DURATION", splitAs(list, transform=float), [0.3, 0.5, 1.5])
2930

30-
INSTRUMENT_SF2 = env("SFONT", str, resourcePath("instrument.sf2"))
31+
INSTRUMENT_SF2 = env("SFONT", str, resource_filename(__name__, "instrument.sf2"))
3132
sampleRate = env("SAMPLE_RATE", int, 44100)
3233
sfontPreset = 0 #< used twice
3334

hachiko_bapu/hachitools.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from threading import Timer
44
from os import environ
5-
from pkg_resources import resource_filename
65

76
SEC_MS = 1000
87

@@ -11,10 +10,6 @@ def grayColor(n:int): return (n,n,n)
1110
def env(name:str, transform:Callable[[str],T], default:T) -> T:
1211
return transform(environ[name]) if name in environ else default
1312

14-
def resourcePath(path) -> str:
15-
try: return resource_filename(__name__, path)
16-
except ModuleNotFoundError: return path
17-
1813
def timeout(n_sec:float, op):
1914
timer = Timer(n_sec, op); timer.start()
2015
return timer

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def parse_requirements(requirements):
99
return list(filter(lambda s: s.strip() != "", items))
1010

1111
setup(
12-
name="hachiko-bapu", version="0.1.5",
12+
name="hachiko-bapu", version="0.1.6",
1313
python_requires=">=3.5",
1414
author="duangsuse", author_email="[email protected]",
1515
url="https://github.com/duangsuse-valid-projects/Hachiko",

0 commit comments

Comments
 (0)