Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-22234: Remove python 2 support #112

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions python/lsst/daf/persistence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

"""Python interface to lsst::daf::persistence classes
"""
from __future__ import absolute_import

StorageList = list

Expand Down Expand Up @@ -54,4 +53,3 @@
from .butlerFactory import *
from .butlerHelpers import *
from .version import *

3 changes: 1 addition & 2 deletions python/lsst/daf/persistence/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import object, super

from lsst.daf.persistence import Policy

Expand All @@ -34,7 +33,7 @@ def __init__(self, cls, storageCfg):
super().__init__({'storageCfg': storageCfg, 'cls': cls})


class Access(object):
class Access:
"""Implements an butler framework interface for Transport, Storage, and Registry

.. warning::
Expand Down
18 changes: 7 additions & 11 deletions python/lsst/daf/persistence/butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
# -*- python -*-

"""This module defines the Butler class."""
from builtins import str, super
from past.builtins import basestring
from builtins import object

import copy
import inspect

Expand Down Expand Up @@ -62,7 +58,7 @@ def __init__(self, cls, repoCfg):
super().__init__({'repoCfg': repoCfg, 'cls': cls})


class RepoData(object):
class RepoData:
"""Container object for repository data used by Butler

Parameters
Expand Down Expand Up @@ -240,7 +236,7 @@ def addTags(self, tags):
self.tags = self.tags.union(tags)


class RepoDataContainer(object):
class RepoDataContainer:
"""Container object for RepoData instances owned by a Butler instance.

Parameters
Expand Down Expand Up @@ -322,7 +318,7 @@ def addToList(repoData, lst):
self._outputs = [repoData.repoData for repoData in outputs]


class Butler(object):
class Butler:
"""Butler provides a generic mechanism for persisting and retrieving data using mappers.

A Butler manages a collection of datasets known as a repository. Each dataset has a type representing its
Expand Down Expand Up @@ -625,7 +621,7 @@ def _processInputArguments(self, root=None, mapper=None, inputs=None, outputs=No
raise RuntimeError("The mode of an output should be writable.")
# check for class instances in args.mapper (not allowed)
for args in inputs + outputs:
if (args.mapper and not isinstance(args.mapper, basestring) and
if (args.mapper and not isinstance(args.mapper, str) and
not inspect.isclass(args.mapper)):
self.log.warn(preinitedMapperWarning)
# if the output is readable, there must be only one output:
Expand Down Expand Up @@ -1015,7 +1011,7 @@ def _convertV1Args(self, root, mapper, mapperArgs):
tuple
(inputs, outputs) - values to be used for inputs and outputs in Butler.__init__
"""
if (mapper and not isinstance(mapper, basestring) and
if (mapper and not isinstance(mapper, str) and
not inspect.isclass(mapper)):
self.log.warn(preinitedMapperWarning)
inputs = None
Expand Down Expand Up @@ -1067,7 +1063,7 @@ def _getDefaultMapper(self):
# * a string, import it.
# * a class instance, get its class type
# * a class, do nothing; use it
if isinstance(mapper, basestring):
if isinstance(mapper, str):
mapper = doImport(mapper)
elif not inspect.isclass(mapper):
mapper = mapper.__class__
Expand Down Expand Up @@ -1348,7 +1344,7 @@ def _locate(self, datasetType, dataId, write):
def _getBypassFunc(location, dataId):
pythonType = location.getPythonType()
if pythonType is not None:
if isinstance(pythonType, basestring):
if isinstance(pythonType, str):
pythonType = doImport(pythonType)
bypassFunc = getattr(location.mapper, "bypass_" + location.datasetType)
return lambda: bypassFunc(location.datasetType, pythonType, location, dataId)
Expand Down
1 change: 0 additions & 1 deletion python/lsst/daf/persistence/butlerExceptions.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 builtins import str, super


class NoMapperException(Exception):
Expand Down
3 changes: 1 addition & 2 deletions python/lsst/daf/persistence/butlerFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
# -*- python -*-

"""This module defines the ButlerFactory class."""
from builtins import object

from lsst.daf.persistence import Butler


class ButlerFactory(object):
class ButlerFactory:
"""ButlerFactory creates data Butlers containing data mappers. Use of it
is deprecated in favor of the direct Butler constructor.

Expand Down
12 changes: 5 additions & 7 deletions python/lsst/daf/persistence/butlerLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
import lsst.daf.base as dafBase

import os
from past.builtins import basestring
import yaml

from . import iterify, doImport


class ButlerComposite(object):
class ButlerComposite:
"""Initializer

Parameters
Expand Down Expand Up @@ -101,9 +100,9 @@ def __repr__(self):
self.repository)

def __init__(self, assembler, disassembler, python, dataId, mapper):
self.assembler = doImport(assembler) if isinstance(assembler, basestring) else assembler
self.disassembler = doImport(disassembler) if isinstance(disassembler, basestring) else disassembler
self.python = doImport(python) if isinstance(python, basestring) else python
self.assembler = doImport(assembler) if isinstance(assembler, str) else assembler
self.disassembler = doImport(disassembler) if isinstance(disassembler, str) else disassembler
self.python = doImport(python) if isinstance(python, str) else python
self.dataId = dataId
self.mapper = mapper
self.componentInfo = {}
Expand Down Expand Up @@ -209,8 +208,7 @@ def __repr__(self):

def __init__(self, pythonType, cppType, storageName, locationList, dataId, mapper, storage,
usedDataId=None, datasetType=None, additionalData=None):
# pythonType is sometimes unicode with Python 2 and pybind11; this breaks the interpreter
self.pythonType = str(pythonType) if isinstance(pythonType, basestring) else pythonType
self.pythonType = pythonType
self.cppType = cppType
self.storageName = storageName
self.mapper = mapper
Expand Down
9 changes: 3 additions & 6 deletions python/lsst/daf/persistence/butlerSubset.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@

"""This module defines the ButlerSubset class and the ButlerDataRefs contained
within it as well as an iterator over the subset."""
from builtins import next
from builtins import range
from builtins import object

from . import DataId


class ButlerSubset(object):
class ButlerSubset:

"""ButlerSubset is a container for ButlerDataRefs. It represents a
collection of data ids that can be used to obtain datasets of the type
Expand Down Expand Up @@ -130,7 +127,7 @@ def __iter__(self):
return ButlerSubsetIterator(self)


class ButlerSubsetIterator(object):
class ButlerSubsetIterator:
"""
An iterator over the ButlerDataRefs in a ButlerSubset.
"""
Expand All @@ -146,7 +143,7 @@ def __next__(self):
return ButlerDataRef(self.butlerSubset, next(self.iter))


class ButlerDataRef(object):
class ButlerDataRef:
"""
A ButlerDataRef is a reference to a potential dataset or group of datasets
that is portable between compatible dataset types. As such, it can be
Expand Down
12 changes: 2 additions & 10 deletions python/lsst/daf/persistence/dataId.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from past.builtins import basestring

# On Python 3 collections.UserDict is iterable but on Python 2
# we have to use UserDict.IterableUserDict. Since collections.UserDict
# exists on Python 2 we try the Python 2 variant first.
try:
from UserDict import IterableUserDict as UserDict
except ImportError:
from collections import UserDict
from collections import UserDict

import copy

Expand Down Expand Up @@ -59,7 +51,7 @@ def __init__(self, initialdata=None, tag=None, **kwargs):
self.tag = set()

if tag is not None:
if isinstance(tag, basestring):
if isinstance(tag, str):
self.tag.update([tag])
else:
try:
Expand Down
5 changes: 1 addition & 4 deletions python/lsst/daf/persistence/fsScanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@


"""This module provides the FsScanner class."""
from __future__ import print_function
from builtins import range
from builtins import object

import glob
import os
import re
import sys


class FsScanner(object):
class FsScanner:
"""Class to scan a filesystem location for paths matching a template.

Decomposes the resulting paths into fields and passes them to a callback
Expand Down
5 changes: 1 addition & 4 deletions python/lsst/daf/persistence/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import object, super


from . import Policy

"""This module defines the Mapper base class."""


class Mapper(object):
class Mapper:
"""Mapper is a base class for all mappers.

Subclasses may define the following methods:
Expand Down
27 changes: 9 additions & 18 deletions python/lsst/daf/persistence/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import str
from past.builtins import basestring
from future.utils import with_metaclass

import collections
import collections.abc
import copy
import os
import sys
import warnings
import yaml

Expand All @@ -39,20 +34,16 @@
from yaml.representer import Representer
yaml.add_representer(collections.defaultdict, Representer.represent_dict)


# UserDict and yaml have defined metaclasses and Python 3 does not allow multiple
# inheritance of classes with distinct metaclasses. We therefore have to
# create a new baseclass that Policy can inherit from. This is because the metaclass
# syntax differs between versions
# create a new baseclass that Policy can inherit from.
class _PolicyMeta(type(collections.UserDict), type(yaml.YAMLObject)):
pass

if sys.version_info[0] >= 3:
class _PolicyMeta(type(collections.UserDict), type(yaml.YAMLObject)):
pass

class _PolicyBase(with_metaclass(_PolicyMeta, collections.UserDict, yaml.YAMLObject)):
pass
else:
class _PolicyBase(collections.UserDict, yaml.YAMLObject):
pass
class _PolicyBase(collections.UserDict, yaml.YAMLObject, metaclass=_PolicyMeta):
pass


class Policy(_PolicyBase):
Expand Down Expand Up @@ -84,7 +75,7 @@ def __init__(self, other=None):
self.update(other)
elif isinstance(other, Policy):
self.data = copy.deepcopy(other.data)
elif isinstance(other, basestring):
elif isinstance(other, str):
# if other is a string, assume it is a file path.
self.__initFromFile(other)
elif isinstance(other, pexPolicy.Policy):
Expand Down Expand Up @@ -293,7 +284,7 @@ def asArray(self, name):
:return:
"""
val = self.get(name)
if isinstance(val, basestring):
if isinstance(val, str):
val = [val]
elif not isinstance(val, collections.abc.Container):
val = [val]
Expand Down Expand Up @@ -373,7 +364,7 @@ def getStringArray(self, key):
"""
warnings.warn("Deprecated. Use asArray()", DeprecationWarning)
val = self.get(key)
if isinstance(val, basestring):
if isinstance(val, str):
val = [val]
elif not isinstance(val, collections.abc.Container):
val = [val]
Expand Down
9 changes: 4 additions & 5 deletions python/lsst/daf/persistence/posixStorage.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 past.builtins import basestring
import sys
import pickle
import importlib
Expand Down Expand Up @@ -528,7 +527,7 @@ def readConfigStorage(butlerLocation):
raise RuntimeError("No such config file: " + logLoc.locString())
pythonType = butlerLocation.getPythonType()
if pythonType is not None:
if isinstance(pythonType, basestring):
if isinstance(pythonType, str):
pythonType = doImport(pythonType)
finalItem = pythonType()
finalItem.load(logLoc.locString())
Expand Down Expand Up @@ -573,7 +572,7 @@ def readFitsStorage(butlerLocation):
"""
pythonType = butlerLocation.getPythonType()
if pythonType is not None:
if isinstance(pythonType, basestring):
if isinstance(pythonType, str):
pythonType = doImport(pythonType)
supportsOptions = hasattr(pythonType, "readFitsWithOptions")
if not supportsOptions:
Expand Down Expand Up @@ -664,7 +663,7 @@ def readParquetStorage(butlerLocation):

pythonType = butlerLocation.getPythonType()
if pythonType is not None:
if isinstance(pythonType, basestring):
if isinstance(pythonType, str):
pythonType = doImport(pythonType)

filename = logLoc.locString()
Expand Down Expand Up @@ -779,7 +778,7 @@ def readFitsCatalogStorage(butlerLocation):
"""
pythonType = butlerLocation.getPythonType()
if pythonType is not None:
if isinstance(pythonType, basestring):
if isinstance(pythonType, str):
pythonType = doImport(pythonType)
results = []
additionalData = butlerLocation.getAdditionalData()
Expand Down
2 changes: 0 additions & 2 deletions python/lsst/daf/persistence/readProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

"""This module defines the ReadProxy class."""

from __future__ import absolute_import

from .persistence import ReadProxyBase


Expand Down