From f2b5e0f62ede8900ada3841b0a462a13dceeb23e Mon Sep 17 00:00:00 2001 From: RibomBalt Date: Sat, 7 May 2022 17:30:25 +0800 Subject: [PATCH] handle python executable when building wheels --- setup.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 3967ba1..452985a 100644 --- a/setup.py +++ b/setup.py @@ -12,19 +12,28 @@ break DISTNAME = 'matlab_kernel' +PY_EXECUTABLE = 'python' + +# when building wheels, directly use 'python' in the kernelspec. +if any(a.startswith("bdist") for a in sys.argv): + PY_EXECUTABLE = 'python' + +# when directly installing, use sys.executable to get python full path. +if any(a.startswith("install") for a in sys.argv): + PY_EXECUTABLE = sys.executable # generating kernel.json for both kernels os.makedirs(os.path.join(DISTNAME, 'matlab'), exist_ok=True) with open(os.path.join(DISTNAME, 'kernel_template.json'), 'r') as fp: matlab_json = json.load(fp) -matlab_json['argv'][0] = sys.executable +matlab_json['argv'][0] = PY_EXECUTABLE with open(os.path.join(DISTNAME, 'matlab','kernel.json'), 'w') as fp: json.dump(matlab_json, fp) os.makedirs(os.path.join(DISTNAME, 'matlab_connect'), exist_ok=True) with open(os.path.join(DISTNAME, 'kernel_template.json'), 'r') as fp: matlab_json = json.load(fp) -matlab_json['argv'][0] = sys.executable +matlab_json['argv'][0] = PY_EXECUTABLE matlab_json['display_name'] = 'Matlab (Connection)' matlab_json['name'] = "matlab_connect" matlab_json['env'] = {'connect-to-existing-kernel': '1'}