From f5c74740e18de603aa964af4e4ba2bb9b1d9767e Mon Sep 17 00:00:00 2001 From: Riccardo Di Virgilio Date: Tue, 28 Nov 2023 16:28:29 +0100 Subject: [PATCH 1/4] fixing initfile --- .../evaluation/kernel/kernelcontroller.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/wolframclient/evaluation/kernel/kernelcontroller.py b/wolframclient/evaluation/kernel/kernelcontroller.py index 47ee65a8..d657592b 100644 --- a/wolframclient/evaluation/kernel/kernelcontroller.py +++ b/wolframclient/evaluation/kernel/kernelcontroller.py @@ -7,7 +7,6 @@ from subprocess import PIPE, Popen from threading import Event, RLock, Thread -from wolframclient.utils.environment import find_default_kernel_path from wolframclient.evaluation.kernel.zmqsocket import ( Socket, SocketAborted, @@ -17,6 +16,8 @@ from wolframclient.exception import WolframKernelException from wolframclient.utils import six from wolframclient.utils.api import json, os, time, zmq +from wolframclient.utils.environment import find_default_kernel_path +from wolframclient.utils.functional import iterate if six.WINDOWS: from subprocess import STARTF_USESHOWWINDOW, STARTUPINFO @@ -130,12 +131,13 @@ def __init__( "Cannot locate a kernel automatically. Please provide an explicit kernel path." ) - if initfile is None: - self.initfile = os.path_join(os.dirname(__file__), "initkernel.m") - else: - self.initfile = initfile - if not os.isfile(self.initfile): - raise FileNotFoundError("Kernel initialization file %s not found." % self.initfile) + self.initfile = tuple( + iterate(initfile or (), os.path_join(os.dirname(__file__), "initkernel.m")) + ) + for path in self.initfile: + if not os.isfile(path): + raise FileNotFoundError("Kernel initialization file %s not found." % path) + if logger.isEnabledFor(logging.DEBUG): logger.debug( "Initializing kernel %s using script: %s" % (self.kernel, self.initfile) @@ -384,7 +386,12 @@ def _kernel_start(self): "Kernel receives evaluated expressions from socket: %s", self.kernel_socket_in ) # start the kernel process - cmd = [self.kernel, "-noprompt", "-initfile", self.initfile] + cmd = [self.kernel, "-noprompt"] + + for path in self.initfile: + cmd.append('-initfile') + cmd.append(path) + if self.loglevel != logging.NOTSET: self.kernel_logger = KernelLogger( name="wolfram-kernel-logger-%i" % self.id, level=self.loglevel From cb3d2e87605613464cf15f1a03fde5d66b467f11 Mon Sep 17 00:00:00 2001 From: Riccardo Di Virgilio Date: Tue, 28 Nov 2023 16:29:32 +0100 Subject: [PATCH 2/4] code lint --- wolframclient/cli/commands/start_externalevaluate.py | 5 ++++- wolframclient/evaluation/kernel/kernelcontroller.py | 2 +- wolframclient/serializers/base.py | 5 +++-- wolframclient/serializers/encoder.py | 2 +- wolframclient/tests/externalevaluate/ev_loop.py | 1 - wolframclient/tests/serializers/wxf_numpy.py | 2 +- wolframclient/utils/environment.py | 11 ++++------- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/wolframclient/cli/commands/start_externalevaluate.py b/wolframclient/cli/commands/start_externalevaluate.py index a9897afb..288d65d0 100644 --- a/wolframclient/cli/commands/start_externalevaluate.py +++ b/wolframclient/cli/commands/start_externalevaluate.py @@ -19,7 +19,10 @@ def add_arguments(self, parser): def handle(self, port=None, installpath=None, kernelversion=None, **opts): - for key, value in (("WOLFRAM_INSTALLATION_DIRECTORY", installpath), ("WOLFRAM_KERNEL_VERSION", kernelversion)): + for key, value in ( + ("WOLFRAM_INSTALLATION_DIRECTORY", installpath), + ("WOLFRAM_KERNEL_VERSION", kernelversion), + ): if value: os.environ[key] = value diff --git a/wolframclient/evaluation/kernel/kernelcontroller.py b/wolframclient/evaluation/kernel/kernelcontroller.py index d657592b..482bb7e7 100644 --- a/wolframclient/evaluation/kernel/kernelcontroller.py +++ b/wolframclient/evaluation/kernel/kernelcontroller.py @@ -389,7 +389,7 @@ def _kernel_start(self): cmd = [self.kernel, "-noprompt"] for path in self.initfile: - cmd.append('-initfile') + cmd.append("-initfile") cmd.append(path) if self.loglevel != logging.NOTSET: diff --git a/wolframclient/serializers/base.py b/wolframclient/serializers/base.py index c7aae45d..a48f1ed8 100644 --- a/wolframclient/serializers/base.py +++ b/wolframclient/serializers/base.py @@ -15,11 +15,12 @@ from wolframclient.utils.encoding import concatenate_bytes, force_text from wolframclient.utils.functional import first -if hasattr(inspect, 'getfullargspec'): +if hasattr(inspect, "getfullargspec"): inspect_args = inspect.getfullargspec -elif hasattr(inspect, 'getargspec'): +elif hasattr(inspect, "getargspec"): inspect_args = inspect.getargspec else: + def inspect_args(f): raise TypeError() diff --git a/wolframclient/serializers/encoder.py b/wolframclient/serializers/encoder.py index 2c673959..bd6c6cc6 100644 --- a/wolframclient/serializers/encoder.py +++ b/wolframclient/serializers/encoder.py @@ -5,10 +5,10 @@ from collections import defaultdict from functools import partial -from wolframclient.utils.environment import installation_version from wolframclient.serializers.utils import safe_len from wolframclient.utils.api import multiprocessing, pkg_resources from wolframclient.utils.dispatch import Dispatch +from wolframclient.utils.environment import installation_version from wolframclient.utils.functional import composition, is_iterable, iterate, map from wolframclient.utils.importutils import safe_import_string diff --git a/wolframclient/tests/externalevaluate/ev_loop.py b/wolframclient/tests/externalevaluate/ev_loop.py index b25c44ea..11ced7ae 100644 --- a/wolframclient/tests/externalevaluate/ev_loop.py +++ b/wolframclient/tests/externalevaluate/ev_loop.py @@ -3,7 +3,6 @@ from threading import Thread import zmq - from wolframclient.language import wl from wolframclient.serializers import export from wolframclient.utils.externalevaluate import EXPORT_KWARGS, start_zmq_loop diff --git a/wolframclient/tests/serializers/wxf_numpy.py b/wolframclient/tests/serializers/wxf_numpy.py index 3e04a992..4c6f0773 100644 --- a/wolframclient/tests/serializers/wxf_numpy.py +++ b/wolframclient/tests/serializers/wxf_numpy.py @@ -228,7 +228,7 @@ def test_scalars(self): for arr, result in ( (numpy.array(1, dtype=numpy.int8), b"1"), (numpy.array(0.5, dtype=numpy.float32), b"0.5"), - ): + ): self.assertEqual(export(arr), result) def test_bad_options(self): diff --git a/wolframclient/utils/environment.py b/wolframclient/utils/environment.py index 1efb3757..ea49eaad 100644 --- a/wolframclient/utils/environment.py +++ b/wolframclient/utils/environment.py @@ -3,17 +3,16 @@ from wolframclient.utils import six from wolframclient.utils.api import os -from wolframclient.utils import six -from wolframclient.utils.api import os def installation_version(): - v = os.environ.get('WOLFRAM_KERNEL_VERSION', None) + v = os.environ.get("WOLFRAM_KERNEL_VERSION", None) if v: return float(v) return 12.0 + def _explore_paths(*paths): highest_version = -1 best_path = None @@ -60,17 +59,15 @@ def _installation_directories(): yield "/Applications/Wolfram Engine.app/Contents" - def find_default_kernel_path(): """ Look for the most recent installed kernel. """ if six.WINDOWS: rel = "WolframKernel.exe" elif six.LINUX: - rel = "Executables/WolframKernel" + rel = "Executables/WolframKernel" elif six.MACOS: - rel = "MacOS/WolframKernel" - + rel = "MacOS/WolframKernel" for path in _installation_directories(): if rel: From 8e290d4f5968144624f92ed22f40add347028952 Mon Sep 17 00:00:00 2001 From: Riccardo Di Virgilio Date: Tue, 28 Nov 2023 16:30:09 +0100 Subject: [PATCH 3/4] add comment --- wolframclient/cli/commands/refactor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wolframclient/cli/commands/refactor.py b/wolframclient/cli/commands/refactor.py index 0f410c78..6acb8c52 100644 --- a/wolframclient/cli/commands/refactor.py +++ b/wolframclient/cli/commands/refactor.py @@ -10,7 +10,8 @@ class Command(SimpleCommand): modules = ["wolframclient"] - dependencies = (("isort", "5.3.2"), ("autoflake", "1.3"), ("black", "19.3b0")) + #dependencies = (("isort", "5.3.2"), ("autoflake", "1.3"), ("black", "19.3b0")) + #dependencies is broken please install isort==5.3.2 autoflake==1.3 black==19.3b0" def _module_args(self, *args): From 8244d8c51a13f9578b60d50a978cb8a0c58c7f7d Mon Sep 17 00:00:00 2001 From: Riccardo Di Virgilio Date: Tue, 28 Nov 2023 16:32:00 +0100 Subject: [PATCH 4/4] bump version --- wolframclient/about.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolframclient/about.py b/wolframclient/about.py index 0395ec63..568b5f20 100644 --- a/wolframclient/about.py +++ b/wolframclient/about.py @@ -2,6 +2,6 @@ __name__ = "wolframclient" __description__ = "A Python library with various tools to interact with the Wolfram Language and the Wolfram Cloud." -__version__ = "1.1.9" +__version__ = "1.1.10" __author__ = "Wolfram Research" __author_email__ = "support@wolfram.com, dorianb@wolfram.com, riccardod@wolfram.com"