Skip to content

Commit

Permalink
Merge pull request #25 from lsst/tickets/DM-15435
Browse files Browse the repository at this point in the history
DM-15435: Remove python 2 support from pex packages
  • Loading branch information
r-owen committed Aug 15, 2018
2 parents 636dfb1 + 650000f commit 9645794
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 93 deletions.
6 changes: 1 addition & 5 deletions python/lsst/pex/config/callStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@
# see <https://www.lsstcorp.org/LegalNotices/>.
#

from __future__ import print_function, division, absolute_import

__all__ = ['getCallerFrame', 'getStackFrame', 'StackFrame', 'getCallStack']

from builtins import object

import inspect
import linecache

Expand Down Expand Up @@ -70,7 +66,7 @@ def getStackFrame(relative=0):
return StackFrame.fromFrame(frame)


class StackFrame(object):
class StackFrame:
"""A single element of the stack trace
This differs slightly from the standard system mechanisms for
Expand Down
9 changes: 1 addition & 8 deletions python/lsst/pex/config/choiceField.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
oldStringType = str # Need to keep hold of original str type
from builtins import str
__all__ = ["ChoiceField"]

from .config import Field, _typeStr
from .callStack import getStackFrame

__all__ = ["ChoiceField"]


class ChoiceField(Field):
"""
Expand All @@ -43,10 +40,6 @@ def __init__(self, doc, dtype, allowed, default=None, optional=True):
if len(self.allowed) == 0:
raise ValueError("ChoiceFields must allow at least one choice")

# Use standard string type if we are given a future str
if dtype == str:
dtype = oldStringType

Field.__init__(self, doc=doc, dtype=dtype, default=default,
check=None, optional=optional)

Expand Down
26 changes: 5 additions & 21 deletions python/lsst/pex/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
# the GNU General Public License along with this program. If not,
# see <https://www.lsstcorp.org/LegalNotices/>.
#
oldStringType = str # Need to keep hold of original str type
from builtins import str
from builtins import object
from past.builtins import long
from past.builtins import basestring
from past.builtins import unicode
__all__ = ("Config", "Field", "FieldValidationError")

import io
import os
Expand All @@ -37,9 +32,6 @@

from .comparison import getComparisonName, compareScalars, compareConfigs
from .callStack import getStackFrame, getCallStack
from future.utils import with_metaclass

__all__ = ("Config", "Field", "FieldValidationError")


def _joinNamePath(prefix=None, name=None, index=None):
Expand All @@ -66,10 +58,6 @@ def _autocast(x, dtype):
"""
if dtype == float and isinstance(x, int):
return float(x)
if dtype == int and isinstance(x, long):
return int(x)
if isinstance(x, str):
return oldStringType(x)
return x


Expand Down Expand Up @@ -151,7 +139,7 @@ def __init__(self, field, config, msg):
ValueError.__init__(self, error)


class Field(object):
class Field:
"""A field in a a Config.
Instances of Field should be class attributes of Config subclasses:
Expand All @@ -162,7 +150,7 @@ class Example(Config):
"""
# Must be able to support str and future str as we can not guarantee that
# code will pass in a future str type on Python 2
supportedTypes = set((str, unicode, basestring, oldStringType, bool, float, int, complex))
supportedTypes = set((str, bool, float, int, complex))

def __init__(self, doc, dtype, default=None, check=None, optional=False):
"""Initialize a Field.
Expand All @@ -179,10 +167,6 @@ def __init__(self, doc, dtype, default=None, check=None, optional=False):
if dtype not in self.supportedTypes:
raise ValueError("Unsupported Field dtype %s" % _typeStr(dtype))

# Use standard string type if we are given a future str
if dtype == str:
dtype = oldStringType

source = getStackFrame()
self._setup(doc=doc, dtype=dtype, default=default, check=check, optional=optional, source=source)

Expand Down Expand Up @@ -376,7 +360,7 @@ def _compare(self, instance1, instance2, shortcut, rtol, atol, output):
return compareScalars(name, v1, v2, dtype=self.dtype, rtol=rtol, atol=atol, output=output)


class RecordingImporter(object):
class RecordingImporter:
"""An Importer (for sys.meta_path) that records which modules are being imported.
Objects also act as Context Managers, so you can:
Expand Down Expand Up @@ -418,7 +402,7 @@ def getModules(self):
return self._modules


class Config(with_metaclass(ConfigMeta, object)):
class Config(metaclass=ConfigMeta):
"""Base class for control objects.
A Config object will usually have several Field instances as class
Expand Down
6 changes: 2 additions & 4 deletions python/lsst/pex/config/configChoiceField.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import print_function
from builtins import str

__all__ = ["ConfigChoiceField"]

import copy
import collections
Expand All @@ -29,8 +29,6 @@
from .comparison import getComparisonName, compareScalars, compareConfigs
from .callStack import getCallStack, getStackFrame

__all__ = ["ConfigChoiceField"]


class SelectionSet(collections.MutableSet):
"""
Expand Down
1 change: 0 additions & 1 deletion python/lsst/pex/config/configDictField.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import print_function

from .config import Config, FieldValidationError, _autocast, _typeStr, _joinNamePath
from .dictField import Dict, DictField
Expand Down
5 changes: 2 additions & 3 deletions python/lsst/pex/config/configField.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import str

__all__ = ["ConfigField"]

from .config import Config, Field, FieldValidationError, _joinNamePath, _typeStr
from .comparison import compareConfigs, getComparisonName
from .callStack import getCallStack, getStackFrame

__all__ = ["ConfigField"]


class ConfigField(Field):
"""
Expand Down
5 changes: 1 addition & 4 deletions python/lsst/pex/config/configurableField.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import print_function
from builtins import str
from builtins import object

import copy

Expand All @@ -30,7 +27,7 @@
from .callStack import getCallStack, getStackFrame


class ConfigurableInstance(object):
class ConfigurableInstance:
def __initValue(self, at, label):
"""
if field.default is an instance of ConfigClass, custom construct
Expand Down
5 changes: 2 additions & 3 deletions python/lsst/pex/config/dictField.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import str

__all__ = ["DictField"]

import collections

from .config import Field, FieldValidationError, _typeStr, _autocast, _joinNamePath
from .comparison import getComparisonName, compareScalars
from .callStack import getCallStack, getStackFrame

__all__ = ["DictField"]


class Dict(collections.MutableMapping):
"""
Expand Down
7 changes: 1 addition & 6 deletions python/lsst/pex/config/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import print_function
from builtins import str
from builtins import object

import os
import re
import sys

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


class Color(object):
class Color:
"""Control whether strings should be coloured
The usual usage is `Color(string, category)` which returns a string that
Expand Down
7 changes: 2 additions & 5 deletions python/lsst/pex/config/listField.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import zip
from builtins import str
from builtins import range

__all__ = ["ListField"]

import collections

from .config import Field, FieldValidationError, _typeStr, _autocast, _joinNamePath
from .comparison import compareScalars, getComparisonName
from .callStack import getCallStack, getStackFrame

__all__ = ["ListField"]


class List(collections.MutableSequence):
def __init__(self, config, field, value, at, label, setHistory=True):
Expand Down
9 changes: 4 additions & 5 deletions python/lsst/pex/config/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import object

__all__ = ("Registry", "makeRegistry", "RegistryField", "registerConfig", "registerConfigurable")

import collections
import copy

from .config import Config, FieldValidationError, _typeStr
from .configChoiceField import ConfigInstanceDict, ConfigChoiceField

__all__ = ("Registry", "makeRegistry", "RegistryField", "registerConfig", "registerConfigurable")


class ConfigurableWrapper(object):
class ConfigurableWrapper:
"""A wrapper for configurables
Used for configurables that don't contain a ConfigClass attribute,
Expand Down Expand Up @@ -62,7 +61,7 @@ class that has a psfMatch method with a particular call signature.
registry = Registry()
class FooConfig(Config):
val = Field(dtype=int, default=3, doc="parameter for Foo")
class Foo(object):
class Foo:
ConfigClass = FooConfig
def __init__(self, config):
self.config = config
Expand Down
8 changes: 3 additions & 5 deletions python/lsst/pex/config/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from past.builtins import basestring
__all__ = ("wrap", "makeConfigClass")

import inspect
import re
Expand All @@ -30,8 +30,6 @@
from .configField import ConfigField
from .callStack import getCallerFrame, getCallStack

__all__ = ("wrap", "makeConfigClass")

# Mapping from C++ types to Python type: assumes we can round-trip between these using
# the usual pybind11 converters, but doesn't require they be binary equivalent under-the-hood
# or anything.
Expand All @@ -41,7 +39,7 @@
"double": float,
"float": float,
"std::int64_t": int,
"std::string": basestring
"std::string": str
}

_containerRegex = re.compile(r"(std::)?(vector|list)<\s*(?P<type>[a-z0-9_:]+)\s*>")
Expand Down Expand Up @@ -129,7 +127,7 @@ class will be silently ignored; this allows the user to customize fields and
frame = getCallerFrame(module)
moduleObj = inspect.getmodule(frame)
moduleName = moduleObj.__name__
elif isinstance(module, basestring):
elif isinstance(module, str):
moduleName = module
moduleObj = __import__(moduleName)
else:
Expand Down
5 changes: 0 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,3 @@ exclude = __init__.py, testLib.py, ticket1914.py
[tool:pytest]
addopts = --flake8
flake8-ignore = E133 E226 E228 N802 N803 N806
# These can be fixed when python2 is dropped
# ie E402 module level import not at top of file
# These are caused by storing `str` before imports override it
python/lsst/pex/config/choiceField.py E402
python/lsst/pex/config/config.py E402
6 changes: 2 additions & 4 deletions tests/test_Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import object
from past.builtins import unicode

import io
import itertools
Expand Down Expand Up @@ -270,7 +268,7 @@ class FFF(AAA, DDD):
self.assertEqual(f.a, 4)

# test inheritance from non Config objects
class GGG(object):
class GGG:
a = pexConfig.Field("AAA.a", float, default=10.)

class HHH(GGG, AAA):
Expand Down Expand Up @@ -323,7 +321,7 @@ def checkImportRoundTrip(self, importStatement, searchString, shouldBeThere):

# Generate a Config through loading
stream = io.StringIO()
stream.write(unicode(importStatement))
stream.write(str(importStatement))
self.comp.saveToStream(stream)
roundtrip = Complex()
roundtrip.loadFromStream(stream.getvalue())
Expand Down
3 changes: 1 addition & 2 deletions tests/test_configurableField.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import object

import os
import unittest
Expand All @@ -33,7 +32,7 @@ class Config1(pexConf.Config):
f = pexConf.Field("f", dtype=float, default=5, check=lambda x: x > 0)


class Target1(object):
class Target1:
ConfigClass = Config1

def __init__(self, config):
Expand Down

0 comments on commit 9645794

Please sign in to comment.