From 9754a2a7584e48f2501de95a83c02c1032afe02e Mon Sep 17 00:00:00 2001 From: Liam Marsh Date: Wed, 19 Jun 2024 18:08:14 +0200 Subject: [PATCH] packaging: add help importing qstack_qml in __init__ --- qstack/__init__.py | 5 +++++ qstack/qml.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 qstack/qml.py diff --git a/qstack/__init__.py b/qstack/__init__.py index 71bb664..f9e7bb9 100644 --- a/qstack/__init__.py +++ b/qstack/__init__.py @@ -8,7 +8,12 @@ from qstack import spahm from qstack import mathutils from qstack import orcaio +from qstack import qml +if 'b2r2' not in dir(qml): + del qml + +# qstack.regression needs sklearn to work try: import sklearn except ImportError: diff --git a/qstack/qml.py b/qstack/qml.py new file mode 100644 index 0000000..3448825 --- /dev/null +++ b/qstack/qml.py @@ -0,0 +1,16 @@ +# qstack.qml is in a different python package +# but prefer "the local version of it" if we are in a development environment, and both sources are there. +import os +_qstack_qml_path = os.path.join(os.path.dirname(__file__), 'qstack-qml') +if os.path.isfile(os.path.join(_qstack_qml_path, 'qstack_qml', '__init__.py')): + import sys + sys.path.insert(0,_qstack_qml_path) + from qstack_qml import * + sys.path.pop(0) + del sys +else: + try: + from qstack_qml import * + except ImportError: + pass +del os, _qstack_qml_path