Skip to content

Commit

Permalink
Pull request #258: Bugfix/github issue 10
Browse files Browse the repository at this point in the history
Merge in LCL/wolframclientforpython from bugfix/github-issue-10 to master

* commit '8244d8c51a13f9578b60d50a978cb8a0c58c7f7d':
  bump version
  add comment
  code lint
  fixing initfile
  • Loading branch information
crazyeng committed Nov 28, 2023
2 parents 51939b8 + 8244d8c commit 681c91f
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion wolframclient/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion wolframclient/cli/commands/refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
5 changes: 4 additions & 1 deletion wolframclient/cli/commands/start_externalevaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 15 additions & 8 deletions wolframclient/evaluation/kernel/kernelcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions wolframclient/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion wolframclient/serializers/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion wolframclient/tests/externalevaluate/ev_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wolframclient/tests/serializers/wxf_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 4 additions & 7 deletions wolframclient/utils/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 681c91f

Please sign in to comment.