X Tutup
Skip to content

Commit 4dc6e03

Browse files
committed
Removed spyderlib dependency (upgrading Spyder from WP Control Panel is now possible!)
1 parent 9c801e6 commit 4dc6e03

File tree

13 files changed

+585
-23
lines changed

13 files changed

+585
-23
lines changed

README

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Licensed under the terms of the MIT License
2525

2626
Python >=2.6 or Python >=3.0
2727
PyQt4 >=4.5 or PySide >=1.1.1 (PyQt4 is recommended)
28-
spyderlib >=2.1
2928
guidata >=1.6.1
3029

3130
Requirements

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_subpackages(name):
5959
package_data={LIBNAME:
6060
get_package_data(LIBNAME, ('.mo', '.svg', '.png', '.css',
6161
'.html', '.js', '.ini')),},
62-
requires=["spyderlib (>=2.1.12)", "PyQt4 (>=4.5)", "guidata (>=1.6.1)"],
62+
requires=["PyQt4 (>=4.5)", "guidata (>=1.6.1)"],
6363
scripts=[osp.join('scripts', fname) for fname in
6464
('register_python', 'register_python.bat',
6565
'wpcp', 'wpcp.bat', 'wppm', 'wppm.bat', '2to3.bat')],

winpython/config.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,35 @@
1010
Created on Wed Aug 29 12:23:19 2012
1111
"""
1212

13-
from spyderlib.baseconfig import add_image_path, get_module_data_path
13+
import sys
14+
import os.path as osp
1415

15-
add_image_path(get_module_data_path('winpython', relpath='images'))
16-
add_image_path(get_module_data_path('spyderlib', relpath='images'))
1716

18-
def get_data_path():
19-
"""Return package data path"""
20-
return get_module_data_path('winpython', relpath='data')
17+
def get_module_path(modname):
18+
"""Return module *modname* base path"""
19+
return osp.abspath(osp.dirname(sys.modules[modname].__file__))
20+
21+
22+
def get_module_data_path(modname, relpath=None, attr_name='DATAPATH'):
23+
"""Return module *modname* data path
24+
Note: relpath is ignored if module has an attribute named *attr_name*
25+
26+
Handles py2exe/cx_Freeze distributions"""
27+
datapath = getattr(sys.modules[modname], attr_name, '')
28+
if datapath:
29+
return datapath
30+
else:
31+
datapath = get_module_path(modname)
32+
parentdir = osp.join(datapath, osp.pardir)
33+
if osp.isfile(parentdir):
34+
# Parent directory is not a directory but the 'library.zip' file:
35+
# this is either a py2exe or a cx_Freeze distribution
36+
datapath = osp.abspath(osp.join(osp.join(parentdir, osp.pardir),
37+
modname))
38+
if relpath is not None:
39+
datapath = osp.abspath(osp.join(datapath, relpath))
40+
return datapath
41+
42+
43+
DATA_PATH = get_module_data_path('winpython', relpath='data')
44+
IMAGE_PATH = get_module_data_path('winpython', relpath='images')

winpython/controlpanel.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414
import os
1515
import sys
1616
import platform
17+
import locale
1718

18-
from spyderlib.qt.QtGui import (QApplication, QMainWindow, QWidget, QLineEdit,
19+
from winpython.qt.QtGui import (QApplication, QMainWindow, QWidget, QLineEdit,
1920
QHBoxLayout, QVBoxLayout, QColor, QMessageBox,
2021
QAbstractItemView, QProgressDialog, QTableView,
2122
QPushButton, QLabel, QTabWidget, QToolTip,
2223
QDesktopServices)
23-
from spyderlib.qt.QtCore import (Qt, QAbstractTableModel, QModelIndex, SIGNAL,
24+
from winpython.qt.QtCore import (Qt, QAbstractTableModel, QModelIndex, SIGNAL,
2425
QThread, QTimer, QUrl)
25-
from spyderlib.qt.compat import (to_qvariant, getopenfilenames,
26+
from winpython.qt.compat import (to_qvariant, getopenfilenames,
2627
getexistingdirectory)
27-
import spyderlib.qt
28+
import winpython.qt
2829

29-
from spyderlib.utils.qthelpers import (get_icon, add_actions, create_action,
30-
keybinding, get_std_icon, action2button,
31-
mimedata2url)
32-
from spyderlib.utils import encoding
30+
from winpython.qthelpers import (get_icon, add_actions, create_action,
31+
keybinding, get_std_icon, action2button,
32+
mimedata2url)
3333

3434
# Local imports
3535
from winpython import __version__, __project_url__, __forum_url__
@@ -330,7 +330,14 @@ def run(self):
330330
try:
331331
self.callback()
332332
except Exception as error:
333-
self.error = encoding.to_unicode_from_fs(str(error))
333+
error_str = str(error)
334+
fs_encoding = sys.getfilesystemencoding()\
335+
or locale.getpreferredencoding()
336+
try:
337+
error_str = error_str.decode(fs_encoding)
338+
except (UnicodeError, TypeError):
339+
pass
340+
self.error = error_str
334341

335342

336343
def python_distribution_infos():
@@ -688,8 +695,8 @@ def report_issue(self):
688695
Please provide any additional information below.
689696
""" % (python_distribution_infos(),
690697
__version__, platform.python_version(),
691-
spyderlib.qt.QtCore.__version__, spyderlib.qt.API_NAME,
692-
spyderlib.qt.__version__)
698+
winpython.qt.QtCore.__version__, winpython.qt.API_NAME,
699+
winpython.qt.__version__)
693700

694701
url = QUrl("%s/issues/entry" % __project_url__)
695702
url.addQueryItem("comment", issue_template)
@@ -715,8 +722,8 @@ def about(self):
715722
Python %s, Qt %s, %s %s"""
716723
% (self.NAME, __version__, __project_url__, __forum_url__,
717724
python_distribution_infos(),
718-
platform.python_version(), spyderlib.qt.QtCore.__version__,
719-
spyderlib.qt.API_NAME, spyderlib.qt.__version__,) )
725+
platform.python_version(), winpython.qt.QtCore.__version__,
726+
winpython.qt.API_NAME, winpython.qt.__version__,) )
720727

721728

722729
def main(test=False):
@@ -731,6 +738,7 @@ def main(test=False):
731738

732739
def test():
733740
app, win = main(test=True)
741+
print(sys.modules)
734742
app.exec_()
735743

736744

winpython/images/bug.png

1.62 KB
Loading

winpython/qt/QtCore.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright © 2011 Pierre Raybaut
4+
# Licensed under the terms of the MIT License
5+
# (copied from Spyder source code [spyderlib.qt])
6+
7+
import os
8+
9+
if os.environ['QT_API'] == 'pyqt':
10+
from PyQt4.QtCore import * # analysis:ignore
11+
from PyQt4.Qt import QCoreApplication # analysis:ignore
12+
from PyQt4.Qt import Qt # analysis:ignore
13+
from PyQt4.QtCore import pyqtSignal as Signal # analysis:ignore
14+
from PyQt4.QtCore import pyqtSlot as Slot # analysis:ignore
15+
from PyQt4.QtCore import pyqtProperty as Property # analysis:ignore
16+
from PyQt4.QtCore import QT_VERSION_STR as __version__
17+
else:
18+
import PySide.QtCore
19+
__version__ = PySide.QtCore.__version__ # analysis:ignore
20+
from PySide.QtCore import * # analysis:ignore

winpython/qt/QtGui.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright © 2011 Pierre Raybaut
4+
# Licensed under the terms of the MIT License
5+
# (copied from Spyder source code [spyderlib.qt])
6+
7+
import os
8+
9+
if os.environ['QT_API'] == 'pyqt':
10+
from PyQt4.Qt import QKeySequence, QTextCursor # analysis:ignore
11+
from PyQt4.QtGui import * # analysis:ignore
12+
else:
13+
from PySide.QtGui import * # analysis:ignore

winpython/qt/QtSvg.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright © 2012 Pierre Raybaut
4+
# Licensed under the terms of the MIT License
5+
# (copied from Spyder source code [spyderlib.qt])
6+
7+
import os
8+
9+
if os.environ['QT_API'] == 'pyqt':
10+
from PyQt4.QtSvg import * # analysis:ignore
11+
else:
12+
from PySide.QtSvg import * # analysis:ignore

winpython/qt/QtWebKit.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright © 2011 Pierre Raybaut
4+
# Licensed under the terms of the MIT License
5+
# (copied from Spyder source code [spyderlib.qt])
6+
7+
import os
8+
9+
if os.environ['QT_API'] == 'pyqt':
10+
from PyQt4.QtWebKit import * # analysis:ignore
11+
else:
12+
from PySide.QtWebKit import * # analysis:ignore

winpython/qt/__init__.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright © 2011 Pierre Raybaut
4+
# Licensed under the terms of the MIT License
5+
# (copied from Spyder source code [spyderlib.qt])
6+
7+
"""Transitional package (PyQt4 --> PySide)"""
8+
9+
import os
10+
11+
os.environ.setdefault('QT_API', 'pyqt')
12+
assert os.environ['QT_API'] in ('pyqt', 'pyside')
13+
14+
API = os.environ['QT_API']
15+
API_NAME = {'pyqt': 'PyQt4', 'pyside': 'PySide'}[API]
16+
17+
if API == 'pyqt':
18+
# We do not force QString, QVariant, ... API to #1 or #2 anymore
19+
# as spyderlib is now compatible with both APIs
20+
# import sip
21+
# try:
22+
# sip.setapi('QString', 2)
23+
# sip.setapi('QVariant', 2)
24+
# except AttributeError:
25+
# # PyQt < v4.6: in future version, we should warn the user
26+
# # that PyQt is outdated and won't be supported by Spyder >v2.1
27+
# pass
28+
try:
29+
from PyQt4.QtCore import PYQT_VERSION_STR as __version__
30+
except ImportError:
31+
# Switching to PySide
32+
API = os.environ['QT_API'] = 'pyside'
33+
API_NAME = 'PySide'
34+
else:
35+
__version_info__ = tuple(__version__.split('.')+['final', 1])
36+
is_old_pyqt = __version__.startswith(('4.4', '4.5', '4.6', '4.7'))
37+
is_pyqt46 = __version__.startswith('4.6')
38+
import sip
39+
try:
40+
API_NAME += (" (API v%d)" % sip.getapi('QString'))
41+
except AttributeError:
42+
pass
43+
44+
if API == 'pyside':
45+
try:
46+
from PySide import __version__ # analysis:ignore
47+
except ImportError:
48+
raise ImportError("Spyder requires PySide or PyQt to be installed")
49+
else:
50+
is_old_pyqt = is_pyqt46 = False

0 commit comments

Comments
 (0)
X Tutup