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-11664: Flake8 fixes #76

Merged
merged 6 commits into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from future import standard_library
standard_library.install_aliases()
from builtins import object

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

"""This module defines the Butler class."""
from future import standard_library
standard_library.install_aliases()
from builtins import str
from past.builtins import basestring
from builtins import object

import collections
import copy
import inspect
import json
import os
import weakref

import yaml

from lsst.log import Log
import lsst.pex.policy as pexPolicy
from . import LogicalLocation, ReadProxy, ButlerSubset, ButlerDataRef, Persistence, \
from . import ReadProxy, ButlerSubset, ButlerDataRef, Persistence, \
Storage, Policy, NoResults, Repository, DataId, RepositoryCfg, \
RepositoryArgs, listify, setify, sequencify, doImport, ButlerComposite, genericAssembler, \
genericDisassembler, PosixStorage, ParentsMismatch
Expand Down Expand Up @@ -1386,12 +1380,16 @@ def get(self, datasetType, dataId=None, immediate=True, **rest):

if hasattr(location, 'bypass'):
# this type loader block should get moved into a helper someplace, and duplications removed.
callback = lambda : location.bypass
def callback():
return location.bypass
else:
callback = lambda: self._read(location)
def callback():
return self._read(location)
if location.mapper.canStandardize(location.datasetType):
innerCallback = callback
callback = lambda: location.mapper.standardize(location.datasetType, innerCallback(), dataId)

def callback():
return location.mapper.standardize(location.datasetType, innerCallback(), dataId)
if immediate:
return callback()
return ReadProxy(callback)
Expand Down Expand Up @@ -1530,7 +1528,8 @@ def _read(self, location):
obj = self.get(componentInfo.datasetType, location.dataId, immediate=True)
componentInfo.obj = obj
assembler = location.assembler or genericAssembler
results = assembler(dataId=location.dataId, componentInfo=location.componentInfo, cls=location.python)
results = assembler(dataId=location.dataId, componentInfo=location.componentInfo,
cls=location.python)
return results
else:
results = location.repository.read(location)
Expand Down
4 changes: 1 addition & 3 deletions python/lsst/daf/persistence/butlerExceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from builtins import str
#!/usr/bin/env python

#
# LSST Data Management System
# Copyright 2016 LSST Corporation.
Expand All @@ -22,6 +19,7 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from builtins import str


class NoMapperException(Exception):
Expand Down
33 changes: 11 additions & 22 deletions python/lsst/daf/persistence/butlerLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import lsst.daf.base as dafBase

from collections import namedtuple
import os
from past.builtins import basestring
import yaml
Expand Down Expand Up @@ -55,7 +54,6 @@ class ButlerComposite(object):
A reference to the mapper that created this ButlerComposite object.
"""


class ComponentInfo():
"""Information about a butler composite object. Some details come from the policy and some are filled
in by the butler. Component info is used while assembling and disassembling a composite object in
Expand Down Expand Up @@ -89,23 +87,18 @@ def __init__(self, datasetType, obj, setter, getter, subset, inputOnly):

def __repr__(self):
return 'ComponentInfo(datasetType:%s, obj:%s, setter:%s, getter:%s, subset:%s)' % \
(self.datasetType, self.obj, self.setter, self.getter, self.subset)

(self.datasetType, self.obj, self.setter, self.getter, self.subset)

def __repr__(self):
return 'ButlerComposite(assembler:%s, disassembler:%s, python:%s, dataId:%s, mapper:%s, componentInfo:%s, repository:%s)' % \
(self.assembler,
self.disassembler,
self.python,
self.dataId,
self.mapper,
self.componentInfo,
self.repository)

def __repr__(self):
return "ComponentInfo(datasetType=%s, obj=%s, setter=%s, getter=%s)" % (
self.datasetType, self.obj, self.setter, self.getter)

return 'ButlerComposite(assembler:%s, disassembler:%s, python:%s, dataId:%s, mapper:%s, ' \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of the three, I kept this one as it looked the most detailed.

'componentInfo:%s, repository:%s)' % \
(self.assembler,
self.disassembler,
self.python,
self.dataId,
self.mapper,
self.componentInfo,
self.repository)

def __init__(self, assembler, disassembler, python, dataId, mapper):
self.assembler = doImport(assembler) if isinstance(assembler, basestring) else assembler
Expand Down Expand Up @@ -137,16 +130,12 @@ def add(self, id, datasetType, setter, getter, subset, inputOnly):
If true, indicates that the obj should not be serialized when performing a butler.put.
"""
self.componentInfo[id] = ButlerComposite.ComponentInfo(datasetType=datasetType,
obj = None,
obj=None,
setter=setter,
getter=getter,
subset=subset,
inputOnly=inputOnly)

def __repr__(self):
return "ButlerComposite(assembler=%s, disassembler=%s, python=%s, dataId=%s, components=%s)" % (
self.assembler, self.disassembler, self.python, self.dataId, self.componentInfo)

def setRepository(self, repository):
self.repository = repository

Expand Down
2 changes: 0 additions & 2 deletions python/lsst/daf/persistence/fmtPosixRepositoryCfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@

import copy
import errno
import fcntl
import yaml
import os
import urllib
from . import PosixStorage, RepositoryCfg, safeFileIo, ParentsMismatch
from lsst.log import Log


class RepositoryCfgPosixFormatter():
Expand Down
1 change: 0 additions & 1 deletion python/lsst/daf/persistence/genericAssembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

import inspect

def genericAssembler(dataId, componentInfo, cls):
"""A generic assembler for butler composite datasets, that can be used when the component names match the
Expand Down
2 changes: 0 additions & 2 deletions python/lsst/daf/persistence/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#
from builtins import object

import yaml

from . import Policy

Expand Down Expand Up @@ -166,7 +165,6 @@ class may raise a lsst.daf.persistence.NoResults exception. Butler
func = getattr(self, 'map_' + datasetType)
return func(self.validate(dataId), write)


def canStandardize(self, datasetType):
"""Return true if this mapper can standardize an object of the given
dataset type."""
Expand Down
8 changes: 3 additions & 5 deletions python/lsst/daf/persistence/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from builtins import str
from past.builtins import basestring
from future.utils import with_metaclass
from future.standard_library import install_aliases
install_aliases()

import collections
import copy
Expand All @@ -34,12 +32,12 @@
import warnings
import yaml

from yaml.representer import Representer
yaml.add_representer(collections.defaultdict, Representer.represent_dict)

import lsst.pex.policy as pexPolicy
import lsst.utils

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
Expand Down
16 changes: 6 additions & 10 deletions python/lsst/daf/persistence/posixStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,20 @@
#
from past.builtins import basestring
import sys
import copy
import pickle
import importlib
import os
import urllib.parse
import glob
import shutil
import fcntl

import yaml

from . import (LogicalLocation, Persistence, Policy, StorageList,
StorageInterface, Storage, ButlerLocation,
NoRepositroyAtRoot, RepositoryCfg)
from lsst.log import Log
import lsst.pex.policy as pexPolicy
from .safeFileIo import SafeFilename, safeMakeDir
from future import standard_library
standard_library.install_aliases()


class PosixStorage(StorageInterface):
"""Defines the interface for a storage location on the local filesystem.
Expand Down Expand Up @@ -453,10 +448,10 @@ def v1RepoExists(root):
True if the repository at root exists, else False.
"""
return os.path.exists(root) and (
os.path.exists(os.path.join(root, "registry.sqlite3")) or
os.path.exists(os.path.join(root, "_mapper")) or
os.path.exists(os.path.join(root, "_parent"))
)
os.path.exists(os.path.join(root, "registry.sqlite3")) or
os.path.exists(os.path.join(root, "_mapper")) or
os.path.exists(os.path.join(root, "_parent"))
)

def copyFile(self, fromLocation, toLocation):
"""Copy a file from one location to another on the local filesystem.
Expand Down Expand Up @@ -615,5 +610,6 @@ def storageExists(uri):
"""
return os.path.exists(PosixStorage._pathFromURI(uri))


Storage.registerStorageClass(scheme='', cls=PosixStorage)
Storage.registerStorageClass(scheme='file', cls=PosixStorage)
2 changes: 2 additions & 0 deletions python/lsst/daf/persistence/readProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def __ipow__(self, ob):
def __rpow__(self, ob):
return pow(ob, self.__subject__)


get_callback = ReadProxy.__callback__.__get__
set_callback = ReadProxy.__callback__.__set__
get_cache = ReadProxy.__cache__.__get__
Expand All @@ -139,5 +140,6 @@ def __subject__(self, get_cache=get_cache, set_cache=set_cache):
set_cache(self, get_callback(self)())
return get_cache(self)


ReadProxy.__subject__ = property(__subject__, set_cache)
del __subject__
1 change: 0 additions & 1 deletion python/lsst/daf/persistence/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#
from __future__ import absolute_import

from builtins import object
from future import standard_library
import urllib.parse
from . import NoRepositroyAtRoot
Expand Down
4 changes: 0 additions & 4 deletions python/lsst/daf/persistence/test/testObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ def __lt__(self, other):
def __le__(self, other):
return self.data <= other.data

def __eq__(self, other):
return self.data == other.data

def __gt__(self, other):
return self.data > other.data

Expand Down Expand Up @@ -115,4 +112,3 @@ def set_foo(self, val):

def get_foo(self):
return self._foo

8 changes: 8 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 110
ignore = E133, E226, E228, N802, N803, N806
exclude = __init__.py

[tool:pytest]
addopts = --flake8
flake8-ignore = E133 E226 E228 N802 N803 N806
5 changes: 2 additions & 3 deletions tests/SConscript
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- python -*-
from lsst.sconsUtils import scripts
import os

ignoreList = ["cameraMapper.py", "pickleMapper.py"]

scripts.BasicSConscript.tests(ignoreList=ignoreList, noBuildList=['testLib.cc'])
scripts.BasicSConscript.tests(ignoreList=ignoreList, noBuildList=['testLib.cc'],
pyList=[])
scripts.BasicSConscript.pybind11(['testLib/testLib'], addUnderscore=False)

1 change: 0 additions & 1 deletion tests/cameraMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import re
import lsst.daf.persistence as dafPersist
import os


class CameraMapper(dafPersist.Mapper):
Expand Down
2 changes: 0 additions & 2 deletions tests/pickleMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import os
import lsst.daf.persistence as dafPersist

from testLib import TypeWithProxy, TypeWithoutProxy


class PickleMapper(dafPersist.Mapper):

Expand Down
6 changes: 4 additions & 2 deletions tests/testLib/testLibContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

from .testLib import TypeWithProxy, TypeWithoutProxy

@continueClass

@continueClass # noqa F811 redefinition
class TypeWithProxy:
def __reduce__(self):
return (TypeWithProxy, ())

@continueClass

@continueClass # noqa F811 redefinition
class TypeWithoutProxy:
def __reduce__(self):
return (TypeWithoutProxy, ())
1 change: 1 addition & 0 deletions tests/test_DbStorage_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class TestMemory(lsst.utils.tests.MemoryTestCase):
def setup_module(module):
lsst.utils.tests.init()


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()
1 change: 1 addition & 0 deletions tests/test_DbStorage_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class TestMemory(lsst.utils.tests.MemoryTestCase):
def setup_module(module):
lsst.utils.tests.init()


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()
1 change: 1 addition & 0 deletions tests/test_LogicalLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class TestMemory(lsst.utils.tests.MemoryTestCase):
def setup_module(module):
lsst.utils.tests.init()


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()