Skip to content

Commit

Permalink
Final flake8 fixes (#239)
Browse files Browse the repository at this point in the history
* flake8 apptools.naming

* flake8 etstool.py

* examples already flake8 clean

* Update apptools/naming/dynamic_context.py

Co-authored-by: Poruri Sai Rahul <rporuri@enthought.com>

* apply suggestions from code review

Co-authored-by: Poruri Sai Rahul <rporuri@enthought.com>
  • Loading branch information
aaronayres35 and Poruri Sai Rahul committed Nov 25, 2020
1 parent 9875e18 commit f65158e
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 49 deletions.
27 changes: 26 additions & 1 deletion apptools/naming/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,29 @@
preferences. Part of the AppTools project of the Enthought Tool Suite.
"""
from apptools.naming.api import *
from .exception import NamingError, InvalidNameError, NameAlreadyBoundError
from .exception import NameNotFoundError, NotContextError
from .exception import OperationNotSupportedError

from .address import Address
from .binding import Binding
from .context import Context
from .dynamic_context import DynamicContext
from .dir_context import DirContext
from .initial_context import InitialContext
from .initial_context_factory import InitialContextFactory
from .naming_event import NamingEvent
from .naming_manager import naming_manager
from .object_factory import ObjectFactory
from .object_serializer import ObjectSerializer
from .py_context import PyContext
from .py_object_factory import PyObjectFactory
from .pyfs_context import PyFSContext
from .pyfs_context_factory import PyFSContextFactory
from .pyfs_initial_context_factory import PyFSInitialContextFactory
from .pyfs_object_factory import PyFSObjectFactory
from .pyfs_state_factory import PyFSStateFactory
from .reference import Reference
from .referenceable import Referenceable
from .referenceable_state_factory import ReferenceableStateFactory
from .state_factory import StateFactory
7 changes: 2 additions & 5 deletions apptools/naming/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@


# Enthought library imports.
from traits.api import Any, Dict, Event, HasTraits, Instance
from traits.api import Any, Dict, Event, HasTraits
from traits.api import Property, Str

# Local imports.
from .binding import Binding
from .exception import InvalidNameError, NameAlreadyBoundError
from .exception import NameNotFoundError, NotContextError
from .exception import OperationNotSupportedError
from .naming_event import NamingEvent
from .naming_manager import naming_manager
from .object_factory import ObjectFactory
from .state_factory import StateFactory
from .unique_name import make_unique_name


Expand Down Expand Up @@ -703,7 +700,7 @@ def _search(self, obj, names, path, searched):

if (
isinstance(binding.obj, Context)
and not binding.obj in searched
and binding.obj not in searched
):
path.append(binding.name)
searched[binding.obj] = True
Expand Down
2 changes: 1 addition & 1 deletion apptools/naming/dir_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# Local imports.
from .context import Context
from .exception import NameNotFoundError, NotContextError
from .exception import NameNotFoundError


class DirContext(Context):
Expand Down
4 changes: 2 additions & 2 deletions apptools/naming/dynamic_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _is_context(self, name):
item = self._get_contributed_context_item(name)
if item != (None, None):
obj, trait = item
result = True == trait.is_context
result = trait.is_context is True
else:
result = False

Expand Down Expand Up @@ -168,7 +168,7 @@ def _get_contributed_context_items(self):
traits = [(t.context_order, n, t) for n, t in traits.items()]
traits.sort()

# Convert these trait definitions into a list of name and object tuples.
# Convert these trait definitions into a list of name and object tuples
result = [
(t.context_name, getattr(self, n), t) for order, n, t in traits
]
Expand Down
2 changes: 1 addition & 1 deletion apptools/naming/object_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def load(self, path):
f = open(path, "rb")
try:
try:
obj = VersionedUnpickler(f).load()
obj = VersionedUnpickler(f).load()
except Exception as ex:
print_exc()
logger.exception(
Expand Down
5 changes: 2 additions & 3 deletions apptools/naming/pyfs_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from .binding import Binding
from .context import Context
from .dir_context import DirContext
from .exception import NameNotFoundError, NotContextError
from .naming_event import NamingEvent
from .naming_manager import naming_manager
from .object_serializer import ObjectSerializer
Expand Down Expand Up @@ -152,7 +151,7 @@ def _get_namespace_name(self):
if "root" in self.environment:
root = self.environment["root"]

namespace_name = self.path[len(root) + 1 :]
namespace_name = self.path[len(root) + 1:]

else:
namespace_name = self.path
Expand Down Expand Up @@ -232,7 +231,7 @@ def _lookup(self, name):
# If the load fails then we create a generic file resource
# (the idea being that it might be useful to have access to
# the file to see what went wrong).
except:
except: # noqa: E722
state = File(path)
logger.exception("Error loading resource at %s" % path)

Expand Down
2 changes: 1 addition & 1 deletion apptools/naming/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


# Enthought library imports.
from traits.api import Any, HasPrivateTraits, List, Str
from traits.api import HasPrivateTraits, List, Str

# Local imports.
from .address import Address
Expand Down
12 changes: 10 additions & 2 deletions apptools/naming/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
import unittest

# Enthought library imports.
from apptools.naming.api import *
from apptools.naming.api import (
Context,
InvalidNameError,
NameAlreadyBoundError,
NameNotFoundError,
NotContextError,
ObjectFactory,
StateFactory,
)


class ContextTestCase(unittest.TestCase):
Expand Down Expand Up @@ -480,7 +488,7 @@ def test_search(self):
# Convenience.
context = self.context
sub = self.context.lookup("sub")
sub_sibling = context.create_subcontext("sub sibling")
context.create_subcontext("sub sibling")
sub_sub = sub.create_subcontext("sub sub")

context.bind("one", 1)
Expand Down
6 changes: 5 additions & 1 deletion apptools/naming/tests/test_dir_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@


# Enthought library imports.
from apptools.naming.api import *
from apptools.naming.api import (
DirContext,
NameNotFoundError,
NotContextError,
)

# Local imports.
from .test_context import ContextTestCase
Expand Down
1 change: 1 addition & 0 deletions apptools/naming/tests/test_object_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class FooWithTraits(HasTraits):
def _get_last_name(self):
return self.full_name.split(" ")[-1]


class TestObjectSerializer(unittest.TestCase):

def setUp(self):
Expand Down
29 changes: 17 additions & 12 deletions apptools/naming/tests/test_pyfs_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@


# Standard library imports.
import os, shutil, unittest
import os
import shutil
import unittest

# Enthought library imports.
from apptools.io import File
from apptools.naming.api import *
from apptools.naming.api import (
DirContext,
InvalidNameError,
NameAlreadyBoundError,
NameNotFoundError,
NotContextError,
PyFSContext,
)


class PyFSContextTestCase(unittest.TestCase):
Expand All @@ -32,14 +41,10 @@ class PyFSContextTestCase(unittest.TestCase):
def setUp(self):
""" Prepares the test fixture before each test method is called. """

try:
if os.path.exists("data"):
shutil.rmtree("data")
if os.path.exists("other"):
shutil.rmtree("other")

except:
pass
if os.path.exists("data"):
shutil.rmtree("data", ignore_errors=True)
if os.path.exists("other"):
shutil.rmtree("other", ignore_errors=True)

os.mkdir("data")
os.mkdir("other")
Expand Down Expand Up @@ -248,7 +253,7 @@ def test_create_subcontext(self):
self.assertRaises(InvalidNameError, context.create_subcontext, "")

# Create a sub-context.
a = context.create_subcontext("sub/a")
context.create_subcontext("sub/a")
self.assertEqual(len(sub.list_bindings("")), 1)
self.assertTrue(os.path.isdir(os.path.join(sub.path, "a")))

Expand All @@ -273,7 +278,7 @@ def test_destroy_subcontext(self):
self.assertRaises(InvalidNameError, context.destroy_subcontext, "")

# Create a sub-context.
a = context.create_subcontext("sub/a")
context.create_subcontext("sub/a")
self.assertEqual(len(sub.list_bindings("")), 1)

# Destroy it.
Expand Down
2 changes: 1 addition & 1 deletion apptools/naming/trait_defs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# Imports:
# ------------------------------------------------------------------------------

from apptools.naming.trait_defs.api import *
from .naming_traits import NamingInstance
22 changes: 10 additions & 12 deletions apptools/naming/trait_defs/naming_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

from traits.trait_base import class_of, get_module_name

from traitsui.api import DropEditor

from apptools.naming.api import Binding


Expand Down Expand Up @@ -56,7 +54,7 @@ class NamingTraitHandler(TraitHandler):

def __init__(self, aClass, or_none, module):
"""Initializes the object."""
self.or_none = or_none != False
self.or_none = or_none is not False
self.module = module
self.aClass = aClass
if (aClass is not None) and (
Expand All @@ -73,7 +71,7 @@ def validate(self, object, name, value):
self.validate_failed(object, name, value)
try:
value = self._get_binding_for(value)
except:
except: # noqa: E722
self.validate_failed(object, name, value)

if isinstance(self.aClass, str):
Expand Down Expand Up @@ -123,10 +121,10 @@ def _get_binding_for(self, value):

result = None

# FIXME: The following code makes this whole component have a dependency
# on envisage, and worse, assumes the use of a particular project
# plugin! This is horrible and should be refactored out, possibly to
# a custom sub-class of whoever needs this behavior.
# FIXME: The following code makes this whole component have a
# dependency on envisage, and worse, assumes the use of a particular
# project plugin! This is horrible and should be refactored out,
# possibly to a custom sub-class of whoever needs this behavior.
try:
from envisage import get_application

Expand All @@ -146,8 +144,8 @@ def resolve_class(self, object, name, value):
self.aClass = aClass

# fixme: The following is quite ugly, because it wants to try and fix
# the trait referencing this handler to use the 'fast path' now that the
# actual class has been resolved. The problem is finding the trait,
# the trait referencing this handler to use the 'fast path' now that
# the actual class has been resolved. The problem is finding the trait,
# especially in the case of List(Instance('foo')), where the
# object.base_trait(...) value is the List trait, not the Instance
# trait, so we need to check for this and pull out the List
Expand All @@ -165,11 +163,11 @@ def find_class(self):
col = aClass.rfind(".")
if col >= 0:
module = aClass[:col]
aClass = aClass[col + 1 :]
aClass = aClass[col + 1:]
theClass = getattr(sys.modules.get(module), aClass, None)
if (theClass is None) and (col >= 0):
try:
theClass = getattr(__import__(module), aClass, None)
except:
except Exception:
pass
return theClass
10 changes: 8 additions & 2 deletions etstool.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def install(runtime, environment, source):
commands = [
"edm environments create {environment} --force --version={runtime}",
"edm install -y -e {environment} " + packages,
"edm run -e {environment} -- pip install -r ci-src-requirements.txt --no-dependencies",
"edm run -e {environment} -- pip install -r ci-src-requirements.txt"
" --no-dependencies",
"edm run -e {environment} -- python setup.py clean --all",
"edm run -e {environment} -- python setup.py develop"
]
Expand Down Expand Up @@ -213,6 +214,7 @@ def test(runtime, environment):
execute(commands, parameters)
click.echo('Done test')


@cli.command()
@click.option('--runtime', default=DEFAULT_RUNTIME)
@click.option('--environment', default=None)
Expand Down Expand Up @@ -240,6 +242,7 @@ def docs(runtime, environment):
commands = [apidoc_command, html_build_command]
execute(commands, parameters)


@cli.command()
@click.option('--runtime', default=DEFAULT_RUNTIME)
@click.option('--environment', default=None)
Expand Down Expand Up @@ -291,6 +294,7 @@ def test_clean(runtime):
finally:
cleanup(args=args, standalone_mode=False)


@cli.command()
@click.option('--runtime', default=DEFAULT_RUNTIME)
@click.option('--environment', default=None)
Expand Down Expand Up @@ -424,7 +428,9 @@ def get_parameters(runtime, environment):
""" Set up parameters dictionary for format() substitution """
parameters = {'runtime': runtime, 'environment': environment}
if environment is None:
parameters['environment'] = 'apptools-test-{runtime}'.format(**parameters)
parameters['environment'] = 'apptools-test-{runtime}'.format(
**parameters
)
return parameters


Expand Down
5 changes: 0 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
[flake8]
ignore = E266, W503
per-file-ignores = */api.py:F401, */__init__.py:F401
exclude =
# The following list should eventually be empty.
apptools/naming/*
etstool.py
examples/*

0 comments on commit f65158e

Please sign in to comment.