taurus-org / taurus

Moved to https://gitlab.com/taurus-org/taurus
http://taurus-scada.org
43 stars 46 forks source link

Isolate taurus external dependencies that need patching #50

Closed sf-migrator-bot closed 7 years ago

sf-migrator-bot commented 10 years ago

Description

Today taurus uses some external libraries that need local customization. This customization may be required for different reasons:

  1. dependency on the actual implementation (ex.: PyQt vs PySide)
  2. dependency on python version (ex.: ordereddict exists only on python >= 2.7)
  3. soft dependency, ie, if library X is not installed then a local implementation of X can be used instead (ex.: pint for units).

Local customizations are being made inline. This has some weakenesses. For example, Qt is being wrapped inside taurus/qt/. It is not possible to extend the wrapping for the PyQt4.uic package because before the Qt wrapping concept was added to taurus, an internal taurus sub-package called taurus/qt/uic already existed to help handle code generation in taurusuic4 tool. It is therefore not possible to wrap PyQt4.uic inside taurus.

This is a request to clearly isolate dependencies in a taurus sub package. I propose to make a taurus.external which isolates the management of these dependencies.

Here is the list of packages that need to be "externalized" and the reason:

  1. Qt - a lot of boilerplate code to manage different Qt implementations.
  2. enum ([SEP12]) - present on python >= 3.4 only, there is a backport for python >= 2.4. It should be a soft dependency: if not installed it should use a local implementation.
  3. ordereddict - present on python >= 2.7 only, there is a backport for python >= 2.4 It should be a soft dependency: if not installed it should use a local implementation.
  4. argparse - present on python >= 3.2 only, there is a backport for python >= 2.3 It should be a soft dependency: if not installed it should use a local implementation.
  5. unittest - taurus needs implementation new features of python >= 2.7. A backport exists (unittest2) for python >= 2.4 It should not be a soft dependency: if not installed you should not be able to run tests with python 2.6
  6. pint - taurus requires pint of unit management ([SEP3]). Some boilerplate initialization code needs to be done before using pint. pint should be a soft dependency: if not installed it should use a local implementation.
  7. setuptools - maybe in the future. Not absolutely required for now

In practice, the import statements in taurus should be changed from:

:::python
try:
    import argparse
except ImportError:
    import optparse as argparse

to:

:::python
from taurus.external import argparse

and from:

:::python
from taurus.qt import Qt
from taurus.qt import QtCore
from taurus.qt import QtGui

to:

:::python
from taurus.external.qt import Qt
from taurus.external.qt import QtCore
from taurus.external.qt import QtGui

Special note for the Qt package

Backward compatibility

Since many taurus applications are relying on taurus.qt.Qt[Core|Gui], the implementation must take into account backward compatibility.

Handling of PyQt4.Qt

The PyQt4.Qt sub-package is a helper for the following packages: QtDBus QtHelp QtNetwork QtOpenGL QtScriptTools QtScript QtDeclarative QtCore QtGui

Today taurus uses Qt to address only QtCore and QtGui symbols. When taurus imports PyQt4.Qt indirectly a waste of ~25Mb of RAM (depends on implementation) is made by process which only needs QtCore and QtGui.

This package doesn't exist in PySide. The QtNetwork was only added in PyQt4 4.4.

Because of these problems it is proposed that an implementation of taurus.external.qt.Qt includes only symbols from QtCore and QtGui.

Colaborative Qt

Taurus Qt usage should depend on the private taurus qt configuration. The configuration describes the policy for using a specific Qt implementation. The usage of a specific Qt implementation should correspond to the following algorithm:

if a Qt is already in memory:
    if config.[use specific Qt implementation]:
        if config.[specific Qt implementation] != Qt in memory:
            <raise Failed to use Qt X because Qt Y is already in use>
else:
    <find best Qt according to config.[prefered Qts] and installed Qts>
    if no Qt found:
        <raise no Qt implementation found>

if Qt as not been initialized:
    <initialize Qt implementation>

the Qt configuration could be based on taurus.tauruscustomsettings. Example:

:::python
# ----------------------------------------------------------------------------
# Qt configuration
# ----------------------------------------------------------------------------

#: Auto initialize Qt
DEFAULT_QT_AUTO_INIT = True

#: Set preffered API if not is already loaded
DEFAULT_QT_AUTO_API = 'PyQt4'

#: Whether or not should be strict in choosing Qt API
DEFAULT_QT_AUTO_STRICT = False

#: Auto initialize Qt logging to python logging
DEFAULT_QT_AUTO_INIT_LOG = True

#: Auto initialize taurus resources (icons)
DEFAULT_QT_AUTO_INIT_RES = True

#: Remove input hook (only valid for PyQt4)
DEFAULT_QT_AUTO_REMOVE_INPUTHOOK = True

#: Auto initialize Qt
QT_AUTO_INIT = DEFAULT_QT_AUTO_INIT

#: Set preffered API if not is already loaded
QT_AUTO_API = DEFAULT_QT_AUTO_API

#: Whether or not should be strict in choosing Qt API
QT_AUTO_STRICT = DEFAULT_QT_AUTO_STRICT

#: Auto initialize Qt logging to python logging
QT_AUTO_INIT_LOG = DEFAULT_QT_AUTO_INIT_LOG

#: Auto initialize taurus resources (icons)
QT_AUTO_INIT_RES = DEFAULT_QT_AUTO_INIT_RES

#: Remove input hook (only valid for PyQt4)
QT_AUTO_REMOVE_INPUTHOOK = DEFAULT_QT_AUTO_REMOVE_INPUTHOOK

References

The implementation I propose is based on the success story of IPython management of external dependencies through the usage of IPython.external pattern.

This implementation has also proved to work before on the Qarbon project with a similar External pattern

Reported by: tiagocoutinho ( http://sf.net/u/tiagocoutinho )

sf-migrator-bot commented 10 years ago

Diff:


--- old
+++ new
@@ -1,3 +1,5 @@
+Description
+===========

 Today taurus uses some external libraries that need local customization. 
 This customization may be required for different reasons:
@@ -125,12 +127,11 @@
     #: Auto initialize Qt logging to python logging
     DEFAULT_QT_AUTO_INIT_LOG = True

-    #: Auto initialize Qarbon resources (icons)
+    #: Auto initialize taurus resources (icons)
     DEFAULT_QT_AUTO_INIT_RES = True

     #: Remove input hook (only valid for PyQt4)
     DEFAULT_QT_AUTO_REMOVE_INPUTHOOK = True
-

     #: Auto initialize Qt
     QT_AUTO_INIT = DEFAULT_QT_AUTO_INIT
@@ -144,15 +145,16 @@
     #: Auto initialize Qt logging to python logging
     QT_AUTO_INIT_LOG = DEFAULT_QT_AUTO_INIT_LOG

-    #: Auto initialize Qarbon resources (icons)
+    #: Auto initialize taurus resources (icons)
     QT_AUTO_INIT_RES = DEFAULT_QT_AUTO_INIT_RES

     #: Remove input hook (only valid for PyQt4)
     QT_AUTO_REMOVE_INPUTHOOK = DEFAULT_QT_AUTO_REMOVE_INPUTHOOK

-
 References
 ==============

-The implementation I propose is based on the success story of IPython management
-of external dependencies through the usage of IPython.external pattern.
+The implementation I propose is based on the success story of [IPython](http://www.ipython.org) management
+of external dependencies through the usage of [IPython.external pattern](https://github.com/ipython/ipython/tree/master/IPython/external "IPython.external pattern").
+
+This implementation has also proved to work before on the [Qarbon project](http://qarbon.rtfd.org) with a similar [External pattern](https://github.com/ESRF-BCU/qarbon/tree/master/qarbon/external "Qarbon external management")

Original comment by: tiagocoutinho (http://sourceforge.net/u/tiagocoutinho)

sf-migrator-bot commented 10 years ago

Original comment by: tiagocoutinho (http://sourceforge.net/u/tiagocoutinho)

sf-migrator-bot commented 10 years ago

A patch has been sent to implement this feature

Original comment by: tiagocoutinho (http://sourceforge.net/u/tiagocoutinho)

sf-migrator-bot commented 10 years ago

Original comment by: tiagocoutinho (http://sourceforge.net/u/tiagocoutinho)

sf-migrator-bot commented 10 years ago

Original comment by: cpascual (http://sourceforge.net/u/cpascual)

sf-migrator-bot commented 10 years ago

After quite some troubles, I finally managed to apply the patch. The feature is now immplemented in the develop branch.

I also changed some more imports that were not covered in tiago's patch, mostly in docs and in sardana

Original comment by: cpascual (http://sourceforge.net/u/cpascual)

sf-migrator-bot commented 10 years ago

Thanks Carlos. You're the best!

Original comment by: tiagocoutinho (http://sourceforge.net/u/tiagocoutinho)

sf-migrator-bot commented 9 years ago

Ticket moved from /p/sardana/tickets/113/

Can't be converted:

Original comment by: tiagocoutinho (http://sourceforge.net/u/tiagocoutinho)