Skip to content

Commit

Permalink
Replace past/future with compat (#255)
Browse files Browse the repository at this point in the history
* setup: update atom dependency

* Add missing compat change in scintilla

* Bump pyqt5 version for QScintilla 2.10.3

* tests: don't use bare except (this is bad practice)
  • Loading branch information
frmdstryr authored and MatthieuDartiailh committed Mar 5, 2018
1 parent 3c179f0 commit a4a4be8
Show file tree
Hide file tree
Showing 36 changed files with 67 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ before_install:
# This will force qt to the last available version on PyPI and means that
# we will have two versions of qt at the same time but it seems to work fine
- 'if [ $QT_VERSION -gt 4 ] && [ $QSCINTILLA -eq 1 ]; then
$PIP_INSTALL QScintilla pyqt5==5.9.2;
$PIP_INSTALL QScintilla pyqt5==5.10.1;
fi'

# Install the dev version of the other nucleic projects
Expand Down
3 changes: 1 addition & 2 deletions enaml/applib/live_editor_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import traceback
from types import ModuleType

from future.builtins import int
from future.utils import exec_
from atom.api import Atom, Str, Typed, observe

import enaml
from enaml.core.object import Object
from enaml.core.enaml_compiler import EnamlCompiler
from enaml.core.parser import parse
from enaml.compat import exec_
from enaml.widgets.widget import Widget

try:
Expand Down
4 changes: 2 additions & 2 deletions enaml/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"""
from colorsys import hls_to_rgb
import re
from past.builtins import basestring


from atom.api import Coerced

from .colorext import Color

from enaml.compat import basestring

#: Regex sub-expressions used for building more complex expression.
_int = r'\s*((?:\+|\-)?[0-9]+)\s*'
Expand Down
25 changes: 21 additions & 4 deletions enaml/compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# Copyright (c) 2013-2017, Nucleic Development Team.
# Copyright (c) 2013-2018, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand All @@ -8,8 +8,7 @@
import sys
import re
import codecs

IS_PY3 = sys.version_info >= (3,)
from atom.compat import *

USE_WORDCODE = sys.version_info >= (3, 6)

Expand Down Expand Up @@ -111,8 +110,8 @@ def update_code_co_filename(code, src_path):
code.co_cellvars)
return updated_code

# Source file reading and encoding detection

# Source file reading and encoding detection
if IS_PY3:
import tokenize

Expand Down Expand Up @@ -249,3 +248,21 @@ def read_source(filename):
with open(filename, 'rU') as f:
src = f.read()
return src.decode(enc).encode('utf-8')


if IS_PY3:
import builtins
exec_ = getattr(builtins, "exec")

else:
def exec_(code, globs=None, locs=None):
"""Execute code in a namespace."""
if globs is None:
frame = sys._getframe(1)
globs = frame.f_globals
if locs is None:
locs = frame.f_locals
del frame
elif locs is None:
locs = globs
exec("""exec code in globs, locs""")
3 changes: 1 addition & 2 deletions enaml/core/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from future.utils import with_metaclass

from atom.api import Event, Typed, Unicode
from atom.datastructures.api import sortedmap

from .declarative_meta import DeclarativeMeta
from .expression_engine import ExpressionEngine
from .object import Object, flag_generator, flag_property
from enaml.compat import with_metaclass


def d_(member, readable=True, writable=True, final=True):
Expand Down
5 changes: 2 additions & 3 deletions enaml/core/import_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
from zipfile import ZipFile


from future.utils import with_metaclass, exec_

from .enaml_compiler import EnamlCompiler, COMPILER_VERSION
from .parser import parse
from ..compat import read_source, detect_encoding, update_code_co_filename
from ..compat import (read_source, detect_encoding, update_code_co_filename,
with_metaclass, exec_)


# The magic number as symbols for the current Python interpreter. These
Expand Down
3 changes: 1 addition & 2 deletions enaml/core/parser/base_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import os
import tokenize

from future.builtins import str
import ply.lex as lex

from ...compat import IS_PY3
from ...compat import IS_PY3, str


#------------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions enaml/core/parser/lexer3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from future.builtins import bytes

from .base_lexer import BaseEnamlLexer
from ...compat import decode_escapes, encode_escapes
from ...compat import decode_escapes, encode_escapes, bytes


class Python3EnamlLexer(BaseEnamlLexer):
Expand Down
3 changes: 1 addition & 2 deletions enaml/core/standard_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from past.builtins import basestring
from atom.api import Atom, atomref

from .alias import Alias
from .code_tracing import CodeTracer
from ..compat import IS_PY3
from ..compat import IS_PY3, basestring


class SubscriptionObserver(object):
Expand Down
2 changes: 1 addition & 1 deletion enaml/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
""" A utility module for dealing with CSS3 font strings.
"""
from past.builtins import basestring

from atom.api import Coerced

from .fontext import Font, FontStyle, FontCaps
from enaml.compat import basestring


#: A mapping from CSS font style keyword to style enum
Expand Down
2 changes: 1 addition & 1 deletion enaml/layout/constrainable.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#------------------------------------------------------------------------------
from abc import ABCMeta

from future.utils import with_metaclass
from atom.api import Atom, Constant, DefaultValue, Enum
from enaml.compat import with_metaclass

import kiwisolver as kiwi

Expand Down
3 changes: 1 addition & 2 deletions enaml/layout/dock_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import sys
import warnings

from future.utils import with_metaclass
from past.builtins import basestring
from atom.api import Atom, Int, Bool, Coerced, Enum, List, Unicode

from enaml.nodevisitor import NodeVisitor
from enaml.compat import with_metaclass, basestring

from .geometry import Rect

Expand Down
2 changes: 1 addition & 1 deletion enaml/layout/linear_symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from abc import ABCMeta


from future.utils import with_metaclass
from enaml.compat import with_metaclass
import kiwisolver as kiwi


Expand Down
1 change: 0 additions & 1 deletion enaml/layout/strength_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from future.builtins import int
from atom.api import Validate, Value


Expand Down
2 changes: 1 addition & 1 deletion enaml/qt/docking/q_dock_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from atom.api import Typed, Bool
from future.builtins import str
from enaml.compat import str

from enaml.qt.QtCore import Qt, QMargins, QPoint, QRect, QEvent, Signal
from enaml.qt.QtGui import QIcon, QCursor
Expand Down
2 changes: 1 addition & 1 deletion enaml/qt/docking/q_dock_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from future.builtins import str
from enaml.compat import str
from enaml.qt.QtCore import Qt, QRect, QSize, QPoint, QTimer, Signal
from enaml.qt.QtWidgets import QApplication, QFrame, QLayout

Expand Down
2 changes: 1 addition & 1 deletion enaml/qt/docking/q_dock_title_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from future.builtins import str
from enaml.compat import str
from enaml.qt.QtCore import Qt, QSize, QPoint, QMargins, Signal
from enaml.qt.QtWidgets import (
QWidget, QFrame, QLineEdit, QHBoxLayout, QSizePolicy
Expand Down
2 changes: 1 addition & 1 deletion enaml/qt/docking/style_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from future.builtins import str
from enaml.compat import str

#: The global dict of registered stylesheets. This dict should never be
#: modified directly. Use the functions 'register_style_sheet' and
Expand Down
2 changes: 1 addition & 1 deletion enaml/qt/docking/xbms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from future.builtins import bytes
from enaml.compat import bytes
from atom.api import Atom, Int, Bytes

from enaml.qt.QtCore import QSize
Expand Down
2 changes: 1 addition & 1 deletion enaml/qt/q_flow_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#------------------------------------------------------------------------------
from abc import ABCMeta, abstractmethod

from future.utils import with_metaclass
from enaml.compat import with_metaclass

from .QtCore import Qt, QSize, QRect
from .QtWidgets import QLayout, QWidgetItem
Expand Down
1 change: 0 additions & 1 deletion enaml/qt/qt_ipython_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from atom.api import Typed
from future.utils import raise_from

from enaml.widgets.ipython_console import ProxyIPythonConsole

Expand Down
4 changes: 1 addition & 3 deletions enaml/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
import sys
import types

from future.utils import exec_

from enaml import imports
from enaml.core.parser import parse
from enaml.core.enaml_compiler import EnamlCompiler
from enaml.compat import read_source
from enaml.compat import read_source, exec_


def main():
Expand Down
3 changes: 2 additions & 1 deletion enaml/scintilla/scintilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
import uuid
from future.builtins import str

from atom.api import (
Atom, Int, Constant, Enum, Event, Typed, List, ForwardTyped, Tuple,
Unicode, observe, set_default
)
from enaml.image import Image
from enaml.core.declarative import d_
from enaml.compat import str
from enaml.widgets.control import Control, ProxyControl


Expand Down
3 changes: 1 addition & 2 deletions enaml/stdlib/dock_area_styles.enaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ developer is free to define their own styles completely from scratch, and
ignore these styles in their entirety.

"""
from future.builtins import str
from past.builtins import basestring
from atom.api import Atom, Typed, Unicode
from enaml.core.template_ import Template
from enaml.compat import str, basestring
from enaml.styling import StyleSheet, Style, Setter


Expand Down
2 changes: 1 addition & 1 deletion enaml/stdlib/fields.enaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
This is a library of Enaml components deriving from the builtin Field.

"""
from future.builtins import str
from enaml.compat import str
from enaml.validator import RegexValidator, IntValidator, FloatValidator
from enaml.widgets.field import Field

Expand Down
3 changes: 1 addition & 2 deletions enaml/stdlib/message_box.enaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
import sys
from past.builtins import basestring

from enaml.compat import basestring
from enaml.core.dynamic_template import DynamicTemplate
from enaml.image import Image
from enaml.layout.layout_helpers import align, hbox, spacer
Expand Down
2 changes: 1 addition & 1 deletion enaml/widgets/file_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from future.builtins import str
from atom.api import (
Enum, Bool, Callable, List, Unicode, Typed, ForwardTyped, Event
)

from enaml.application import deferred_call
from enaml.core.declarative import d_
from enaml.compat import str
from .toolkit_object import ToolkitObject, ProxyToolkitObject


Expand Down
3 changes: 1 addition & 2 deletions enaml/widgets/object_combo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from future.builtins import str
from atom.api import (
Bool, Callable, List, Value, Typed, ForwardTyped, set_default, observe
)

from enaml.core.declarative import d_

from enaml.compat import str
from .control import Control, ProxyControl


Expand Down
2 changes: 1 addition & 1 deletion enaml/workbench/workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#------------------------------------------------------------------------------
from collections import defaultdict

from future.builtins import str
from atom.api import Atom, Event, Typed
from enaml.compat import str

from .plugin import Plugin

Expand Down
8 changes: 5 additions & 3 deletions examples/layout/advanced/factory_func.enaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ that a relayout is necessary.

<< autodoc-me >>
"""
from future import standard_library
standard_library.install_aliases()
from itertools import zip_longest
from enaml.compat import IS_PY3
if IS_PY3:
from itertools import zip_longest
else:
from itertools import izip_longest as zip_longest

from enaml.core.api import Include
from enaml.layout.api import align, grid, factory
Expand Down
Loading

0 comments on commit a4a4be8

Please sign in to comment.