From 29f7821ff5a7b1674b2f5bba15597755e70bcdac Mon Sep 17 00:00:00 2001 From: Benjamin Hugo Date: Wed, 6 Jan 2021 06:52:44 +0200 Subject: [PATCH] Issue tiggerlsm19 (#64) * Fixes astropy error and disentangles qt4 from pipeliner - fixes tigger-lsm#19 - disentangles pipeliner from qt4 * Default build system is now py3 --- .travis/py2.docker | 8 ++++---- .travis/py3.docker | 25 +++++++++++------------ CMakeLists.txt | 2 +- PyApps/src/Apps/QObject.py | 8 ++++---- PyApps/src/Apps/meqserver.py | 3 +-- PyApps/src/Apps/multiapp_proxy.py | 17 +++++++++------- PyApps/src/Meq/meq.py | 1 - PyApps/src/Meq/meqds.py | 5 +++-- PyApps/src/TDL/Compile.py | 33 ++++++++++++++++++++++++------- PyApps/src/TDL/TDLOptions.py | 12 +++++++---- 10 files changed, 69 insertions(+), 45 deletions(-) diff --git a/.travis/py2.docker b/.travis/py2.docker index bc1ea6213..ba17686c5 100644 --- a/.travis/py2.docker +++ b/.travis/py2.docker @@ -80,16 +80,16 @@ RUN pip install meqtrees-cattery astro-kittens purr astro-tigger-lsm owlcat Pyth ADD . /code RUN mkdir /code/build WORKDIR /code/build -RUN cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release ../ +RUN cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DENABLE_PYTHON_3=OFF ../ RUN make -j4 RUN make install RUN ldconfig # get the test from pyxis WORKDIR /code -RUN wget https://github.com/ska-sa/pyxis/archive/v1.7.0.tar.gz -RUN tar -xvf v1.7.0.tar.gz -WORKDIR /code/pyxis-1.7.0 +RUN wget https://github.com/ska-sa/pyxis/archive/v1.7.1.tar.gz +RUN tar -xvf v1.7.1.tar.gz +WORKDIR /code/pyxis-1.7.1 RUN pip install -U . RUN flag-ms.py --help RUN meqtree-pipeliner.py --help diff --git a/.travis/py3.docker b/.travis/py3.docker index ed385646e..9d1256b24 100644 --- a/.travis/py3.docker +++ b/.travis/py3.docker @@ -11,20 +11,19 @@ RUN docker-apt-install libblitz0-dev python3-dev libblas-dev liblapack-dev libqd ##################################################################### RUN mkdir /src WORKDIR /src -RUN wget https://github.com/casacore/casacore/archive/v3.2.1.tar.gz -RUN tar xvf v3.2.1.tar.gz -RUN mkdir casacore-3.2.1/build -WORKDIR /src/casacore-3.2.1/build -RUN echo hello +RUN wget https://github.com/casacore/casacore/archive/v3.3.0.tar.gz +RUN tar xvf v3.3.0.tar.gz +RUN mkdir casacore-3.3.0/build +WORKDIR /src/casacore-3.3.0/build RUN cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DBUILD_DEPRECATED=ON -DBUILD_PYTHON3=ON -DBUILD_PYTHON=OFF ../ RUN make -j 4 RUN make install RUN ldconfig #RUN pip install -U --user --force-reinstall --install-option="--prefix=/usr" pip setuptools wheel WORKDIR /src -RUN wget https://github.com/casacore/python-casacore/archive/v3.2.0.tar.gz -RUN tar xvf v3.2.0.tar.gz -WORKDIR /src/python-casacore-3.2.0 +RUN wget https://github.com/casacore/python-casacore/archive/v3.3.0.tar.gz +RUN tar xvf v3.3.0.tar.gz.1 +WORKDIR /src/python-casacore-3.3.0 RUN pip3 install . WORKDIR / RUN python3 -c "from pyrap.tables import table as tbl" @@ -61,11 +60,11 @@ RUN makems WSRT_makems.cfg ##################################################################### WORKDIR /src RUN docker-apt-install git -RUN wget https://github.com/Athanaseus/casarest/archive/1.6.0.tar.gz -RUN tar xvf 1.6.0.tar.gz -WORKDIR /src/casarest-1.6.0 +RUN wget https://github.com/casacore/casarest/archive/v1.7.0.tar.gz +RUN tar xvf v1.7.0.tar.gz +WORKDIR /src/casarest-1.7.0 RUN mkdir -p build -WORKDIR /src/casarest-1.6.0/build +WORKDIR /src/casarest-1.7.0/build RUN cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release ../ RUN make -j 4 RUN make install @@ -80,7 +79,7 @@ RUN git clone -b v1.5.0 https://github.com/ska-sa/purr.git RUN git clone -b v1.6.2 https://github.com/ska-sa/owlcat.git RUN git clone -b v1.4.3 https://github.com/ska-sa/kittens.git RUN git clone -b v1.6.0 https://github.com/ska-sa/tigger-lsm.git -RUN git clone -b v1.7.0 https://github.com/ska-sa/pyxis.git +RUN git clone -b v1.7.1 https://github.com/ska-sa/pyxis.git RUN pip3 install ./meqtrees-cattery ./purr ./owlcat ./kittens ./tigger-lsm RUN pip3 install -e ./pyxis diff --git a/CMakeLists.txt b/CMakeLists.txt index c60197668..6916ea6c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake) include(cmake/meqmacros.cmake) include(cmake/mequtils.cmake) -option(ENABLE_PYTHON_3 "Enables support for Python 3.x" OFF) +option(ENABLE_PYTHON_3 "Enables support for Python 3.x" ON) if ("${ENABLE_PYTHON_3}") message("-- Compiling backend against Python 3.x") set(PYREQ_VER 3.0) diff --git a/PyApps/src/Apps/QObject.py b/PyApps/src/Apps/QObject.py index 905507a3d..0dd44ad72 100644 --- a/PyApps/src/Apps/QObject.py +++ b/PyApps/src/Apps/QObject.py @@ -36,26 +36,26 @@ def PYSIGNAL (sig): class QObject (object): """This is a qt.QObject replacememt for systems with no PyQt. It supports a simple connect/emit mechanism.""" - def __init__ (self,name=None,*args): + def __init__ (self, name=None, *args): self._name = name; self._connections = {}; def name (self): return self._name; - def connect (sender,signal,receiver): + def connect (sender, signal, receiver): """Connects named signal of sender to receiver"""; conns = sender._connections.setdefault(signal,[]); conns.append(receiver); return True; connect = staticmethod(connect); - def disconnect (sender,signal,receiver): + def disconnect (sender, signal, receiver): """Disconnects named signal of sender from receiver"""; conns = sender._connections.get(signal,None); if conns: sender._connections[signal] = [x for x in conns if x!=receiver]; disconnect = staticmethod(disconnect); - def emit (signal,args): + def emit (self, signal, *args): for receiver in self._connections.get(signal,[]): receiver(*args); diff --git a/PyApps/src/Apps/meqserver.py b/PyApps/src/Apps/meqserver.py index 0c5dd776f..229d97d53 100644 --- a/PyApps/src/Apps/meqserver.py +++ b/PyApps/src/Apps/meqserver.py @@ -39,9 +39,8 @@ try: from Timba.GUI import meqserver_gui from Timba.GUI.meqserver_gui import * - except: + except ImportError: print("*** Error importing GUI modules:"); - traceback.print_exc(); pass; # #-------- update default debuglevels diff --git a/PyApps/src/Apps/multiapp_proxy.py b/PyApps/src/Apps/multiapp_proxy.py index 0387dc0a1..4648a6000 100644 --- a/PyApps/src/Apps/multiapp_proxy.py +++ b/PyApps/src/Apps/multiapp_proxy.py @@ -28,18 +28,21 @@ from Timba.Apps import app_defaults -if app_defaults.include_gui: - import Timba.GUI.app_proxy_gui; - if app_defaults.args.threads: - import Timba.qt_threading; try: from PyQt4.Qt import QObject,SIGNAL from Kittens.widgets import PYSIGNAL -except: + QT_AVAILABLE = True +except ImportError: print("Qt not available, substituting proxy types for QObject"); from .QObject import QObject,PYSIGNAL - + SIGNAL = PYSIGNAL + QT_AVAILABLE = False + +if app_defaults.include_gui and QT_AVAILABLE: + import Timba.GUI.app_proxy_gui; + if app_defaults.args.threads: + import Timba.qt_threading; from Timba.dmi import * from Timba import octopussy @@ -285,7 +288,7 @@ def _connect_server (self,addr): self.servers[addr] = server; self.dprint(2, "requesting state and status update"); self.send_command("Request.State",destination=addr); - self.client.emit(SIGNAL("serverConnected"),server,); + self.client.emit(SIGNAL("serverConnected"),server); self._gui_event_handler(self.hello_event,addr,server); self._gui_event_handler(self.server_state_event,record(),server); # is an auto-attach request in place? diff --git a/PyApps/src/Meq/meq.py b/PyApps/src/Meq/meq.py index 52b5ca1fe..073563baf 100644 --- a/PyApps/src/Meq/meq.py +++ b/PyApps/src/Meq/meq.py @@ -30,7 +30,6 @@ from Timba.dmi import * from Timba.array import * -from Timba.Meq import meqds from Timba import mequtils domain_ndim = 2; diff --git a/PyApps/src/Meq/meqds.py b/PyApps/src/Meq/meqds.py index be933ac04..b1b595ab6 100644 --- a/PyApps/src/Meq/meqds.py +++ b/PyApps/src/Meq/meqds.py @@ -42,11 +42,12 @@ import traceback try: - from PyQt4.Qt import QObject,SIGNAL + from PyQt4.Qt import QObject, SIGNAL from Kittens.widgets import PYSIGNAL except: print("Qt not available, substituting proxy types for QObject"); - from Timba.Apps.QObject import QObject,PYSIGNAL + from Timba.Apps.QObject import QObject, PYSIGNAL + SIGNAL = PYSIGNAL _dbg = verbosity(0,name='meqds'); _dprint = _dbg.dprint; diff --git a/PyApps/src/TDL/Compile.py b/PyApps/src/TDL/Compile.py index 0c491ca53..841b49a78 100644 --- a/PyApps/src/TDL/Compile.py +++ b/PyApps/src/TDL/Compile.py @@ -32,7 +32,7 @@ import Timba.TDL.Settings from Timba.TDL import TDLOptions -import imp + import sys import re import traceback @@ -42,6 +42,9 @@ import six if six.PY3: from importlib import reload + import importlib.machinery +#else: +import imp _dbg = verbosity(0,name='tdlc'); _dprint = _dbg.dprint; @@ -66,6 +69,7 @@ def _update_modlist (): _dprint(1,'TDL run imported',len(_tdlmodlist),"modules:",modlist); _tdlmodlist = set([name for name in _tdlmodlist if name != "six" and not name.startswith("six.") + and name != "astropy" and not name.startswith("astropy.") and not getattr(sys.modules[name],'_tdl_no_reimport',False)]); modlist = list(_tdlmodlist); modlist.sort(); @@ -84,12 +88,11 @@ class CompileError (RuntimeError): def __init__ (self,*errlist): self.errlist = errlist; -def import_tdl_module (filename,text=None,config=0): +def import_tdl_module (filename, text=None, config=0): """Imports a TDL module. Parameters: filename: script location - text: text of module. If none, file will be re-read. - + text: if None loads from specified filename Return value: a tuple of (module,text), where module is the newly-imported TDL module, and text is the module text. @@ -117,10 +120,18 @@ def import_tdl_module (filename,text=None,config=0): except: pass; # open file - infile = open(filename,'r'); + infile = open(filename,'r') if text is None: text = infile.read(); infile.seek(0); + # infile = open(filename,'r') + # text = infile.read() + # infile.seek(0) + # else: + # infile = open("./.currenttdl.py", mode='w+b') + # infile.write(text.encode('utf-8')) + # infile.seek(0) + # infile is now an open input file object, and text is the script # flush all modules imported via previous TDL run @@ -135,11 +146,19 @@ def import_tdl_module (filename,text=None,config=0): modname = '__tdlruntime'; try: TDLOptions.enable_save_config(False); - imp.acquire_lock(); - _tdlmod = imp.load_source(modname,filename,infile); + # if six.PY2: + imp.acquire_lock() + _tdlmod = imp.load_source(modname, filename, infile) + # else: + # import types + # loader = importlib.machinery.SourceFileLoader(modname, filename if text is None else infile.name) + # spec = importlib.util.spec_from_loader(loader.name, loader) + # _tdlmod = importlib.util.module_from_spec(spec) + # loader.exec_module(_tdlmod) finally: TDLOptions.enable_save_config(True); TDLOptions.save_config(); + #if six.PY2: imp.release_lock(); infile.close(); _update_modlist(); diff --git a/PyApps/src/TDL/TDLOptions.py b/PyApps/src/TDL/TDLOptions.py index a4e3996e3..b5f93c57a 100644 --- a/PyApps/src/TDL/TDLOptions.py +++ b/PyApps/src/TDL/TDLOptions.py @@ -26,7 +26,6 @@ from Timba.dmi import * from Timba.utils import * -from Timba.GUI.pixmaps import pixmaps import configparser import traceback @@ -45,9 +44,11 @@ from PyQt4.Qt import * from Kittens.widgets import PYSIGNAL OptionObject = QObject(); -except: - OptionObject; - pass; +except ImportError: + OptionObject = None + class QFileDialog: + pass + pass _dbg = verbosity(0,name='tdlopt'); _dprint = _dbg.dprint; @@ -384,6 +385,7 @@ def set_doc (self,doc): self.doc = doc; if self._twitem: if self.doc: + from Timba.GUI.pixmaps import pixmaps icon = pixmaps.info_blue_round.icon(); # add body tags to convert documentation to rich text doc = ""+self.doc+""; @@ -441,6 +443,7 @@ def __init__ (self,func,name=None,namespace=None,doc=None,job_id=None): def make_treewidget_item0 (self,parent,after,executor=None): item = QTreeWidgetItem(parent,after); item.setText(0,self.name); + from Timba.GUI.pixmaps import pixmaps item.setIcon(0,pixmaps.gear.icon()); font = item.font(0); font.setBold(True); @@ -455,6 +458,7 @@ def make_treewidget_item (self,parent,after,executor=None): tw = item.treeWidget(); button = QToolButton(tw); button.setText(self.name); + from Timba.GUI.pixmaps import pixmaps button.setIcon(pixmaps.gear.icon()); button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon); if self.doc: