Skip to content

Commit

Permalink
Update flake8 linting to include documentation standard lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Nov 1, 2019
1 parent d2b89a4 commit d64fef8
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 41 deletions.
7 changes: 4 additions & 3 deletions python/lsst/pex/config/callStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def getCallerFrame(relative=0):
Parameters
----------
relative : `int`, optional
Number of frames (0 or more) above the caller to retrieve. Default is 0.
Number of frames (0 or more) above the caller to retrieve.
Default is 0.
Returns
-------
Expand Down Expand Up @@ -157,8 +158,8 @@ def format(self, full=False):
Parameters
----------
full : `bool`, optional
If `True`, output includes the conentent (`StackFrame.content`) being executed. Default
is `False`.
If `True`, output includes the conentent (`StackFrame.content`)
being executed. Default is `False`.
Returns
-------
Expand Down
16 changes: 10 additions & 6 deletions python/lsst/pex/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ def save(self, outfile, instance):
if self.deprecated and value == self.default:
return

# write full documentation string as comment lines (i.e. first character is #)
# write full documentation string as comment lines
# (i.e. first character is #)
doc = "# " + str(self.doc).replace("\n", "\n# ")
if isinstance(value, float) and (math.isinf(value) or math.isnan(value)):
# non-finite numbers need special care
Expand Down Expand Up @@ -868,7 +869,8 @@ def __reduce__(self):
since it may contain lambdas (as the ``check`` elements) that cannot
be pickled.
"""
# The stream must be in characters to match the API but pickle requires bytes
# The stream must be in characters to match the API but pickle
# requires bytes
stream = io.StringIO()
self.saveToStream(stream)
return (unreduceConfig, (self.__class__, stream.getvalue().encode()))
Expand Down Expand Up @@ -1021,7 +1023,8 @@ def loadFromStream(self, stream, root="config", filename=None):
except NameError as e:
if root == "config" and "root" in e.args[0]:
if filename is None:
# try to determine the file name; a compiled string has attribute "co_filename",
# try to determine the file name; a compiled string
# has attribute "co_filename",
# an open file has attribute "name", else give up
filename = getattr(stream, "co_filename", None)
if filename is None:
Expand Down Expand Up @@ -1128,9 +1131,10 @@ def _save(self, outfile):
def _collectImports(self):
"""Adds module containing self to the list of things to import and
then loops over all the fields in the config calling a corresponding
collect method. The field method will call _collectImports on any configs
it may own and return the set of things to import. This returned set
will be merged with the set of imports for this config class.
collect method. The field method will call _collectImports on any
configs it may own and return the set of things to import. This
returned set will be merged with the set of imports for this config
class.
"""
self._imports.add(self.__module__)
for name, field in self._fields.items():
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/pex/config/configChoiceField.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ class ConfigChoiceField(Field):
(If the config instance allows multiple selections, you'd assign a sequence
to the ``names`` attribute instead.)
``ConfigChoiceField`` instances also allow multiple values of the same type:
``ConfigChoiceField`` instances also allow multiple values of the same
type:
>>> TYPEMAP["CCC"] = AaaConfig
>>> TYPEMAP["BBB"] = AaaConfig
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/pex/config/configDictField.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ def _compare(self, instance1, instance2, shortcut, rtol, atol, output):
atol : `float`
Absolute tolerance for floating point comparisons.
output : callable
A callable that takes a string, used (possibly repeatedly) to report inequalities.
A callable that takes a string, used (possibly repeatedly) to
report inequalities.
Returns
-------
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/pex/config/configField.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ def _compare(self, instance1, instance2, shortcut, rtol, atol, output):
atol : `float`
Absolute tolerance for floating point comparisons.
output : callable
A callable that takes a string, used (possibly repeatedly) to report inequalities.
A callable that takes a string, used (possibly repeatedly) to
report inequalities.
Returns
-------
Expand Down
6 changes: 4 additions & 2 deletions python/lsst/pex/config/configurableField.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ def __getattr__(self, name):
def __setattr__(self, name, value, at=None, label="assignment"):
"""Pretend to be an instance of ConfigClass.
Attributes defined by ConfigurableInstance will shadow those defined in ConfigClass
Attributes defined by ConfigurableInstance will shadow those defined
in ConfigClass
"""
if self._config._frozen:
raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
Expand All @@ -151,7 +152,8 @@ def __setattr__(self, name, value, at=None, label="assignment"):
def __delattr__(self, name, at=None, label="delete"):
"""
Pretend to be an isntance of ConfigClass.
Attributes defiend by ConfigurableInstance will shadow those defined in ConfigClass
Attributes defiend by ConfigurableInstance will shadow those defined
in ConfigClass
"""
if self._config._frozen:
raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/pex/config/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class Color:
text : `str`
Text content to print to a terminal.
category : `str`
Semantic category of the ``text``. See `categories` for possible values.
Semantic category of the ``text``. See `categories` for possible
values.
Raises
------
Expand Down
23 changes: 14 additions & 9 deletions python/lsst/pex/config/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ def makeConfigClass(ctrl, name=None, base=Config, doc=None, module=None, cls=Non
// myHeader.h
struct InnerControl {
LSST_CONTROL_FIELD(wim, std::string, "documentation for field 'wim'");
LSST_CONTROL_FIELD(wim, std::string,
"documentation for field 'wim'");
};
struct FooControl {
LSST_CONTROL_FIELD(bar, int, "documentation for field 'bar'");
LSST_CONTROL_FIELD(baz, double, "documentation for field 'baz'");
LSST_NESTED_CONTROL_FIELD(zot, myWrappedLib, InnerControl, "documentation for field 'zot'");
LSST_NESTED_CONTROL_FIELD(zot, myWrappedLib, InnerControl,
"documentation for field 'zot'");
FooControl() : bar(0), baz(0.0) {}
};
Expand Down Expand Up @@ -155,8 +157,9 @@ def makeConfigClass(ctrl, name=None, base=Config, doc=None, module=None, cls=Non
if cls is None:
cls = type(name, (base,), {"__doc__": doc})
if module is not None:
# Not only does setting __module__ make Python pretty-printers more useful,
# it's also necessary if we want to pickle Config objects.
# Not only does setting __module__ make Python pretty-printers
# more useful, it's also necessary if we want to pickle Config
# objects.
if isinstance(module, int):
frame = getCallerFrame(module)
moduleObj = inspect.getmodule(frame)
Expand All @@ -177,8 +180,8 @@ def makeConfigClass(ctrl, name=None, base=Config, doc=None, module=None, cls=Non
if doc is None:
doc = ctrl.__doc__
fields = {}
# loop over all class attributes, looking for the special static methods that indicate a field
# defined by one of the macros in pex/config.h.
# loop over all class attributes, looking for the special static methods
# that indicate a field defined by one of the macros in pex/config.h.
for attr in dir(ctrl):
if attr.startswith("_type_"):
k = attr[len("_type_"):]
Expand Down Expand Up @@ -213,8 +216,9 @@ def makeConfigClass(ctrl, name=None, base=Config, doc=None, module=None, cls=Non
raise TypeError("Could not parse field type '%s'." % ctype)
fields[k] = FieldCls(doc=doc, dtype=dtype, optional=True)

# Define a number of methods to put in the new Config class. Note that these are "closures";
# they have access to local variables defined in the makeConfigClass function (like the fields dict).
# Define a number of methods to put in the new Config class. Note that
# these are "closures"; they have access to local variables defined in
# the makeConfigClass function (like the fields dict).
def makeControl(self):
"""Construct a C++ Control object from this Config object.
Expand Down Expand Up @@ -275,7 +279,8 @@ def setDefaults(self):
super(cls, self).setDefaults()
try:
r = self.Control()
# Indicate in the history that these values came from C++, even if we can't say which line
# Indicate in the history that these values came from C++, even
# if we can't say which line
self.readControl(r, __at=[(ctrl.__name__ + " C++", 0, "setDefaults", "")], __label="defaults",
__reset=True)
except Exception:
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# if there are later changes to the developer guide standard.
[flake8]
max-line-length = 110
max-doc-length = 79
ignore = E133, E226, E228, N802, N803, N806, N812, N815, N816, W504
exclude =
bin,
Expand Down
13 changes: 8 additions & 5 deletions tests/test_Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ class Cfg1(pexConfig.Config):
inclusiveMax=inclusiveMax)
Cfg1()
else:
# raise while constructing the RangeField (hence cannot make it part of a Config)
# raise while constructing the RangeField (hence cannot make
# it part of a Config)
self.assertRaises(ValueError, pexConfig.RangeField, doc="", dtype=int,
default=val, min=val, max=val, inclusiveMin=inclusiveMin,
inclusiveMax=inclusiveMax)
Expand Down Expand Up @@ -259,7 +260,8 @@ def testSave(self):
self.assertEqual(self.comp.c.f, roundTrip.c.f)
self.assertEqual(self.comp.r.name, roundTrip.r.name)

# test backwards compatibility feature of allowing "root" instead of "config"
# test backwards compatibility feature of allowing "root" instead of
# "config"
outfile = open("roundtrip.test", "w")
self.comp.saveToStream(outfile, root="root")
outfile.close()
Expand Down Expand Up @@ -464,16 +466,17 @@ def outFunc(msg):
self.assertFalse(self.outer.compare(self.inner))

def testLoadError(self):
"""Check that loading allows errors in the file being loaded to propagate
"""Check that loading allows errors in the file being loaded to
propagate.
"""
self.assertRaises(SyntaxError, self.simple.loadFromStream, "bork bork bork")
self.assertRaises(NameError, self.simple.loadFromStream, "config.f = bork")

def testNames(self):
"""Check that the names() method returns valid keys
"""Check that the names() method returns valid keys.
Also check that we have the right number of keys, and as they are
all known to be valid we know that we got them all
all known to be valid we know that we got them all.
"""

names = self.simple.names()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_configDictField.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def testNoArbitraryAttributes(self):
def testEquality(self):
"""Test ConfigDictField.__eq__
We create two configs, with the keys explicitly added in a different order
and test their equality.
We create two configs, with the keys explicitly added in a different
order and test their equality.
"""
keys1 = ['A', 'B', 'C']
keys2 = ['X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e']
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dictField.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def testNoArbitraryAttributes(self):
def testEquality(self):
"""Test DictField.__eq__
We create two dicts, with the keys explicitly added in a different order
and test their equality.
We create two dicts, with the keys explicitly added in a different
order and test their equality.
"""
keys1 = ['A', 'B', 'C']
keys2 = ['X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e']
Expand Down
4 changes: 2 additions & 2 deletions tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def testHistory(self):
output = b.formatHistory("a", writeSourceLine=False)

# The history differs depending on how the tests are executed and might
# depend on pytest internals. We therefore test the output for the presence
# of strings that we know should be there.
# depend on pytest internals. We therefore test the output for the
# presence of strings that we know should be there.

# For reference, this is the output from running with unittest.main()
"""a
Expand Down
6 changes: 4 additions & 2 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

class ConfigTest(unittest.TestCase):
def setUp(self):
"""Note: the classes are defined here in order to test the register decorator
"""Note: the classes are defined here in order to test the register
decorator.
"""
class ParentConfig(pexConfig.Config):
pass
Expand Down Expand Up @@ -105,7 +106,8 @@ def testReplace(self):
self.assertEqual(self.registry["foo1"], self.fooAlg1Class)

def testNesting(self):
"""Make sure nesting a config with a RegistryField doesn't deep-copy the registry."""
"""Make sure nesting a config with a RegistryField doesn't deep-copy
the registry."""
class MidConfig(pexConfig.Config):
field = self.registry.makeField("docs for registry field")

Expand Down
12 changes: 8 additions & 4 deletions tests/test_wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def testMakeControl(self):
self.assertTrue(testLib.checkControl(control, config.foo, config.bar.list()))

def testReadControl(self):
"""Test reading the values from a C++ Control object into a Config object."""
"""Test reading the values from a C++ Control object into a Config
object."""
control = testLib.ControlObject()
control.foo = 3
control.bar = ["zot", "yox"]
Expand All @@ -51,7 +52,8 @@ def testReadControl(self):
self.assertTrue(testLib.checkControl(control, config.foo, config.bar.list()))

def testDefaults(self):
"""Test that C++ Control object defaults are correctly used as defaults for Config objects."""
"""Test that C++ Control object defaults are correctly used as defaults
for Config objects."""
config = testLib.ConfigObject()
control = testLib.ControlObject()
self.assertTrue(testLib.checkControl(control, config.foo, config.bar.list()))
Expand All @@ -77,7 +79,8 @@ def testMakeControl(self):
self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b))

def testReadControl(self):
"""Test reading the values from a C++ Control object into a Config object."""
"""Test reading the values from a C++ Control object into a Config
object."""
control = testLib.OuterControlObject()
control.a.p = 6.0
control.a.q = 4
Expand All @@ -87,7 +90,8 @@ def testReadControl(self):
self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b))

def testDefaults(self):
"""Test that C++ Control object defaults are correctly used as defaults for Config objects."""
"""Test that C++ Control object defaults are correctly used as defaults
for Config objects."""
config = testLib.OuterConfigObject()
control = testLib.OuterControlObject()
self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b))
Expand Down

0 comments on commit d64fef8

Please sign in to comment.