Skip to content

Commit

Permalink
Minor cleanups (mostly lint fixes).
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 232975361
  • Loading branch information
dhr committed Feb 18, 2019
1 parent 34ca917 commit 02117a0
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 36 deletions.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Copyright 2018 The Gin-Config Authors. All rights reserved.

Apache License
Version 2.0, January 2004
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Import Gin (without TensorFlow functionality):
import gin
```

Import Gin (with TensorFlow functionality):
Import additional TensorFlow-specific functionality via the TF module:

```python
import gin.tf
Expand Down
2 changes: 1 addition & 1 deletion docs/walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Import Gin (without TensorFlow functionality):
import gin
```

Import Gin (with TensorFlow functionality):
Import additional TensorFlow-specific functionality via the TF module:

```python
import gin.tf
Expand Down
6 changes: 3 additions & 3 deletions gin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ def drink(cocktail):

import enum

import six

from gin import config_parser
from gin import selector_map
from gin import utils

import six


# Maintains the registry of configurable functions and classes.
_REGISTRY = selector_map.SelectorMap()
Expand Down Expand Up @@ -1657,7 +1657,7 @@ def singleton_value(key, constructor=None):


def constant(name, value):
"""Creates a constant that can be referenced from Gin config files.
"""Creates a constant that can be referenced from gin config files.
After calling this function in Python, the constant can be referenced from
within a Gin config file using the macro syntax. For example, in Python:
Expand Down
4 changes: 2 additions & 2 deletions gin/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import re
import tokenize

import six

from gin import selector_map
from gin import utils

import six

# A regular expression matching a valid module identifier. A valid module
# identifier consists of one or more valid identifiers (see below), separated by
# periods (as in a Python module).
Expand Down
1 change: 1 addition & 0 deletions gin/tf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
"""Init file for TensorFlow-specific Gin package."""


# pylint: disable=unused-import
from gin.tf.utils import GinConfigSaverHook
4 changes: 2 additions & 2 deletions gin/tf/external_configurables.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

import functools

from gin import config

import numpy as np
import tensorflow as tf

from gin import config


# Learning rate decays.

Expand Down
5 changes: 4 additions & 1 deletion gin/tf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@

import os

from gin import config

import tensorflow as tf

from gin import config
# pylint: disable=g-direct-tensorflow-import
from tensorflow.core.framework import summary_pb2
# pylint: enable=g-direct-tensorflow-import


# Register TF file reader for Gin's parse_config_file.
Expand Down
1 change: 1 addition & 0 deletions gin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def augment_exception_message_and_reraise(exception, message):
"""Reraises `exception`, appending `message` to its string representation."""

class ExceptionProxy(type(exception)):
"""Acts as a proxy for an exception with an augmented message."""
__module__ = type(exception).__module__

def __init__(self):
Expand Down
10 changes: 5 additions & 5 deletions tests/config_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

from absl.testing import absltest

import six

from gin import config_parser

import six


def _generate_nested_value(max_depth=4, max_container_size=5):
def generate_int():
Expand Down Expand Up @@ -255,7 +255,7 @@ def testConfigurableReferences(self):

# Test a list of configurable references.
value = self._parse_value('[@ref1, @scoped/ref2, @ref3]')
self.assertEqual(len(value), 3)
self.assertLen(value, 3)
self.assertEqual(value[0].name, 'ref1')
self.assertFalse(value[0].evaluate)
self.assertEqual(value[1].name, 'scoped/ref2')
Expand All @@ -265,7 +265,7 @@ def testConfigurableReferences(self):

# Test mix of configurable references with output references.
value = self._parse_value('[@ref1(), @scoped/ref2(), @ref3]')
self.assertEqual(len(value), 3)
self.assertLen(value, 3)
self.assertEqual(value[0].name, 'ref1')
self.assertTrue(value[0].evaluate)
self.assertEqual(value[1].name, 'scoped/ref2')
Expand All @@ -277,7 +277,7 @@ def testConfigurableReferences(self):
@ref1
]"""
value = self._parse_value(multiline)
self.assertEqual(len(value), 1)
self.assertLen(value, 1)
self.assertEqual(value[0].name, 'ref1')
self.assertFalse(value[0].evaluate)

Expand Down
4 changes: 2 additions & 2 deletions tests/config_py3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#! python3. This invalid shebang is just here to disable the linter, which isn't
# yet compatible with Python 3.
# python3

from __future__ import absolute_import
from __future__ import division
Expand All @@ -34,6 +33,7 @@ class ConfigTest(absltest.TestCase):

def tearDown(self):
config.clear_config()
super(ConfigTest, self).tearDown()

def testKwOnlyArgs(self):
config_str = """
Expand Down
6 changes: 3 additions & 3 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
from absl.testing import absltest

import enum
import six

from gin import config
import six


_EXPECTED_OPERATIVE_CONFIG_STR = """
Expand Down Expand Up @@ -277,6 +276,7 @@ class ConfigTest(absltest.TestCase):

def tearDown(self):
config.clear_config()
super(ConfigTest, self).tearDown()

def testConfigurable(self):
config.bind_parameter('configurable1.kwarg1', 'value1')
Expand Down Expand Up @@ -740,7 +740,7 @@ def some_fn(only_one_arg=None):

@config.configurable('broken_function')
def borked_fn(arg): # pylint: disable=unused-variable
some_fn(**{'nonexistent_arg': arg})
some_fn(nonexistent_arg=arg) # pylint: disable=unexpected-keyword-arg

config.parse_config([
'configurable2.non_kwarg = @broken_function()',
Expand Down
6 changes: 3 additions & 3 deletions tests/selector_map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ def testPartiallyMatchingCompleteSelectors(self):
sm['specific.selector'] = 2
self.assertEqual(sm.get_match('specific.selector'), 2)
self.assertEqual(sm.get_match('more.specific.selector'), 1)
self.assertItemsEqual(sm.get_all_matches('selector'), [1, 2])
self.assertCountEqual(sm.get_all_matches('selector'), [1, 2])
# Because 'specific.selector' exactly matches an existing selector, it isn't
# ambiguous and `get_all_matches` only returns one value.
self.assertItemsEqual(sm.get_all_matches('specific.selector'), [2])
self.assertCountEqual(sm.get_all_matches('specific.selector'), [2])

# Try in the reverse order.
sm = selector_map.SelectorMap()
sm['specific.selector'] = 2
sm['more.specific.selector'] = 1
self.assertEqual(sm.get_match('more.specific.selector'), 1)
self.assertEqual(sm.get_match('specific.selector'), 2)
self.assertItemsEqual(sm.get_all_matches('selector'), [1, 2])
self.assertCountEqual(sm.get_all_matches('selector'), [1, 2])

self.assertEqual(
sm.minimal_selector('specific.selector'), 'specific.selector')
Expand Down
5 changes: 3 additions & 2 deletions tests/tf/config_py3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import gin.tf

import gin
import tensorflow as tf


class TFConfigPy3Test(tf.test.TestCase):

def tearDown(self):
gin.clear_config()
super(TFConfigPy3Test, self).tearDown()

def testAugmentExceptionMessageOnTFError(self):
@gin.configurable('config_name')
Expand Down
7 changes: 4 additions & 3 deletions tests/tf/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import gin.tf

import gin
import tensorflow as tf


class TFConfigTest(tf.test.TestCase):

def tearDown(self):
gin.clear_config()
super(TFConfigTest, self).tearDown()

def testAugmentExceptionMessageOnTFError(self):
@gin.configurable('config_name')
Expand All @@ -42,7 +43,7 @@ def broken(sess):
str(assert_raises.exception))
# Note that in Python3 (but not Python2) the function name will be in
# the exception message, which is caught with the '\S*'.
self.assertRegexpMatches(
self.assertRegex(
str(assert_raises.exception), r"'config_name' \(<function \S*broken")
self.assertEqual(assert_raises.exception.op.name, 'strided_slice')

Expand Down
8 changes: 3 additions & 5 deletions tests/tf/external_configurables_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
from __future__ import division
from __future__ import print_function

import tensorflow as tf

from gin import config
from gin.tf import external_configurables # pylint: disable=unused-import

# pylint: disable=unused-import
from gin.tf import external_configurables
# pylint: enable=unused-import
import tensorflow as tf

# Necessary for AdagradaDAOptimizer test.
config.external_configurable(tf.train.get_global_step)
Expand All @@ -46,6 +43,7 @@ class TFConfigTest(tf.test.TestCase):

def tearDown(self):
config.clear_config()
super(TFConfigTest, self).tearDown()

def testConfigureOptimizerAndLearningRate(self):
config_str = """
Expand Down
6 changes: 3 additions & 3 deletions tests/tf/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import os
import tempfile

from six.moves import zip
import tensorflow as tf

from gin import config
from gin.tf import utils

from six.moves import zip
import tensorflow as tf


@config.configurable
def configurable_fn(kwarg1=0, kwarg2=1): # pylint: disable=unused-argument
Expand Down

0 comments on commit 02117a0

Please sign in to comment.