diff --git a/.flake8 b/.flake8 index 1b0794e02..ae3e4d470 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,5 @@ [flake8] +max-line-length = 79 exclude = build -ignore = E266, W503 +ignore = E203, E266, W503 per-file-ignores = */api.py:F401 diff --git a/.github/workflows/check-style.yml b/.github/workflows/check-style.yml new file mode 100644 index 000000000..ec8eb07ca --- /dev/null +++ b/.github/workflows/check-style.yml @@ -0,0 +1,20 @@ +name: Run style checks + +on: [pull_request, workflow_dispatch] + +jobs: + style: + runs-on: 'ubuntu-latest' + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + cache: 'pip' + cache-dependency-path: '.github/workflows/style-requirements.txt' + - run: python -m pip install -r .github/workflows/style-requirements.txt + - run: | + python -m black --check --diff . + python -m isort --check --diff . + python -m flake8 . diff --git a/.github/workflows/style-requirements.txt b/.github/workflows/style-requirements.txt new file mode 100644 index 000000000..70f461dcc --- /dev/null +++ b/.github/workflows/style-requirements.txt @@ -0,0 +1,4 @@ +black ~= 23.0 +flake8 +flake8-ets +isort diff --git a/.github/workflows/test-with-edm.yml b/.github/workflows/test-with-edm.yml index e6816d450..4f362f7c0 100644 --- a/.github/workflows/test-with-edm.yml +++ b/.github/workflows/test-with-edm.yml @@ -45,9 +45,6 @@ jobs: run: python -m pip install -r .github/workflows/bootstrap-requirements.txt - name: Install test environment run: python etstool.py install --runtime=${{ matrix.runtime }} --toolkit=${{ matrix.toolkit }} - - name: Flake8 - run: python etstool.py flake8 --runtime=${{ matrix.runtime }} --toolkit=${{ matrix.toolkit }} - if: runner.os == 'Linux' && matrix.toolkit == 'null' - name: Run tests (Ubuntu) if: matrix.os == 'ubuntu-latest' run: xvfb-run -a python etstool.py test --runtime=${{ matrix.runtime }} --toolkit=${{ matrix.toolkit }} diff --git a/docs/source/conf.py b/docs/source/conf.py index 049e75e70..6dc1e3474 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -120,7 +120,7 @@ .. |Message| replace:: :github-demo:`Message ` .. |messages.py| replace:: :github-demo:`message.py ` .. |Message of the Day| replace:: :github-demo:`Message of the Day ` -""" # noqa: E501 +""" # noqa: E501 # Options for HTML output # ----------------------- @@ -234,7 +234,8 @@ # -- Options for extlinks extension ------------------------------------------- extlinks = { - 'github-demo': ( - f'https://github.com/enthought/envisage/tree/{version}/envisage/examples/demo/%s', # noqa: E501 - '') + "github-demo": ( + f"https://github.com/enthought/envisage/tree/{version}/envisage/examples/demo/%s", # noqa: E501 + "", + ) } diff --git a/envisage/api.py b/envisage/api.py index 8a498a614..bce27b546 100644 --- a/envisage/api.py +++ b/envisage/api.py @@ -66,6 +66,18 @@ """ +from .application import Application +from .core_plugin import CorePlugin +from .egg_plugin_manager import EggPluginManager +from .extension_point import ExtensionPoint +from .extension_point_binding import ( + bind_extension_point, + ExtensionPointBinding, + unbind_extension_point, +) +from .extension_point_changed_event import ExtensionPointChangedEvent +from .extension_provider import ExtensionProvider +from .extension_registry import ExtensionRegistry from .i_application import IApplication from .i_extension_point import IExtensionPoint from .i_extension_point_user import IExtensionPointUser @@ -76,19 +88,6 @@ from .i_plugin_activator import IPluginActivator from .i_plugin_manager import IPluginManager from .i_service_registry import IServiceRegistry - -from .application import Application -from .core_plugin import CorePlugin -from .egg_plugin_manager import EggPluginManager -from .extension_registry import ExtensionRegistry -from .extension_point import ExtensionPoint -from .extension_point_binding import ( - ExtensionPointBinding, - bind_extension_point, - unbind_extension_point, -) -from .extension_provider import ExtensionProvider -from .extension_point_changed_event import ExtensionPointChangedEvent from .ids import ( BINDINGS, COMMANDS, @@ -96,8 +95,8 @@ PREFERENCES_CATEGORIES, PREFERENCES_PANES, SERVICE_OFFERS, + TASK_EXTENSIONS, TASKS, - TASK_EXTENSIONS ) from .import_manager import ImportManager from .plugin import Plugin diff --git a/envisage/application.py b/envisage/application.py index 8cafc246a..66f025f35 100644 --- a/envisage/application.py +++ b/envisage/application.py @@ -15,31 +15,40 @@ import os # Enthought library imports. -from apptools.preferences.api import IPreferences, ScopedPreferences -from apptools.preferences.api import set_default_preferences +from apptools.preferences.api import ( + IPreferences, + ScopedPreferences, + set_default_preferences, +) from traits.api import ( - Delegate, Event, HasTraits, Instance, observe, provides, Str, VetoableEvent + Delegate, + Event, + HasTraits, + Instance, + observe, + provides, + Str, + VetoableEvent, ) from traits.etsconfig.api import ETSConfig +from .application_event import ApplicationEvent + # Local imports. from .i_application import IApplication from .i_extension_registry import IExtensionRegistry from .i_import_manager import IImportManager from .i_plugin_manager import IPluginManager from .i_service_registry import IServiceRegistry - -from .application_event import ApplicationEvent from .import_manager import ImportManager - # Logging. logger = logging.getLogger(__name__) @provides(IApplication) class Application(HasTraits): - """ An extensible, pluggable, application. + """An extensible, pluggable, application. This class handles the common case for non-GUI applications, and it is intended to be subclassed to change start/stop behaviour etc. @@ -113,7 +122,7 @@ class Application(HasTraits): ########################################################################### def __init__(self, plugins=None, **traits): - """ Constructor. + """Constructor. We allow the caller to specify an initial list of plugins, but the list itself is not part of the public API. To add and remove plugins after @@ -154,27 +163,28 @@ def __init__(self, plugins=None, **traits): #### Trait initializers ################################################### def _home_default(self): - """ Trait initializer. """ + """Trait initializer.""" return ETSConfig.application_home def _user_data_default(self): - """ Trait initializer. """ + """Trait initializer.""" return ETSConfig.user_data def _preferences_default(self): - """ Trait initializer. """ + """Trait initializer.""" return ScopedPreferences( application_preferences_filename=os.path.join( - self.home, 'preferences.ini') + self.home, "preferences.ini" + ) ) #### Methods ############################################################## def run(self): - """ Run the application. """ + """Run the application.""" if self.start(): self.stop() @@ -184,52 +194,48 @@ def run(self): ########################################################################### def add_extension_point_listener(self, listener, extension_point_id=None): - """ Add a listener for extensions being added/removed. """ + """Add a listener for extensions being added/removed.""" self.extension_registry.add_extension_point_listener( listener, extension_point_id ) def add_extension_point(self, extension_point): - """ Add an extension point. """ + """Add an extension point.""" self.extension_registry.add_extension_point(extension_point) def get_extensions(self, extension_point_id): - """ Return a list containing all contributions to an extension point. - - """ + """Return a list containing all contributions to an extension point.""" return self.extension_registry.get_extensions(extension_point_id) def get_extension_point(self, extension_point_id): - """ Return the extension point with the specified Id. """ + """Return the extension point with the specified Id.""" return self.extension_registry.get_extension_point(extension_point_id) def get_extension_points(self): - """ Return all extension points that have been added to the registry. - - """ + """Return all extension points that have been added to the registry.""" return self.extension_registry.get_extension_points() def remove_extension_point_listener( self, listener, extension_point_id=None ): - """ Remove a listener for extensions being added/removed. """ + """Remove a listener for extensions being added/removed.""" self.extension_registry.remove_extension_point_listener( listener, extension_point_id ) def remove_extension_point(self, extension_point_id): - """ Remove an extension point. """ + """Remove an extension point.""" self.extension_registry.remove_extension_point(extension_point_id) def set_extensions(self, extension_point_id, extensions): - """ Set the extensions contributed to an extension point. """ + """Set the extensions contributed to an extension point.""" self.extension_registry.set_extensions(extension_point_id, extensions) @@ -238,7 +244,7 @@ def set_extensions(self, extension_point_id, extensions): ########################################################################### def import_symbol(self, symbol_path): - """ Import the symbol defined by the specified symbol path. """ + """Import the symbol defined by the specified symbol path.""" return self._import_manager.import_symbol(symbol_path) @@ -247,27 +253,27 @@ def import_symbol(self, symbol_path): ########################################################################### def __iter__(self): - """ Return an iterator over the manager's plugins. """ + """Return an iterator over the manager's plugins.""" return iter(self.plugin_manager) def add_plugin(self, plugin): - """ Add a plugin to the manager. """ + """Add a plugin to the manager.""" self.plugin_manager.add_plugin(plugin) def get_plugin(self, plugin_id): - """ Return the plugin with the specified Id. """ + """Return the plugin with the specified Id.""" return self.plugin_manager.get_plugin(plugin_id) def remove_plugin(self, plugin): - """ Remove a plugin from the manager. """ + """Remove a plugin from the manager.""" self.plugin_manager.remove_plugin(plugin) def start(self): - """ Start the plugin manager. + """Start the plugin manager. Returns True unless the start was vetoed. @@ -296,12 +302,12 @@ def start(self): return not event.veto def start_plugin(self, plugin=None, plugin_id=None): - """ Start the specified plugin. """ + """Start the specified plugin.""" return self.plugin_manager.start_plugin(plugin, plugin_id) def stop(self): - """ Stop the plugin manager. + """Stop the plugin manager. Returns True unless the stop was vetoed. @@ -333,7 +339,7 @@ def stop(self): return not event.veto def stop_plugin(self, plugin=None, plugin_id=None): - """ Stop the specified plugin. """ + """Stop the specified plugin.""" return self.plugin_manager.stop_plugin(plugin, plugin_id) @@ -344,7 +350,7 @@ def stop_plugin(self, plugin=None, plugin_id=None): def get_required_service( self, protocol, query="", minimize="", maximize="" ): - """ Return the service that matches the specified query. + """Return the service that matches the specified query. Raise a 'NoSuchServiceError' exception if no such service exists. @@ -357,7 +363,7 @@ def get_required_service( return service def get_service(self, protocol, query="", minimize="", maximize=""): - """ Return at most one service that matches the specified query. """ + """Return at most one service that matches the specified query.""" service = self.service_registry.get_service( protocol, query, minimize, maximize @@ -366,17 +372,17 @@ def get_service(self, protocol, query="", minimize="", maximize=""): return service def get_service_from_id(self, service_id): - """ Return the service with the specified id. """ + """Return the service with the specified id.""" return self.service_registry.get_service_from_id(service_id) def get_service_properties(self, service_id): - """ Return the dictionary of properties associated with a service. """ + """Return the dictionary of properties associated with a service.""" return self.service_registry.get_service_properties(service_id) def get_services(self, protocol, query="", minimize="", maximize=""): - """ Return all services that match the specified query. """ + """Return all services that match the specified query.""" services = self.service_registry.get_services( protocol, query, minimize, maximize @@ -385,7 +391,7 @@ def get_services(self, protocol, query="", minimize="", maximize=""): return services def register_service(self, protocol, obj, properties=None): - """ Register a service. """ + """Register a service.""" service_id = self.service_registry.register_service( protocol, obj, properties @@ -394,12 +400,12 @@ def register_service(self, protocol, obj, properties=None): return service_id def set_service_properties(self, service_id, properties): - """ Set the dictionary of properties associated with a service. """ + """Set the dictionary of properties associated with a service.""" self.service_registry.set_service_properties(service_id, properties) def unregister_service(self, service_id): - """ Unregister a service. """ + """Unregister a service.""" self.service_registry.unregister_service(service_id) @@ -410,7 +416,7 @@ def unregister_service(self, service_id): #### Trait initializers ################################################### def _extension_registry_default(self): - """ Trait initializer. """ + """Trait initializer.""" # Do the import here to emphasize the fact that this is just the # default implementation and that the application developer is free @@ -420,7 +426,7 @@ def _extension_registry_default(self): return PluginExtensionRegistry(plugin_manager=self) def _plugin_manager_default(self): - """ Trait initializer. """ + """Trait initializer.""" # Do the import here to emphasize the fact that this is just the # default implementation and that the application developer is free @@ -430,7 +436,7 @@ def _plugin_manager_default(self): return PluginManager(application=self) def _service_registry_default(self): - """ Trait initializer. """ + """Trait initializer.""" # Do the import here to emphasize the fact that this is just the # default implementation and that the application developer is free @@ -464,7 +470,7 @@ def _service_registry_default(self): @observe("plugin_manager") def _update_application(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" old, new = event.old, event.new if old is not None: @@ -476,12 +482,12 @@ def _update_application(self, event): #### Methods ############################################################## def _create_application_event(self): - """ Create an application event. """ + """Create an application event.""" return ApplicationEvent(application=self) def _initialize_application_home(self): - """ Initialize the application directories. """ + """Initialize the application directories.""" os.makedirs(self.home, mode=0o700, exist_ok=True) os.makedirs(self.user_data, exist_ok=True) diff --git a/envisage/application_event.py b/envisage/application_event.py index 57b25f70e..97622098c 100644 --- a/envisage/application_event.py +++ b/envisage/application_event.py @@ -15,7 +15,7 @@ class ApplicationEvent(Vetoable): - """ An application event. """ + """An application event.""" # The application that the event is for. application = Instance("envisage.api.IApplication") diff --git a/envisage/composite_plugin_manager.py b/envisage/composite_plugin_manager.py index c96fc1e82..68d150612 100644 --- a/envisage/composite_plugin_manager.py +++ b/envisage/composite_plugin_manager.py @@ -15,7 +15,13 @@ # Enthought library imports. from traits.api import ( - Event, HasTraits, Instance, List, observe, on_trait_change, provides, + Event, + HasTraits, + Instance, + List, + observe, + on_trait_change, + provides, ) # Local imports. @@ -25,14 +31,13 @@ from .plugin_event import PluginEvent from .plugin_manager import PluginManager - # Logging. logger = logging.getLogger(__name__) @provides(IPluginManager) class CompositePluginManager(HasTraits): - """ A plugin manager composed of other plugin managers! + """A plugin manager composed of other plugin managers! e.g:: @@ -106,7 +111,7 @@ def __plugins_default(self): #### 'object' protocol #################################################### def __iter__(self): - """ Return an iterator over the manager's plugins. """ + """Return an iterator over the manager's plugins.""" plugins = [] for plugin_manager in self.plugin_managers: @@ -118,12 +123,12 @@ def __iter__(self): #### 'IPluginManager' protocol ############################################ def add_plugin(self, plugin): - """ Add a plugin to the manager. """ + """Add a plugin to the manager.""" raise NotImplementedError def get_plugin(self, plugin_id): - """ Return the plugin with the specified Id. """ + """Return the plugin with the specified Id.""" for plugin in self: if plugin_id == plugin.id: @@ -135,18 +140,18 @@ def get_plugin(self, plugin_id): return plugin def remove_plugin(self, plugin): - """ Remove a plugin from the manager. """ + """Remove a plugin from the manager.""" raise NotImplementedError def start(self): - """ Start the plugin manager. """ + """Start the plugin manager.""" for plugin in self: self.start_plugin(plugin) def start_plugin(self, plugin=None, plugin_id=None): - """ Start the specified plugin. """ + """Start the specified plugin.""" plugin = plugin or self.get_plugin(plugin_id) if plugin is not None: @@ -158,7 +163,7 @@ def start_plugin(self, plugin=None, plugin_id=None): raise ValueError("no such plugin %s" % plugin_id) def stop(self): - """ Stop the plugin manager. """ + """Stop the plugin manager.""" # We stop the plugins in the reverse order that they were started. stop_order = list(iter(self)) @@ -168,7 +173,7 @@ def stop(self): self.stop_plugin(plugin) def stop_plugin(self, plugin=None, plugin_id=None): - """ Stop the specified plugin. """ + """Stop the specified plugin.""" plugin = plugin or self.get_plugin(plugin_id) if plugin is not None: diff --git a/envisage/core_plugin.py b/envisage/core_plugin.py index 28f16e0e7..24d3a4b49 100644 --- a/envisage/core_plugin.py +++ b/envisage/core_plugin.py @@ -11,15 +11,16 @@ from contextlib import closing +from traits.api import List, on_trait_change, Str + # Enthought library imports. from envisage.extension_point import ExtensionPoint from envisage.plugin import Plugin from envisage.service_offer import ServiceOffer -from traits.api import List, on_trait_change, Str class CorePlugin(Plugin): - """ The Envisage core plugin. + """The Envisage core plugin. The core plugin offers facilities that are generally useful when building extensible applications such as adapters and hooks etc. It does @@ -82,7 +83,7 @@ class CorePlugin(Plugin): @on_trait_change("preferences_items") def _update_preferences(self, event): - """ React to new preferencess being *added*. + """React to new preferencess being *added*. Note that we don't currently do anything if preferences are *removed*. @@ -115,7 +116,7 @@ def _update_preferences(self, event): @on_trait_change("service_offers_items") def _register_new_services(self, event): - """ React to new service offers being *added*. + """React to new service offers being *added*. Note that we don't currently do anything if services are *removed* as we have no facility to let users of the service know that the offer @@ -134,7 +135,7 @@ def _register_new_services(self, event): ########################################################################### def start(self): - """ Start the plugin. """ + """Start the plugin.""" # Load all contributed preferences files into the application's root # preferences node. self._load_preferences(self.preferences) @@ -151,7 +152,7 @@ def start(self): ########################################################################### def _load_preferences(self, preferences): - """ Load all contributed preferences into a preferences node. """ + """Load all contributed preferences into a preferences node.""" # Enthought library imports. from envisage.resource.api import ResourceManager @@ -170,12 +171,12 @@ def _load_preferences(self, preferences): default.load(f) def _register_service_offers(self, service_offers): - """ Register a list of service offers. """ + """Register a list of service offers.""" return list(map(self._register_service_offer, service_offers)) def _register_service_offer(self, service_offer): - """ Register a service offer. """ + """Register a service offer.""" service_id = self.application.register_service( protocol=service_offer.protocol, diff --git a/envisage/egg_basket_plugin_manager.py b/envisage/egg_basket_plugin_manager.py index 8d654a000..4633117f5 100644 --- a/envisage/egg_basket_plugin_manager.py +++ b/envisage/egg_basket_plugin_manager.py @@ -22,12 +22,11 @@ from .egg_utils import add_eggs_on_path, get_entry_points_in_egg_order from .plugin_manager import PluginManager - logger = logging.getLogger(__name__) class EggBasketPluginManager(PluginManager): - """ A plugin manager that finds plugins in eggs on the 'plugin_path'. + """A plugin manager that finds plugins in eggs on the 'plugin_path'. To declare a plugin (or plugins) in your egg use an entry point in your 'setup.py' file, e.g. @@ -87,7 +86,7 @@ def _update_path_and_reset_plugins(self, obj, trait_name, removed, added): # Protected 'PluginManager' protocol ###################################### def __plugins_default(self): - """ Trait initializer. """ + """Trait initializer.""" plugins = self._harvest_plugins_in_eggs(self.application) @@ -98,7 +97,7 @@ def __plugins_default(self): #### Private protocol ##################################################### def _create_plugin_from_entry_point(self, ep, application): - """ Create a plugin from an entry point. """ + """Create a plugin from an entry point.""" klass = ep.load() plugin = klass(application=application) @@ -114,7 +113,7 @@ def _create_plugin_from_entry_point(self, ep, application): return plugin def _get_plugin_entry_points(self, working_set): - """ Return all plugin entry points in the working set. """ + """Return all plugin entry points in the working set.""" entry_points = get_entry_points_in_egg_order( working_set, self.ENVISAGE_PLUGINS_ENTRY_POINT @@ -123,7 +122,7 @@ def _get_plugin_entry_points(self, working_set): return entry_points def _harvest_plugins_in_eggs(self, application): - """ Harvest plugins found in eggs on the plugin path. """ + """Harvest plugins found in eggs on the plugin path.""" # We first add the eggs to a local working set so that when we get # the plugin entry points we don't pick up any from other eggs @@ -172,7 +171,7 @@ def _handle_broken_distributions(self, errors): self.on_broken_distribution(dist, exc) def _update_sys_dot_path(self, removed, added): - """ Add/remove the given entries from sys.path. """ + """Add/remove the given entries from sys.path.""" for dirname in removed: if dirname in sys.path: diff --git a/envisage/egg_plugin_manager.py b/envisage/egg_plugin_manager.py index 55367c732..4eb046d0b 100644 --- a/envisage/egg_plugin_manager.py +++ b/envisage/egg_plugin_manager.py @@ -25,13 +25,12 @@ from .egg_utils import get_entry_points_in_egg_order from .plugin_manager import PluginManager - # Logging. logger = logging.getLogger(__name__) class EggPluginManager(PluginManager): - """ A plugin manager that gets its plugins from Eggs. + """A plugin manager that gets its plugins from Eggs. To declare a plugin (or plugins) in your egg use an entry point in your 'setup.py' file, e.g. @@ -89,7 +88,7 @@ def __init__(self, **traits): ########################################################################### def __plugins_default(self): - """ Trait initializer. """ + """Trait initializer.""" plugins = [] for ep in get_entry_points_in_egg_order( @@ -104,7 +103,7 @@ def __plugins_default(self): return plugins def _working_set_default(self): - """ Trait initializer. """ + """Trait initializer.""" return pkg_resources.working_set @@ -113,7 +112,7 @@ def _working_set_default(self): ########################################################################### def _create_plugin_from_ep(self, ep): - """ Create a plugin from an extension point. """ + """Create a plugin from an extension point.""" klass = ep.load() plugin = klass(application=self.application) @@ -129,7 +128,7 @@ def _create_plugin_from_ep(self, ep): return plugin def _is_excluded(self, plugin_id): - """ Return True if the plugin Id is excluded. + """Return True if the plugin Id is excluded. If no 'exclude' patterns are specified then this method returns False for all plugin Ids. @@ -146,7 +145,7 @@ def _is_excluded(self, plugin_id): return False def _is_included(self, plugin_id): - """ Return True if the plugin Id is included. + """Return True if the plugin Id is included. If no 'include' patterns are specified then this method returns True for all plugin Ids. diff --git a/envisage/egg_utils.py b/envisage/egg_utils.py index 19c8f0742..c44ecded6 100644 --- a/envisage/egg_utils.py +++ b/envisage/egg_utils.py @@ -18,7 +18,7 @@ def add_eggs_on_path(working_set, path, on_error=None): - """ Add all eggs found on the path to a working set. """ + """Add all eggs found on the path to a working set.""" environment = pkg_resources.Environment(path) @@ -38,7 +38,7 @@ def add_eggs_on_path(working_set, path, on_error=None): def get_entry_points_in_egg_order(working_set, entry_point_name): - """ Return entry points in Egg dependency order. """ + """Return entry points in Egg dependency order.""" # Find all distributions that actually contain contributions to the # entry point. @@ -58,9 +58,7 @@ def get_entry_points_in_egg_order(working_set, entry_point_name): def get_distributions_with_entry_point(working_set, entry_point_name): - """ Return all distributions that contribute to an entry point. - - """ + """Return all distributions that contribute to an entry point.""" distributions = [] for distribution in working_set: @@ -71,7 +69,7 @@ def get_distributions_with_entry_point(working_set, entry_point_name): def get_distributions_in_egg_order(working_set, distributions=None): - """ Return all distributions in Egg dependency order. """ + """Return all distributions in Egg dependency order.""" # If no specific list of distributions is specified then use all # distributions in the working set. @@ -91,7 +89,7 @@ def get_distributions_in_egg_order(working_set, distributions=None): def get_requires(working_set, distribution): - """ Return all of the other distributions that a distribution requires. """ + """Return all of the other distributions that a distribution requires.""" requires = [] for requirement in distribution.requires(): diff --git a/envisage/examples/_demo.py b/envisage/examples/_demo.py index 2e28f22b4..653c4055b 100644 --- a/envisage/examples/_demo.py +++ b/envisage/examples/_demo.py @@ -17,7 +17,7 @@ @contextlib.contextmanager def demo_path(path): - """ Context manager to temporarily insert the directory containing + """Context manager to temporarily insert the directory containing the demo script to sys.path such that demo examples can be run using local packages. diff --git a/envisage/examples/_etsdemo_info.py b/envisage/examples/_etsdemo_info.py index 2927db0b5..222dc71e3 100644 --- a/envisage/examples/_etsdemo_info.py +++ b/envisage/examples/_etsdemo_info.py @@ -16,7 +16,7 @@ def info(request): - """ Return a configuration for contributing examples to the + """Return a configuration for contributing examples to the Demo application. Parameters ---------- @@ -30,7 +30,5 @@ def info(request): return dict( version=1, name="Envisage Examples", - root=( - pkg_resources.resource_filename("envisage.examples", "demo") - ), + root=(pkg_resources.resource_filename("envisage.examples", "demo")), ) diff --git a/envisage/examples/demo/GUI_Application/traitsui_gui_app.py b/envisage/examples/demo/GUI_Application/traitsui_gui_app.py index 5794abec4..35c8fb281 100644 --- a/envisage/examples/demo/GUI_Application/traitsui_gui_app.py +++ b/envisage/examples/demo/GUI_Application/traitsui_gui_app.py @@ -10,14 +10,15 @@ """ A simple example of a GUIApplication which wraps a TraitsUI """ -from traits.api import HasTraits, Str, Int, Enum, Instance, on_trait_change +from traits.api import Enum, HasTraits, Instance, Int, on_trait_change, Str +from traitsui.api import Item, OKCancelButtons, View + from envisage.api import Plugin from envisage.ui.gui_application import GUIApplication -from traitsui.api import View, Item, OKCancelButtons class Person(HasTraits): - """ A typical traits model object """ + """A typical traits model object""" name = Str("John Doe") @@ -26,12 +27,15 @@ class Person(HasTraits): gender = Enum("Male", "Female") view = View( - Item("name"), Item("age"), Item("gender"), buttons=OKCancelButtons, + Item("name"), + Item("age"), + Item("gender"), + buttons=OKCancelButtons, ) class PersonViewPlugin(Plugin): - """ The 'Person View' plugin. + """The 'Person View' plugin. This plugin waits for the application to start, and then creates a traits UI. @@ -42,7 +46,7 @@ class PersonViewPlugin(Plugin): @on_trait_change("application:application_initialized") def on_application_start(self): - """ Start the UI. """ + """Start the UI.""" person = Person() @@ -52,7 +56,6 @@ def on_application_start(self): # Application entry point. if __name__ == "__main__": - # Create the application. application = GUIApplication( id="person_view", plugins=[PersonViewPlugin()] diff --git a/envisage/examples/demo/Hello_World/hello_world.py b/envisage/examples/demo/Hello_World/hello_world.py index c9d1ac607..ada39e83a 100644 --- a/envisage/examples/demo/Hello_World/hello_world.py +++ b/envisage/examples/demo/Hello_World/hello_world.py @@ -10,13 +10,14 @@ """ The Envisage version of the old chestnut. """ +from traits.api import List, Str + # Enthought library imports. from envisage.api import Application, ExtensionPoint, Plugin -from traits.api import List, Str class HelloWorld(Plugin): - """ The 'Hello World' plugin. + """The 'Hello World' plugin. This plugin offers a single extension point 'greetings' which is a list of greetings, one of which is used to produce the ' World' message @@ -35,7 +36,7 @@ class HelloWorld(Plugin): # methods are called automatically by Envisage when the application is # started and stopped respectively. def start(self): - """ Start the plugin. """ + """Start the plugin.""" # Standard library imports. # @@ -47,7 +48,7 @@ def start(self): class Greetings(Plugin): - """ A plugin that contributes to the 'greetings' extension point. """ + """A plugin that contributes to the 'greetings' extension point.""" # This tells us that the plugin contributes the value of this trait to the # 'greetings' extension point. @@ -55,7 +56,7 @@ class Greetings(Plugin): class MoreGreetings(Plugin): - """ Another plugin that contributes to the 'greetings' extension point. """ + """Another plugin that contributes to the 'greetings' extension point.""" # This tells us that the plugin contributes the value of this trait to the # 'greetings' extension point. @@ -64,7 +65,7 @@ class MoreGreetings(Plugin): # This shows how you can use a standard trait initializer to populate the # list dynamically. def _greetings_default(self): - """ Trait initializer. """ + """Trait initializer.""" extensions = [ "The %s application says %s" % (self.application.id, greeting) @@ -76,7 +77,6 @@ def _greetings_default(self): # Application entry point. if __name__ == "__main__": - # Create the application. # # An application is simply a collection of plugins. In this case we diff --git a/envisage/examples/demo/MOTD/acme/motd/api.py b/envisage/examples/demo/MOTD/acme/motd/api.py index ccad617e5..096637b3a 100644 --- a/envisage/examples/demo/MOTD/acme/motd/api.py +++ b/envisage/examples/demo/MOTD/acme/motd/api.py @@ -10,6 +10,5 @@ from acme.motd.i_message import IMessage from acme.motd.i_motd import IMOTD - from acme.motd.message import Message from acme.motd.motd import MOTD diff --git a/envisage/examples/demo/MOTD/acme/motd/i_message.py b/envisage/examples/demo/MOTD/acme/motd/i_message.py index ceb99fa31..35c89dc7a 100644 --- a/envisage/examples/demo/MOTD/acme/motd/i_message.py +++ b/envisage/examples/demo/MOTD/acme/motd/i_message.py @@ -16,7 +16,7 @@ class IMessage(Interface): - """ The interface for 'Message of the Day' messages. """ + """The interface for 'Message of the Day' messages.""" # The author of the message. author = Str diff --git a/envisage/examples/demo/MOTD/acme/motd/i_motd.py b/envisage/examples/demo/MOTD/acme/motd/i_motd.py index 5ea082cc1..53655b219 100644 --- a/envisage/examples/demo/MOTD/acme/motd/i_motd.py +++ b/envisage/examples/demo/MOTD/acme/motd/i_motd.py @@ -16,10 +16,10 @@ class IMOTD(Interface): - """ The 'Message of the Day' interface. """ + """The 'Message of the Day' interface.""" def motd(self): - """ Return the message of the day. + """Return the message of the day. Returns an object that implements the 'IMessage' interface. diff --git a/envisage/examples/demo/MOTD/acme/motd/message.py b/envisage/examples/demo/MOTD/acme/motd/message.py index 7d95c5cf4..a72455907 100644 --- a/envisage/examples/demo/MOTD/acme/motd/message.py +++ b/envisage/examples/demo/MOTD/acme/motd/message.py @@ -11,16 +11,16 @@ """ The default implementation of the 'IMessage' interface. """ -# Enthought library imports. -from traits.api import HasTraits, Str, provides - # Local imports. from acme.motd.i_message import IMessage +# Enthought library imports. +from traits.api import HasTraits, provides, Str + @provides(IMessage) class Message(HasTraits): - """ The default implementation of the 'IMessage' interface. """ + """The default implementation of the 'IMessage' interface.""" # The author of the message. author = Str diff --git a/envisage/examples/demo/MOTD/acme/motd/motd.py b/envisage/examples/demo/MOTD/acme/motd/motd.py index 8d05667f8..9fda11254 100644 --- a/envisage/examples/demo/MOTD/acme/motd/motd.py +++ b/envisage/examples/demo/MOTD/acme/motd/motd.py @@ -14,18 +14,18 @@ # Standard library imports. from random import choice -# Enthought library imports. -from traits.api import HasTraits, List, provides - # Local imports. from acme.motd.i_message import IMessage from acme.motd.i_motd import IMOTD from acme.motd.message import Message +# Enthought library imports. +from traits.api import HasTraits, List, provides + @provides(IMOTD) class MOTD(HasTraits): - """ The 'Message of the Day' implementation! """ + """The 'Message of the Day' implementation!""" # The default message is used when there are no other messages! DEFAULT_MESSAGE = Message( @@ -40,7 +40,7 @@ class MOTD(HasTraits): ########################################################################### def motd(self): - """ Prints a random message. """ + """Prints a random message.""" if len(self.messages) > 0: message = choice(self.messages) diff --git a/envisage/examples/demo/MOTD/acme/motd/motd_plugin.py b/envisage/examples/demo/MOTD/acme/motd/motd_plugin.py index d4c4cb7d0..d66ba106e 100644 --- a/envisage/examples/demo/MOTD/acme/motd/motd_plugin.py +++ b/envisage/examples/demo/MOTD/acme/motd/motd_plugin.py @@ -20,13 +20,14 @@ # Eveything else should be imported when it is actually required. +from traits.api import Instance, List, on_trait_change + # Enthought library imports. from envisage.api import ExtensionPoint, Plugin, ServiceOffer -from traits.api import Instance, List, on_trait_change class MOTDPlugin(Plugin): - """ The 'Message of the Day' plugin. + """The 'Message of the Day' plugin. This plugin simply prints the 'Message of the Day' to stdout. @@ -69,7 +70,7 @@ class MOTDPlugin(Plugin): service_offers = List(contributes_to=SERVICE_OFFERS) def _service_offers_default(self): - """ Trait initializer. """ + """Trait initializer.""" # Register the protocol as a string containing the actual module path # and *not* a module path that goes via an 'api.py' file as this does @@ -89,7 +90,7 @@ def _service_offers_default(self): ########################################################################### def _create_motd_service(self): - """ Factory method for the 'MOTD' service. """ + """Factory method for the 'MOTD' service.""" # Only do imports when you need to! This makes sure that the import # only happens when somebody needs an 'IMOTD' service. @@ -101,7 +102,7 @@ def _create_motd_service(self): # the application has started all of its plugins. @on_trait_change("application:started") def _print_motd(self): - """ Print the 'Message of the Day' to stdout! """ + """Print the 'Message of the Day' to stdout!""" # Note that we always offer the service via its name, but look it up # via the actual protocol. diff --git a/envisage/examples/demo/MOTD/acme/motd/software_quotes/software_quotes_plugin.py b/envisage/examples/demo/MOTD/acme/motd/software_quotes/software_quotes_plugin.py index 8a4a21592..60d346051 100644 --- a/envisage/examples/demo/MOTD/acme/motd/software_quotes/software_quotes_plugin.py +++ b/envisage/examples/demo/MOTD/acme/motd/software_quotes/software_quotes_plugin.py @@ -11,13 +11,14 @@ """ The 'Software Quotes' plugin """ +from traits.api import List + # Enthought library imports. from envisage.api import Plugin -from traits.api import List class SoftwareQuotesPlugin(Plugin): - """ The 'Software Quotes' plugin. """ + """The 'Software Quotes' plugin.""" #### 'IPlugin' interface ################################################## @@ -37,7 +38,7 @@ class SoftwareQuotesPlugin(Plugin): messages = List(contributes_to="acme.motd.messages") def _messages_default(self): - """ Trait initializer. """ + """Trait initializer.""" # Only do imports when you need to! from acme.motd.software_quotes.messages import messages diff --git a/envisage/examples/demo/MOTD/run.py b/envisage/examples/demo/MOTD/run.py index 32338ea47..58652bad7 100644 --- a/envisage/examples/demo/MOTD/run.py +++ b/envisage/examples/demo/MOTD/run.py @@ -15,13 +15,14 @@ def main(): - """ Run the application. """ + """Run the application.""" # Import here so that this script can be run from anywhere without # having to install the packages. from acme.motd.motd_plugin import MOTDPlugin from acme.motd.software_quotes.software_quotes_plugin import ( SoftwareQuotesPlugin, ) + # Create an application containing the appropriate plugins. application = Application( id="acme.motd", diff --git a/envisage/examples/demo/plugins/tasks/attractors/attractors_application.py b/envisage/examples/demo/plugins/tasks/attractors/attractors_application.py index 4c446c823..aa0a8aa0e 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/attractors_application.py +++ b/envisage/examples/demo/plugins/tasks/attractors/attractors_application.py @@ -8,18 +8,18 @@ # # Thanks for using Enthought open source! -# Enthought library imports. -from envisage.ui.tasks.api import TasksApplication +# Local imports. +from attractors.attractors_preferences import AttractorsPreferences + from pyface.tasks.api import TaskWindowLayout from traits.api import Bool, Instance, List, Property -# Local imports. -from attractors.attractors_preferences import AttractorsPreferences +# Enthought library imports. +from envisage.ui.tasks.api import TasksApplication class AttractorsApplication(TasksApplication): - """ The chaotic attractors Tasks application. - """ + """The chaotic attractors Tasks application.""" #### 'IApplication' interface ############################################# diff --git a/envisage/examples/demo/plugins/tasks/attractors/attractors_plugin.py b/envisage/examples/demo/plugins/tasks/attractors/attractors_plugin.py index 764366782..68332e671 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/attractors_plugin.py +++ b/envisage/examples/demo/plugins/tasks/attractors/attractors_plugin.py @@ -11,15 +11,15 @@ # Standard library imports. import os.path +from traits.api import List + # Enthought library imports. from envisage.api import Plugin from envisage.ui.tasks.api import TaskFactory -from traits.api import List class AttractorsPlugin(Plugin): - """ The chaotic attractors plugin. - """ + """The chaotic attractors plugin.""" # Extension point IDs. PREFERENCES = "envisage.preferences" diff --git a/envisage/examples/demo/plugins/tasks/attractors/attractors_preferences.py b/envisage/examples/demo/plugins/tasks/attractors/attractors_preferences.py index ec5c00e8e..ecc2b18e8 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/attractors_preferences.py +++ b/envisage/examples/demo/plugins/tasks/attractors/attractors_preferences.py @@ -8,16 +8,16 @@ # # Thanks for using Enthought open source! -# Enthought library imports. -from envisage.ui.tasks.api import PreferencesPane from apptools.preferences.api import PreferencesHelper from traits.api import Bool, Dict, Str -from traitsui.api import EnumEditor, HGroup, VGroup, Item, Label, View +from traitsui.api import EnumEditor, HGroup, Item, Label, VGroup, View + +# Enthought library imports. +from envisage.ui.tasks.api import PreferencesPane class AttractorsPreferences(PreferencesHelper): - """ The preferences helper for the Attractors application. - """ + """The preferences helper for the Attractors application.""" #### 'PreferencesHelper' interface ######################################## @@ -35,8 +35,7 @@ class AttractorsPreferences(PreferencesHelper): class AttractorsPreferencesPane(PreferencesPane): - """ The preferences pane for the Attractors application. - """ + """The preferences pane for the Attractors application.""" #### 'PreferencesPane' interface ########################################## diff --git a/envisage/examples/demo/plugins/tasks/attractors/model/henon.py b/envisage/examples/demo/plugins/tasks/attractors/model/henon.py index e6c4b883a..1f7a08349 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/model/henon.py +++ b/envisage/examples/demo/plugins/tasks/attractors/model/henon.py @@ -10,29 +10,28 @@ # System library imports. import numpy as np + +# Local imports. +from attractors.model.i_plottable_2d import IPlottable2d from scipy import array, zeros # Enthought library imports. from traits.api import ( Array, + cached_property, Float, HasTraits, Int, Property, - Str, - cached_property, provides, + Str, ) from traitsui.api import Item, View -# Local imports. -from attractors.model.i_plottable_2d import IPlottable2d - @provides(IPlottable2d) class Henon(HasTraits): - """ The model object for the Henon map. - """ + """The model object for the Henon map.""" #### 'Henon' interface #################################################### @@ -75,7 +74,7 @@ def _get_points(self): points = zeros((self.steps, 2)) for i in range(self.steps): x, y = points[i] = point - point = array([y + 1 - self.a * x ** 2, self.b * x]) + point = array([y + 1 - self.a * x**2, self.b * x]) return points @cached_property diff --git a/envisage/examples/demo/plugins/tasks/attractors/model/i_model_2d.py b/envisage/examples/demo/plugins/tasks/attractors/model/i_model_2d.py index 3771e6d4d..a4e0083c3 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/model/i_model_2d.py +++ b/envisage/examples/demo/plugins/tasks/attractors/model/i_model_2d.py @@ -13,7 +13,6 @@ class IModel2d(Interface): - # The user-visible name of the model. name = Str() diff --git a/envisage/examples/demo/plugins/tasks/attractors/model/i_model_3d.py b/envisage/examples/demo/plugins/tasks/attractors/model/i_model_3d.py index 41c4f76a4..027afd54e 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/model/i_model_3d.py +++ b/envisage/examples/demo/plugins/tasks/attractors/model/i_model_3d.py @@ -11,21 +11,20 @@ # Enthought library imports. from traits.api import ( Array, + cached_property, DelegatesTo, HasTraits, - Interface, Instance, + Interface, Property, Str, Trait, - cached_property, ) from traitsui.api import Group, Item, View class IModel3d(Interface): - """ A model object that produces an array of 3D points. - """ + """A model object that produces an array of 3D points.""" # The user-visible name of the model. name = Str @@ -35,7 +34,8 @@ class IModel3d(Interface): class IModel3dIPlottable2dMixin(HasTraits): - """ Mixin class to facilitate defining a IModel3d -> IPlottable2D adapter. + """ + Mixin class to facilitate defining a IModel3d -> IPlottable2D adapter. """ #### 'Adapter' interface ################################################## diff --git a/envisage/examples/demo/plugins/tasks/attractors/model/i_plottable_2d.py b/envisage/examples/demo/plugins/tasks/attractors/model/i_plottable_2d.py index 4eebce4e4..de812db38 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/model/i_plottable_2d.py +++ b/envisage/examples/demo/plugins/tasks/attractors/model/i_plottable_2d.py @@ -8,15 +8,14 @@ # # Thanks for using Enthought open source! -# Enthought library imports. -from traits.api import Enum, Str - # Local imports. from attractors.model.i_model_2d import IModel2d +# Enthought library imports. +from traits.api import Enum, Str -class IPlottable2d(IModel2d): +class IPlottable2d(IModel2d): plot_type = Enum("line", "scatter") x_label = Str() diff --git a/envisage/examples/demo/plugins/tasks/attractors/model/lorenz.py b/envisage/examples/demo/plugins/tasks/attractors/model/lorenz.py index e787100c0..c75e568c6 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/model/lorenz.py +++ b/envisage/examples/demo/plugins/tasks/attractors/model/lorenz.py @@ -10,6 +10,10 @@ # System library imports. import numpy as np + +# Local imports +from attractors.model.i_model_3d import IModel3d, IModel3dIPlottable2dMixin +from attractors.model.i_plottable_2d import IPlottable2d from scipy import arange, array from scipy.integrate import odeint @@ -17,26 +21,21 @@ from traits.api import ( Adapter, Array, + cached_property, Float, HasTraits, Instance, Property, - Str, - cached_property, provides, register_factory, + Str, ) -from traitsui.api import View, Item - -# Local imports -from attractors.model.i_model_3d import IModel3d, IModel3dIPlottable2dMixin -from attractors.model.i_plottable_2d import IPlottable2d +from traitsui.api import Item, View @provides(IModel3d) class Lorenz(HasTraits): - """ The model object for the Lorenz attractor. - """ + """The model object for the Lorenz attractor.""" #### 'IModel3d' interface ################################################# @@ -100,7 +99,6 @@ def _get_times(self): @provides(IPlottable2d) class LorenzIPlottable2dAdapter(Adapter, IModel3dIPlottable2dMixin): - adaptee = Instance(Lorenz) plot_type = Str("line") diff --git a/envisage/examples/demo/plugins/tasks/attractors/model/rossler.py b/envisage/examples/demo/plugins/tasks/attractors/model/rossler.py index 043e85a00..2fc314e9f 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/model/rossler.py +++ b/envisage/examples/demo/plugins/tasks/attractors/model/rossler.py @@ -10,6 +10,10 @@ # System library imports. import numpy as np + +# Local imports +from attractors.model.i_model_3d import IModel3d, IModel3dIPlottable2dMixin +from attractors.model.i_plottable_2d import IPlottable2d from scipy import arange, array from scipy.integrate import odeint @@ -17,26 +21,21 @@ from traits.api import ( Adapter, Array, + cached_property, Float, HasTraits, Instance, Property, - Str, - cached_property, provides, register_factory, + Str, ) -from traitsui.api import View, Item - -# Local imports -from attractors.model.i_model_3d import IModel3d, IModel3dIPlottable2dMixin -from attractors.model.i_plottable_2d import IPlottable2d +from traitsui.api import Item, View @provides(IModel3d) class Rossler(HasTraits): - """ The model object for the Rossler attractor. - """ + """The model object for the Rossler attractor.""" #### 'IModel3d' interface ################################################# @@ -92,7 +91,6 @@ def _get_times(self): @provides(IPlottable2d) class RosslerIPlottable2dAdapter(Adapter, IModel3dIPlottable2dMixin): - adaptee = Instance(Rossler) plot_type = Str("line") diff --git a/envisage/examples/demo/plugins/tasks/attractors/model_config_pane.py b/envisage/examples/demo/plugins/tasks/attractors/model_config_pane.py index e80ba0336..94a409182 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/model_config_pane.py +++ b/envisage/examples/demo/plugins/tasks/attractors/model_config_pane.py @@ -15,8 +15,8 @@ class ModelConfigPane(TraitsDockPane): - """ A simple dock pane for editing an attractor model's configuration - options. + """A simple dock pane for editing an attractor model's configuration + options. """ #### 'ITaskPane' interface ################################################ diff --git a/envisage/examples/demo/plugins/tasks/attractors/model_help_pane.py b/envisage/examples/demo/plugins/tasks/attractors/model_help_pane.py index 9f938a1b1..107ce8c8c 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/model_help_pane.py +++ b/envisage/examples/demo/plugins/tasks/attractors/model_help_pane.py @@ -14,7 +14,7 @@ # Enthought library imports. from pyface.tasks.api import TraitsDockPane -from traits.api import HasTraits, Instance, Property, Str, cached_property +from traits.api import cached_property, HasTraits, Instance, Property, Str from traitsui.api import HTMLEditor, Item, View # Constants. @@ -22,8 +22,7 @@ class ModelHelpPane(TraitsDockPane): - """ A dock pane for viewing any help associated with a model. - """ + """A dock pane for viewing any help associated with a model.""" #### 'ITaskPane' interface ################################################ @@ -52,8 +51,7 @@ class ModelHelpPane(TraitsDockPane): @cached_property def _get_html(self): - """ Fetch the help HTML for the current model. - """ + """Fetch the help HTML for the current model.""" if self.model is None: return "No model selected." diff --git a/envisage/examples/demo/plugins/tasks/attractors/plot_2d_pane.py b/envisage/examples/demo/plugins/tasks/attractors/plot_2d_pane.py index 222914a21..2b7017e10 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/plot_2d_pane.py +++ b/envisage/examples/demo/plugins/tasks/attractors/plot_2d_pane.py @@ -8,27 +8,27 @@ # # Thanks for using Enthought open source! +# Local imports. +from attractors.model.i_plottable_2d import IPlottable2d + # Enthought library imports. from chaco.api import ArrayPlotData, Plot from enable.api import ComponentEditor + from pyface.tasks.api import TraitsTaskPane from traits.api import ( Dict, Instance, List, - Property, - Str, observe, on_trait_change, + Property, + Str, ) from traitsui.api import EnumEditor, HGroup, Item, Label, UItem, View -# Local imports. -from attractors.model.i_plottable_2d import IPlottable2d - class Plot2dPane(TraitsTaskPane): - #### 'ITaskPane' interface ################################################ id = "example.attractors.plot_2d_pane" @@ -56,8 +56,8 @@ def _plot_default(self): ("x", "y"), type=self.plot_type, name=self.title, - marker='pixel', - color="blue" + marker="pixel", + color="blue", ) return plot @@ -89,8 +89,8 @@ def _update_plot_new_model(self, event): ("x", "y"), type=self.plot_type, name=self.title, - marker='pixel', - color="blue" + marker="pixel", + color="blue", ) self.plot.invalidate_and_redraw() @@ -100,9 +100,7 @@ def _update_plot_new_model(self, event): Item("active_model", editor=EnumEditor(name="_enum_map")), show_labels=False, ), - UItem( - "plot", editor=ComponentEditor() - ), + UItem("plot", editor=ComponentEditor()), resizable=True, ) diff --git a/envisage/examples/demo/plugins/tasks/attractors/plot_3d_pane.py b/envisage/examples/demo/plugins/tasks/attractors/plot_3d_pane.py index e7a1feef0..93fc88459 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/plot_3d_pane.py +++ b/envisage/examples/demo/plugins/tasks/attractors/plot_3d_pane.py @@ -8,26 +8,20 @@ # # Thanks for using Enthought open source! +# Local imports. +from attractors.model.i_model_3d import IModel3d +from mayavi.core.ui.mayavi_scene import MayaviScene + # Enthought library imports. from mayavi.tools.mlab_scene_model import MlabSceneModel -from mayavi.core.ui.mayavi_scene import MayaviScene -from pyface.tasks.api import TraitsTaskPane -from traits.api import ( - Dict, - Instance, - List, - Str, - on_trait_change, -) -from traitsui.api import EnumEditor, HGroup, Item, Label, View from tvtk.pyface.scene_editor import SceneEditor -# Local imports. -from attractors.model.i_model_3d import IModel3d +from pyface.tasks.api import TraitsTaskPane +from traits.api import Dict, Instance, List, on_trait_change, Str +from traitsui.api import EnumEditor, HGroup, Item, Label, View class Plot3dPane(TraitsTaskPane): - #### 'ITaskPane' interface ################################################ id = "example.attractors.plot_3d_pane" diff --git a/envisage/examples/demo/plugins/tasks/attractors/visualize_2d_task.py b/envisage/examples/demo/plugins/tasks/attractors/visualize_2d_task.py index eb7d0365b..54cc2fd1a 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/visualize_2d_task.py +++ b/envisage/examples/demo/plugins/tasks/attractors/visualize_2d_task.py @@ -8,21 +8,20 @@ # # Thanks for using Enthought open source! -# Enthought library imports. -from pyface.tasks.action.api import SMenu, SMenuBar, TaskToggleGroup -from pyface.tasks.api import Task, TaskLayout, Tabbed, PaneItem -from traits.api import Any, Instance, List, adapt - # Local imports. from attractors.model.i_plottable_2d import IPlottable2d from attractors.model_config_pane import ModelConfigPane from attractors.model_help_pane import ModelHelpPane from attractors.plot_2d_pane import Plot2dPane +# Enthought library imports. +from pyface.tasks.action.api import SMenu, SMenuBar, TaskToggleGroup +from pyface.tasks.api import PaneItem, Tabbed, Task, TaskLayout +from traits.api import adapt, Any, Instance, List + class Visualize2dTask(Task): - """ A task for visualizing attractors in 2D. - """ + """A task for visualizing attractors in 2D.""" #### 'Task' interface ##################################################### @@ -49,8 +48,8 @@ class Visualize2dTask(Task): ########################################################################### def create_central_pane(self): - """ Create a plot pane with a list of models. Keep track of which model - is active so that dock panes can introspect it. + """Create a plot pane with a list of models. Keep track of which model + is active so that dock panes can introspect it. """ pane = Plot2dPane(models=self.models) diff --git a/envisage/examples/demo/plugins/tasks/attractors/visualize_3d_task.py b/envisage/examples/demo/plugins/tasks/attractors/visualize_3d_task.py index f9af26d75..697e154f7 100644 --- a/envisage/examples/demo/plugins/tasks/attractors/visualize_3d_task.py +++ b/envisage/examples/demo/plugins/tasks/attractors/visualize_3d_task.py @@ -8,20 +8,19 @@ # # Thanks for using Enthought open source! -# Enthought library imports. -from pyface.tasks.action.api import SMenu, SMenuBar, TaskToggleGroup -from pyface.tasks.api import Task, TaskLayout, Tabbed, PaneItem -from traits.api import Any, List - # Local imports. from attractors.model_config_pane import ModelConfigPane from attractors.model_help_pane import ModelHelpPane from attractors.plot_3d_pane import Plot3dPane +# Enthought library imports. +from pyface.tasks.action.api import SMenu, SMenuBar, TaskToggleGroup +from pyface.tasks.api import PaneItem, Tabbed, Task, TaskLayout +from traits.api import Any, List + class Visualize3dTask(Task): - """ A task for visualizing attractors in 3D. - """ + """A task for visualizing attractors in 3D.""" #### 'Task' interface ##################################################### @@ -48,8 +47,8 @@ class Visualize3dTask(Task): ########################################################################### def create_central_pane(self): - """ Create a plot pane with a list of models. Keep track of which model - is active so that dock panes can introspect it. + """Create a plot pane with a list of models. Keep track of which model + is active so that dock panes can introspect it. """ pane = Plot3dPane(models=self.models) diff --git a/envisage/examples/demo/plugins/tasks/run_attractor.py b/envisage/examples/demo/plugins/tasks/run_attractor.py index b9985f8a7..f179ce4c1 100644 --- a/envisage/examples/demo/plugins/tasks/run_attractor.py +++ b/envisage/examples/demo/plugins/tasks/run_attractor.py @@ -14,12 +14,11 @@ def main(argv): - """ Run the application. - """ + """Run the application.""" # Import here so that this script can be run from anywhere without # having to install the packages. - from attractors.attractors_plugin import AttractorsPlugin from attractors.attractors_application import AttractorsApplication + from attractors.attractors_plugin import AttractorsPlugin plugins = [CorePlugin(), TasksPlugin(), AttractorsPlugin()] app = AttractorsApplication(plugins=plugins) @@ -28,6 +27,7 @@ def main(argv): if __name__ == "__main__": import sys + # This context manager is added so that one can run this example from any # directory without necessarily having installed the examples as packages. from envisage.examples._demo import demo_path diff --git a/envisage/examples/tests/test__demo.py b/envisage/examples/tests/test__demo.py index 61704190c..fc6ec212a 100644 --- a/envisage/examples/tests/test__demo.py +++ b/envisage/examples/tests/test__demo.py @@ -15,7 +15,7 @@ class TestDemoUtilities(unittest.TestCase): - """ Test utility functions in the _demo module.""" + """Test utility functions in the _demo module.""" def test_sys_path_inserted(self): path = os.path.join("dirname", "file.py") diff --git a/envisage/examples/tests/test_etsdemo_info.py b/envisage/examples/tests/test_etsdemo_info.py index 3a17f0f5e..4a964b783 100644 --- a/envisage/examples/tests/test_etsdemo_info.py +++ b/envisage/examples/tests/test_etsdemo_info.py @@ -14,8 +14,7 @@ class TestETSDemoInfo(unittest.TestCase): - def test_info(self): # input to info is currently just a placeholder response = info({}) - self.assertTrue(os.path.exists(response['root'])) + self.assertTrue(os.path.exists(response["root"])) diff --git a/envisage/extension_point.py b/envisage/extension_point.py index 7606ccce8..982fa9053 100644 --- a/envisage/extension_point.py +++ b/envisage/extension_point.py @@ -15,12 +15,11 @@ import weakref # Enthought library imports. -from traits.api import List, TraitType, Undefined, provides +from traits.api import List, provides, TraitType, Undefined # Local imports. from .i_extension_point import IExtensionPoint - # Exception message template. INVALID_TRAIT_TYPE = ( 'extension points must be "List"s e.g. List, List(Int)' @@ -32,7 +31,7 @@ # declare that we implement an interface. @provides(IExtensionPoint) class ExtensionPoint(TraitType): - """ A trait type used to declare and access extension points. + """A trait type used to declare and access extension points. Note that this is a trait *type* and hence does *NOT* have traits itself (i.e. it does *not* inherit from 'HasTraits'). @@ -45,14 +44,14 @@ class ExtensionPoint(TraitType): @staticmethod def connect_extension_point_traits(obj): - """ Connect all of the 'ExtensionPoint' traits on an object. """ + """Connect all of the 'ExtensionPoint' traits on an object.""" for trait_name, trait in obj.traits(__extension_point__=True).items(): trait.trait_type.connect(obj, trait_name) @staticmethod def disconnect_extension_point_traits(obj): - """ Disconnect all of the 'ExtensionPoint' traits on an object. """ + """Disconnect all of the 'ExtensionPoint' traits on an object.""" for trait_name, trait in obj.traits(__extension_point__=True).items(): trait.trait_type.disconnect(obj, trait_name) @@ -62,7 +61,7 @@ def disconnect_extension_point_traits(obj): ########################################################################### def __init__(self, trait_type=List, id=None, **metadata): - """ Constructor. """ + """Constructor.""" # We add '__extension_point__' to the metadata to make the extension # point traits easier to find with the 'traits' and 'trait_names' @@ -98,7 +97,7 @@ def __init__(self, trait_type=List, id=None, **metadata): self._obj_to_listeners_map = weakref.WeakKeyDictionary() def __repr__(self): - """ String representation of an ExtensionPoint object """ + """String representation of an ExtensionPoint object""" return "ExtensionPoint(id={!r})".format(self.id) ########################################################################### @@ -106,7 +105,7 @@ def __repr__(self): ########################################################################### def get(self, obj, trait_name): - """ Trait type getter. """ + """Trait type getter.""" extension_registry = self._get_extension_registry(obj) @@ -117,7 +116,7 @@ def get(self, obj, trait_name): return self.trait_type.validate(obj, trait_name, extensions) def set(self, obj, name, value): - """ Trait type setter. """ + """Trait type setter.""" extension_registry = self._get_extension_registry(obj) @@ -131,7 +130,7 @@ def set(self, obj, name, value): ########################################################################### def connect(self, obj, trait_name): - """ Connect the extension point to a trait on an object. + """Connect the extension point to a trait on an object. This allows the object to react when contributions are added or removed from the extension point. @@ -143,7 +142,7 @@ def connect(self, obj, trait_name): """ def listener(extension_registry, event): - """ Listener called when an extension point is changed. """ + """Listener called when an extension point is changed.""" # If an index was specified then we fire an '_items' changed event. if event.index is not None: @@ -170,7 +169,7 @@ def listener(extension_registry, event): listeners[trait_name] = listener def disconnect(self, obj, trait_name): - """ Disconnect the extension point from a trait on an object. """ + """Disconnect the extension point from a trait on an object.""" extension_registry = self._get_extension_registry(obj) @@ -189,7 +188,7 @@ def disconnect(self, obj, trait_name): ########################################################################### def _get_extension_registry(self, obj): - """ Return the extension registry in effect for an object. """ + """Return the extension registry in effect for an object.""" extension_registry = getattr(obj, "extension_registry", None) if extension_registry is None: diff --git a/envisage/extension_point_binding.py b/envisage/extension_point_binding.py index 5682081cb..f15e413cb 100644 --- a/envisage/extension_point_binding.py +++ b/envisage/extension_point_binding.py @@ -18,7 +18,7 @@ class ExtensionPointBinding(HasTraits): - """ A binding between a trait on an object and an extension point. """ + """A binding between a trait on an object and an extension point.""" #### 'ExtensionPointBinding' *CLASS* interface ############################ @@ -51,7 +51,7 @@ class ExtensionPointBinding(HasTraits): ########################################################################### def __init__(self, **traits): - """ Constructor. """ + """Constructor.""" super().__init__(**traits) @@ -68,13 +68,13 @@ def __init__(self, **traits): #### Trait change handlers ################################################ def _on_trait_changed(self, obj, trait_name, old, new): - """ Dynamic trait change handler. """ + """Dynamic trait change handler.""" if not self._event_handled: self._set_extensions(new) def _on_trait_items_changed(self, obj, trait_name, old, event): - """ Dynamic trait change handler. """ + """Dynamic trait change handler.""" if not self._event_handled: self._set_extensions(getattr(obj, self.trait_name)) @@ -82,7 +82,7 @@ def _on_trait_items_changed(self, obj, trait_name, old, event): #### Other observer pattern listeners ##################################### def _extension_point_listener(self, extension_registry, event): - """ Listener called when an extension point is changed. """ + """Listener called when an extension point is changed.""" self._event_handled = True if event.index is not None: @@ -95,7 +95,7 @@ def _extension_point_listener(self, extension_registry, event): #### Methods ############################################################## def _bind(self): - """ Wire-up trait change handlers etc. """ + """Wire-up trait change handlers etc.""" # Listen for the object's trait being changed. self.obj.on_trait_change(self._on_trait_changed, self.trait_name) @@ -127,7 +127,7 @@ def _unbind(self): ) def _set_trait(self, notify): - """ Set the object's trait to the value of the extension point. """ + """Set the object's trait to the value of the extension point.""" value = self.extension_registry.get_extensions(self.extension_point_id) traits = {self.trait_name: value} @@ -135,7 +135,7 @@ def _set_trait(self, notify): self.obj.trait_set(trait_change_notify=notify, **traits) def _update_trait(self, event): - """ Update the object's trait to the value of the extension point. """ + """Update the object's trait to the value of the extension point.""" self._set_trait(notify=False) @@ -144,7 +144,7 @@ def _update_trait(self, event): ) def _set_extensions(self, extensions): - """ Set the extensions to an extension point. """ + """Set the extensions to an extension point.""" self.extension_registry.set_extensions( self.extension_point_id, extensions diff --git a/envisage/extension_point_changed_event.py b/envisage/extension_point_changed_event.py index ebcbbe00a..d16b6583a 100644 --- a/envisage/extension_point_changed_event.py +++ b/envisage/extension_point_changed_event.py @@ -15,10 +15,10 @@ class ExtensionPointChangedEvent(TraitListEvent): - """ An event fired when an extension point's extensions have changed. """ + """An event fired when an extension point's extensions have changed.""" def __init__(self, extension_point_id=None, **kw): - """ Constructor. """ + """Constructor.""" # The base class has the 'index', 'removed' and 'added' attributes. super().__init__(**kw) @@ -27,9 +27,7 @@ def __init__(self, extension_point_id=None, **kw): self.extension_point_id = extension_point_id def __repr__(self): - return ("ExtensionPointChangedEvent(extension_point_id={!r}, " - "index={!r}, removed={!r}, added={!r})").format( - self.extension_point_id, - self.index, - self.removed, - self.added) + return ( + "ExtensionPointChangedEvent(extension_point_id={!r}, " + "index={!r}, removed={!r}, added={!r})" + ).format(self.extension_point_id, self.index, self.removed, self.added) diff --git a/envisage/extension_provider.py b/envisage/extension_provider.py index 7944eb7b3..c14aefcb1 100644 --- a/envisage/extension_provider.py +++ b/envisage/extension_provider.py @@ -20,7 +20,7 @@ @provides(IExtensionProvider) class ExtensionProvider(HasTraits): - """ The default base class for extension providers. """ + """The default base class for extension providers.""" #### 'IExtensionProvider' interface ####################################### @@ -30,12 +30,12 @@ class ExtensionProvider(HasTraits): extension_point_changed = Event(ExtensionPointChangedEvent) def get_extension_points(self): - """ Return the extension points offered by the provider. """ + """Return the extension points offered by the provider.""" return [] def get_extensions(self, extension_point_id): - """ Return the provider's extensions to an extension point. """ + """Return the provider's extensions to an extension point.""" return [] @@ -44,7 +44,7 @@ def get_extensions(self, extension_point_id): def _fire_extension_point_changed( self, extension_point_id, added, removed, index ): - """ Fire an extension point changed event. """ + """Fire an extension point changed event.""" self.extension_point_changed = ExtensionPointChangedEvent( extension_point_id=extension_point_id, diff --git a/envisage/extension_registry.py b/envisage/extension_registry.py index e82e84be5..d382409d3 100644 --- a/envisage/extension_registry.py +++ b/envisage/extension_registry.py @@ -23,7 +23,6 @@ from .i_extension_registry import IExtensionRegistry from .unknown_extension_point import UnknownExtensionPoint - # Logging. logger = logging.getLogger(__name__) @@ -63,7 +62,7 @@ def _saferef(listener): @provides(IExtensionRegistry) class ExtensionRegistry(HasTraits): - """ A base class for extension registry implementation. """ + """A base class for extension registry implementation.""" ########################################################################### # Protected 'ExtensionRegistry' interface. @@ -93,42 +92,42 @@ class ExtensionRegistry(HasTraits): ########################################################################### def add_extension_point_listener(self, listener, extension_point_id=None): - """ Add a listener for extensions being added or removed. """ + """Add a listener for extensions being added or removed.""" listeners = self._listeners.setdefault(extension_point_id, []) listeners.append(_saferef(listener)) def add_extension_point(self, extension_point): - """ Add an extension point. """ + """Add an extension point.""" self._extension_points[extension_point.id] = extension_point logger.debug("extension point <%s> added", extension_point.id) def get_extensions(self, extension_point_id): - """ Return the extensions contributed to an extension point. """ + """Return the extensions contributed to an extension point.""" return self._get_extensions(extension_point_id)[:] def get_extension_point(self, extension_point_id): - """ Return the extension point with the specified Id. """ + """Return the extension point with the specified Id.""" return self._extension_points.get(extension_point_id) def get_extension_points(self): - """ Return all extension points. """ + """Return all extension points.""" return list(self._extension_points.values()) def remove_extension_point_listener( self, listener, extension_point_id=None ): - """ Remove a listener for extensions being added or removed. """ + """Remove a listener for extensions being added or removed.""" listeners = self._listeners.setdefault(extension_point_id, []) listeners.remove(_saferef(listener)) def remove_extension_point(self, extension_point_id): - """ Remove an extension point. """ + """Remove an extension point.""" self._check_extension_point(extension_point_id) @@ -149,7 +148,7 @@ def remove_extension_point(self, extension_point_id): logger.debug("extension point <%s> removed", extension_point_id) def set_extensions(self, extension_point_id, extensions): - """ Set the extensions contributed to an extension point. """ + """Set the extensions contributed to an extension point.""" self._check_extension_point(extension_point_id) @@ -164,7 +163,7 @@ def set_extensions(self, extension_point_id, extensions): ########################################################################### def _call_listeners(self, refs, extension_point_id, added, removed, index): - """ Call listeners that are listening to an extension point. """ + """Call listeners that are listening to an extension point.""" event = ExtensionPointChangedEvent( extension_point_id=extension_point_id, @@ -179,7 +178,7 @@ def _call_listeners(self, refs, extension_point_id, added, removed, index): listener(self, event) def _check_extension_point(self, extension_point_id): - """ Check to see if the extension point exists. + """Check to see if the extension point exists. Raise an 'UnknownExtensionPoint' if it does not. @@ -189,12 +188,12 @@ def _check_extension_point(self, extension_point_id): raise UnknownExtensionPoint(extension_point_id) def _get_extensions(self, extension_point_id): - """ Return the extensions for the given extension point. """ + """Return the extensions for the given extension point.""" return self._extensions.setdefault(extension_point_id, []) def _get_listener_refs(self, extension_point_id): - """ Get weak references to all listeners to an extension point. + """Get weak references to all listeners to an extension point. Returns a list containing the weak references to those listeners that are listening to this extension point specifically first, followed by diff --git a/envisage/i_application.py b/envisage/i_application.py index 362cd0110..b834dccd0 100644 --- a/envisage/i_application.py +++ b/envisage/i_application.py @@ -14,18 +14,19 @@ from apptools.preferences.api import IPreferences from traits.api import Event, Instance, Str, VetoableEvent +from .application_event import ApplicationEvent + # Local imports. from .i_extension_registry import IExtensionRegistry from .i_import_manager import IImportManager from .i_plugin_manager import IPluginManager from .i_service_registry import IServiceRegistry -from .application_event import ApplicationEvent class IApplication( IExtensionRegistry, IImportManager, IPluginManager, IServiceRegistry ): - """ The application interface. """ + """The application interface.""" #: The application's globally unique identifier. id = Str @@ -60,7 +61,7 @@ class IApplication( stopped = Event(ApplicationEvent) def run(self): - """ Run the application. + """Run the application. The same as:: diff --git a/envisage/i_extension_point.py b/envisage/i_extension_point.py index cc85221e8..66c7774e0 100644 --- a/envisage/i_extension_point.py +++ b/envisage/i_extension_point.py @@ -15,7 +15,7 @@ class IExtensionPoint(Interface): - """ The interface for extension points. """ + """The interface for extension points.""" # A description of what the extension point is and does! (it is called # the slightly dubious, 'desc', instead of 'description', or, to be more diff --git a/envisage/i_extension_point_user.py b/envisage/i_extension_point_user.py index c1281796f..e7cc054bf 100644 --- a/envisage/i_extension_point_user.py +++ b/envisage/i_extension_point_user.py @@ -18,7 +18,7 @@ class IExtensionPointUser(Interface): - """ The interface for objects using the 'ExtensionPoint' trait type. """ + """The interface for objects using the 'ExtensionPoint' trait type.""" # The extension registry that the object's extension points are stored in. extension_registry = Instance(IExtensionRegistry) diff --git a/envisage/i_extension_provider.py b/envisage/i_extension_provider.py index efdd225a2..408ca1e89 100644 --- a/envisage/i_extension_provider.py +++ b/envisage/i_extension_provider.py @@ -18,13 +18,13 @@ class IExtensionProvider(Interface): - """ The interface for extension providers. """ + """The interface for extension providers.""" # The event fired when one of the provider's extension points has changed. extension_point_changed = Event(ExtensionPointChangedEvent) def get_extension_points(self): - """ Return the extension points offered by the provider. + """Return the extension points offered by the provider. Return an empty list if the provider does not offer any extension points. @@ -32,7 +32,7 @@ def get_extension_points(self): """ def get_extensions(self, extension_point_id): - """ Return the provider's extensions to an extension point. + """Return the provider's extensions to an extension point. The return value *must* be a list. Return an empty list if the provider does not contribute any extensions to the extension point. diff --git a/envisage/i_extension_registry.py b/envisage/i_extension_registry.py index 87a35e0d1..a391a9a32 100644 --- a/envisage/i_extension_registry.py +++ b/envisage/i_extension_registry.py @@ -15,10 +15,10 @@ class IExtensionRegistry(Interface): - """ The interface for extension registries. """ + """The interface for extension registries.""" def add_extension_point_listener(self, listener, extension_point_id=None): - """ Add a listener for extensions being added or removed. + """Add a listener for extensions being added or removed. A listener is any Python callable with the following signature:: @@ -41,7 +41,7 @@ def listener(extension_registry, extension_point_changed_event): """ def add_extension_point(self, extension_point): - """ Add an extension point. + """Add an extension point. If an extension point already exists with this Id then it is simply replaced. @@ -49,35 +49,33 @@ def add_extension_point(self, extension_point): """ def get_extensions(self, extension_point_id): - """ Return the extensions contributed to an extension point. + """Return the extensions contributed to an extension point. Return an empty list if the extension point does not exist. """ def get_extension_point(self, extension_point_id): - """ Return the extension point with the specified Id. + """Return the extension point with the specified Id. Return None if no such extension point exists. """ def get_extension_points(self): - """ Return all extension points that have been added to the registry. - - """ + """Return all extension points that have been added to the registry.""" def remove_extension_point_listener( self, listener, extension_point_id=None ): - """ Remove a listener for extensions being added or removed. + """Remove a listener for extensions being added or removed. Raise a 'ValueError' if the listener does not exist. """ def remove_extension_point(self, extension_point_id): - """ Remove an extension point. + """Remove an extension point. Raise an 'UnknownExtensionPoint' exception if no extension point exists with the specified Id. @@ -85,6 +83,4 @@ def remove_extension_point(self, extension_point_id): """ def set_extensions(self, extension_point_id, extensions): - """ Set the extensions contributed to an extension point. - - """ + """Set the extensions contributed to an extension point.""" diff --git a/envisage/i_import_manager.py b/envisage/i_import_manager.py index d83d6965c..7699e231b 100644 --- a/envisage/i_import_manager.py +++ b/envisage/i_import_manager.py @@ -15,10 +15,10 @@ class IImportManager(Interface): - """ The interface for import managers. """ + """The interface for import managers.""" def import_symbol(self, symbol_path): - """ Import the symbol defined by the specified symbol path. + """Import the symbol defined by the specified symbol path. 'symbol_path' is a string containing the path to a symbol through the Python package namespace. diff --git a/envisage/i_plugin.py b/envisage/i_plugin.py index 3013eff8c..4a441a349 100644 --- a/envisage/i_plugin.py +++ b/envisage/i_plugin.py @@ -18,7 +18,7 @@ class IPlugin(Interface): - """ The plugin interface. """ + """The plugin interface.""" #: The activator used to start and stop the plugin. activator = Instance(IPluginActivator) @@ -42,7 +42,7 @@ class IPlugin(Interface): name = Str def start(self): - """ Start the plugin. + """Start the plugin. This method is called by the framework when the application is starting up. If you want to start a plugin manually use:: @@ -52,7 +52,7 @@ def start(self): """ def stop(self): - """ Stop the plugin. + """Stop the plugin. This method is called by the framework when the application is stopping. If you want to stop a plugin manually use:: diff --git a/envisage/i_plugin_activator.py b/envisage/i_plugin_activator.py index 58dcf41af..155c09416 100644 --- a/envisage/i_plugin_activator.py +++ b/envisage/i_plugin_activator.py @@ -15,7 +15,7 @@ class IPluginActivator(Interface): - """ The plugin activator interface. + """The plugin activator interface. A plugin activator is really just a collection of two strategies - one to start the plugin and one to stop it. @@ -31,11 +31,7 @@ class IPluginActivator(Interface): """ def start_plugin(self, plugin): - """ Start the specified plugin. - - """ + """Start the specified plugin.""" def stop_plugin(self, plugin): - """ Stop the specified plugin. - - """ + """Stop the specified plugin.""" diff --git a/envisage/i_plugin_manager.py b/envisage/i_plugin_manager.py index f4bf47220..2b5e4228c 100644 --- a/envisage/i_plugin_manager.py +++ b/envisage/i_plugin_manager.py @@ -18,7 +18,7 @@ class IPluginManager(Interface): - """ The plugin manager interface. """ + """The plugin manager interface.""" #### Events #### @@ -29,36 +29,30 @@ class IPluginManager(Interface): plugin_removed = Event(PluginEvent) def __iter__(self): - """ Return an iterator over the manager's plugins. - - """ + """Return an iterator over the manager's plugins.""" def add_plugin(self, plugin): - """ Add a plugin to the manager. - - """ + """Add a plugin to the manager.""" def get_plugin(self, plugin_id): - """ Return the plugin with the specified Id. + """Return the plugin with the specified Id. Return None if no such plugin exists. """ def remove_plugin(self, plugin): - """ Remove a plugin from the manager. - - """ + """Remove a plugin from the manager.""" def start(self): - """ Start the plugin manager. + """Start the plugin manager. This starts all of the manager's plugins. """ def start_plugin(self, plugin=None, plugin_id=None): - """ Start the specified plugin. + """Start the specified plugin. If a plugin is specified then start it. @@ -69,7 +63,7 @@ def start_plugin(self, plugin=None, plugin_id=None): """ def stop(self): - """ Stop the plugin manager. + """Stop the plugin manager. This stop's all of the plugin manager's plugins (in the reverse order that they were started). @@ -77,7 +71,7 @@ def stop(self): """ def stop_plugin(self, plugin=None, plugin_id=None): - """ Stop the specified plugin. + """Stop the specified plugin. If a plugin is specified then stop it (the Id is ignored). diff --git a/envisage/i_provider_extension_registry.py b/envisage/i_provider_extension_registry.py index 88aab6509..38efa79e3 100644 --- a/envisage/i_provider_extension_registry.py +++ b/envisage/i_provider_extension_registry.py @@ -15,20 +15,16 @@ class IProviderExtensionRegistry(IExtensionRegistry): - """ The provider extension registry interface. """ + """The provider extension registry interface.""" def add_provider(self, provider): - """ Add an extension provider. - - """ + """Add an extension provider.""" def get_providers(self): - """ Return all of the providers in the registry. - - """ + """Return all of the providers in the registry.""" def remove_provider(self, provider): - """ Remove an extension provider. + """Remove an extension provider. Raise a 'ValueError' if the provider is not in the registry. diff --git a/envisage/i_service_registry.py b/envisage/i_service_registry.py index bb9268dcd..0e3ba0d30 100644 --- a/envisage/i_service_registry.py +++ b/envisage/i_service_registry.py @@ -15,7 +15,7 @@ class IServiceRegistry(Interface): - """ The service registry interface. + """The service registry interface. The service registry provides a 'Yellow Pages' style mechanism, in that services are published and looked up by protocol (meaning, *interface*, @@ -40,7 +40,7 @@ class IServiceRegistry(Interface): unregistered = Event def get_service(self, protocol, query="", minimize="", maximize=""): - """ Return at most one service that matches the specified query. + """Return at most one service that matches the specified query. The protocol can be an actual class or interface, or the *name* of a class or interface in the form '.'. @@ -56,14 +56,14 @@ class or interface in the form '.'. """ def get_service_from_id(self, service_id): - """ Return the service with the specified id. + """Return the service with the specified id. If no such service exists a 'ValueError' exception is raised. """ def get_services(self, protocol, query="", minimize="", maximize=""): - """ Return all services that match the specified query. + """Return all services that match the specified query. The protocol can be an actual class or interface, or the *name* of a class or interface in the form '.'. @@ -76,7 +76,7 @@ class or interface in the form '.'. """ def get_service_properties(self, service_id): - """ Return the dictionary of properties associated with a service. + """Return the dictionary of properties associated with a service. If no such service exists a 'ValueError' exception is raised. @@ -86,7 +86,7 @@ def get_service_properties(self, service_id): """ def register_service(self, protocol, obj, properties=None): - """ Register a service. + """Register a service. The protocol can be an actual class or interface, or the *name* of a class or interface in the form:: @@ -111,14 +111,14 @@ class or interface in the form:: """ def set_service_properties(self, service_id, properties): - """ Set the dictionary of properties associated with a service. + """Set the dictionary of properties associated with a service. If no such service exists a 'ValueError' exception is raised. """ def unregister_service(self, service_id): - """ Unregister a service. + """Unregister a service. If no such service exists a 'ValueError' exception is raised. diff --git a/envisage/i_service_user.py b/envisage/i_service_user.py index ef6028775..118d66557 100644 --- a/envisage/i_service_user.py +++ b/envisage/i_service_user.py @@ -18,7 +18,7 @@ class IServiceUser(Interface): - """ The interface for objects using the 'Service' trait type. """ + """The interface for objects using the 'Service' trait type.""" # The service registry that the object's services are stored in. service_registry = Instance(IServiceRegistry) diff --git a/envisage/ids.py b/envisage/ids.py index 57ffa6e25..63c5eca4d 100644 --- a/envisage/ids.py +++ b/envisage/ids.py @@ -20,33 +20,33 @@ #: Extension Point to contribute preference files, defined on the #: ``CorePlugin``. -PREFERENCES = 'envisage.preferences' +PREFERENCES = "envisage.preferences" #: Extension Point to contribute ``ServiceOffer`` s, defined on the #: ``CorePlugin``. -SERVICE_OFFERS = 'envisage.service_offers' +SERVICE_OFFERS = "envisage.service_offers" # NOTE : The other PythonShellPlugin defines extension points with the same ID. #: Extension Point to contribute name/value pairs that will be bound to the #: ``PythonShell``, defined on the ``PythonShellPlugin``. -BINDINGS = 'envisage.plugins.python_shell.bindings' +BINDINGS = "envisage.plugins.python_shell.bindings" #: Extension Point to contribute commands that will be executed in the #: ``PythonShell``, defined on the ``PythonShellPlugin``. -COMMANDS = 'envisage.plugins.python_shell.commands' +COMMANDS = "envisage.plugins.python_shell.commands" #: Extension Point to contribute preferences categories, defined on the #: ``TasksPlugin``. -PREFERENCES_CATEGORIES = 'envisage.ui.tasks.preferences_categories' +PREFERENCES_CATEGORIES = "envisage.ui.tasks.preferences_categories" #: Extension Point to contribute preference panes, defined on the #: ``TasksPlugin``. -PREFERENCES_PANES = 'envisage.ui.tasks.preferences_panes' +PREFERENCES_PANES = "envisage.ui.tasks.preferences_panes" #: Extension Point to contribute task factories, defined on the #: ``TasksPlugin``. -TASKS = 'envisage.ui.tasks.tasks' +TASKS = "envisage.ui.tasks.tasks" #: Extension Point to contribute task extensions, defined on the #: ``TasksPlugin``. -TASK_EXTENSIONS = 'envisage.ui.tasks.task_extensions' +TASK_EXTENSIONS = "envisage.ui.tasks.task_extensions" diff --git a/envisage/import_manager.py b/envisage/import_manager.py index 8c3af62af..56a02d73d 100644 --- a/envisage/import_manager.py +++ b/envisage/import_manager.py @@ -20,7 +20,7 @@ @provides(IImportManager) class ImportManager(HasTraits): - """ The default import manager implementation. + """The default import manager implementation. Its just a guess, but I think using an import manager to do all imports will make debugging easier (as opposed to just letting imports happen from @@ -33,7 +33,7 @@ class ImportManager(HasTraits): ########################################################################### def import_symbol(self, symbol_path): - """ Import the symbol defined by the specified symbol path. """ + """Import the symbol defined by the specified symbol path.""" if ":" in symbol_path: module_name, symbol_name = symbol_path.split(":") diff --git a/envisage/package_plugin_manager.py b/envisage/package_plugin_manager.py index dff79b5b1..0de01d8b1 100644 --- a/envisage/package_plugin_manager.py +++ b/envisage/package_plugin_manager.py @@ -19,12 +19,11 @@ from .plugin_manager import PluginManager - logger = logging.getLogger(__name__) class PackagePluginManager(PluginManager): - """ A plugin manager that finds plugins in packages on the 'plugin_path'. + """A plugin manager that finds plugins in packages on the 'plugin_path'. All items in 'plugin_path' are directory names and they are all added to 'sys.path' (if not already present). Each directory is then searched for @@ -68,7 +67,7 @@ def _update_path_and_reset_plugins(self, obj, trait_name, removed, added): #### Protected 'PluginManager' protocol ################################### def __plugins_default(self): - """ Trait initializer. """ + """Trait initializer.""" plugins = [ plugin @@ -83,7 +82,7 @@ def __plugins_default(self): #### Private protocol ##################################################### def _get_plugins_module(self, package_name): - """ Import 'plugins.py' from the package with the given name. + """Import 'plugins.py' from the package with the given name. If the package does not exist, or does not contain 'plugins.py' then return None. @@ -102,7 +101,7 @@ def _get_plugins_module(self, package_name): # smell: Looooong and ugly! def _harvest_plugins_in_package(self, package_name, package_dirname): - """ Harvest plugins found in the given package. """ + """Harvest plugins found in the given package.""" # If the package contains a 'plugins.py' module, then we import it and # look for a callable 'get_plugins' that takes no arguments and returns @@ -136,7 +135,7 @@ def _harvest_plugins_in_package(self, package_name, package_dirname): return plugins def _harvest_plugins_in_packages(self): - """ Harvest plugins found in packages on the plugin path. """ + """Harvest plugins found in packages on the plugin path.""" plugins = [] for dirname in self.plugin_path: @@ -151,7 +150,7 @@ def _harvest_plugins_in_packages(self): return plugins def _update_sys_dot_path(self, removed, added): - """ Add/remove the given entries from sys.path. """ + """Add/remove the given entries from sys.path.""" for dirname in removed: if dirname in sys.path: diff --git a/envisage/plugin.py b/envisage/plugin.py index 832b5fd40..ae68a240b 100644 --- a/envisage/plugin.py +++ b/envisage/plugin.py @@ -15,7 +15,7 @@ from os.path import exists, join # Enthought library imports. -from traits.api import Instance, List, Property, Str, provides +from traits.api import Instance, List, Property, provides, Str from traits.util.camel_case import camel_case_to_words # Local imports. @@ -36,7 +36,7 @@ @provides(IPlugin, IExtensionPointUser, IServiceUser) class Plugin(ExtensionProvider): - """ The default implementation of the 'IPlugin' interface. + """The default implementation of the 'IPlugin' interface. This class is intended to be subclassed for each plugin that you create. @@ -92,7 +92,7 @@ class Plugin(ExtensionProvider): ########################################################################### def _get_extension_registry(self): - """ Trait property getter. """ + """Trait property getter.""" return self.application @@ -101,7 +101,7 @@ def _get_extension_registry(self): ########################################################################### def _get_service_registry(self): - """ Trait property getter. """ + """Trait property getter.""" return self.application @@ -110,7 +110,7 @@ def _get_service_registry(self): ########################################################################### def get_extension_points(self): - """ Return the extension points offered by the provider. """ + """Return the extension points offered by the provider.""" extension_points = [ trait.trait_type @@ -120,7 +120,7 @@ def get_extension_points(self): return extension_points def get_extensions(self, extension_point_id): - """ Return the provider's extensions to an extension point. """ + """Return the provider's extensions to an extension point.""" # Each class can have at most *one* trait that contributes to a # particular extension point. @@ -148,7 +148,7 @@ def get_extensions(self, extension_point_id): #### Trait initializers ################################################### def _home_default(self): - """ Trait initializer. """ + """Trait initializer.""" # Each plugin gets a sub-directory of a 'plugins' directory in # 'application.home'. @@ -166,23 +166,25 @@ def _home_default(self): return home_dir def _id_default(self): - """ Trait initializer. """ + """Trait initializer.""" id = "%s.%s" % (type(self).__module__, type(self).__name__) logger.warning( "plugin {} has no Id - using <{}>".format( - object.__repr__(self), id) + object.__repr__(self), id + ) ) return id def _name_default(self): - """ Trait initializer. """ + """Trait initializer.""" name = camel_case_to_words(type(self).__name__) logger.warning( "plugin {} has no name - using <{}>".format( - object.__repr__(self), name) + object.__repr__(self), name + ) ) return name @@ -190,7 +192,7 @@ def _name_default(self): #### Methods ############################################################## def start(self): - """ Start the plugin. + """Start the plugin. This method will *always* be empty so that you never have to call 'super().start()' if you provide an implementation in a @@ -204,7 +206,7 @@ def start(self): pass def stop(self): - """ Stop the plugin. + """Stop the plugin. This method will *always* be empty so that you never have to call 'super().stop()' if you provide an implementation in a @@ -222,7 +224,7 @@ def stop(self): ########################################################################### def connect_extension_point_traits(self): - """ Connect all of the plugin's extension points. + """Connect all of the plugin's extension points. This means that the plugin will be notified if and when contributions are add or removed. @@ -232,12 +234,12 @@ def connect_extension_point_traits(self): ExtensionPoint.connect_extension_point_traits(self) def disconnect_extension_point_traits(self): - """ Disconnect all of the plugin's extension points.""" + """Disconnect all of the plugin's extension points.""" ExtensionPoint.disconnect_extension_point_traits(self) def register_services(self): - """ Register the services offered by the plugin. """ + """Register the services offered by the plugin.""" for trait_name, trait in self.traits(service=True).items(): logger.warning( @@ -256,7 +258,7 @@ def register_services(self): self._service_ids.append(service_id) def unregister_services(self): - """ Unregister any service offered by the plugin. """ + """Unregister any service offered by the plugin.""" # Unregister the services in the reverse order that we registered # them. @@ -282,7 +284,7 @@ def unregister_services(self): #### Trait change handlers ################################################ def _anytrait_changed(self, trait_name, old, new): - """ Static trait change handler. """ + """Static trait change handler.""" # Ignore the '_items' part of the trait name (if it is there!), and get # the actual trait. @@ -310,7 +312,7 @@ def _anytrait_changed(self, trait_name, old, new): #### Methods ############################################################## def _create_multiple_traits_exception(self, extension_point_id): - """ Create the exception raised when multiple traits are found. """ + """Create the exception raised when multiple traits are found.""" exception = ValueError( "multiple traits for extension point <%s> in plugin <%s>" @@ -320,7 +322,7 @@ def _create_multiple_traits_exception(self, extension_point_id): return exception def _get_extensions_from_trait(self, trait_name): - """ Return the extensions contributed via the specified trait. """ + """Return the extensions contributed via the specified trait.""" try: extensions = getattr(self, trait_name) @@ -334,7 +336,7 @@ def _get_extensions_from_trait(self, trait_name): return extensions def _get_service_protocol(self, trait): - """ Determine the protocol to register a service trait with. """ + """Determine the protocol to register a service trait with.""" # If a specific protocol was specified then use it. if trait.service_protocol is not None: @@ -354,7 +356,7 @@ def _get_service_protocol(self, trait): return protocol def _register_service_factory(self, trait_name, trait): - """ Register a service factory for the specified trait. """ + """Register a service factory for the specified trait.""" # Determine the protocol that the service should be registered with. protocol = self._get_service_protocol(trait) @@ -364,7 +366,7 @@ def _register_service_factory(self, trait_name, trait): # (this could obviously be a lambda function, but I thought it best to # be more explicit 8^). def factory(**properties): - """ A service factory. """ + """A service factory.""" return getattr(self, trait_name) @@ -375,5 +377,5 @@ def factory(**properties): ########################################################################### def __repr__(self): - """ String representation of a Plugin object """ + """String representation of a Plugin object""" return f"{type(self).__name__}(id={self.id!r}, name={self.name!r})" diff --git a/envisage/plugin_activator.py b/envisage/plugin_activator.py index 574fae403..4b9a280e5 100644 --- a/envisage/plugin_activator.py +++ b/envisage/plugin_activator.py @@ -19,14 +19,14 @@ @provides(IPluginActivator) class PluginActivator(HasTraits): - """ The default plugin activator. """ + """The default plugin activator.""" ########################################################################### # 'IPluginActivator' interface. ########################################################################### def start_plugin(self, plugin): - """ Start the specified plugin. """ + """Start the specified plugin.""" # Connect all of the plugin's extension point traits so that the plugin # will be notified if and when contributions are added or removed. @@ -39,7 +39,7 @@ def start_plugin(self, plugin): plugin.start() def stop_plugin(self, plugin): - """ Stop the specified plugin. """ + """Stop the specified plugin.""" # Plugin specific stop. plugin.stop() diff --git a/envisage/plugin_event.py b/envisage/plugin_event.py index 6e3f9379c..cbff3c3a7 100644 --- a/envisage/plugin_event.py +++ b/envisage/plugin_event.py @@ -15,7 +15,7 @@ class PluginEvent(Vetoable): - """ A plugin event. """ + """A plugin event.""" # The plugin that the event is for. plugin = Instance("envisage.api.IPlugin") diff --git a/envisage/plugin_extension_registry.py b/envisage/plugin_extension_registry.py index 78761c0de..7adeed5be 100644 --- a/envisage/plugin_extension_registry.py +++ b/envisage/plugin_extension_registry.py @@ -19,7 +19,7 @@ class PluginExtensionRegistry(ProviderExtensionRegistry): - """ An extension registry that uses plugins as extension providers. + """An extension registry that uses plugins as extension providers. The application's plugins are used as the registries providers so adding or removing a plugin affects the extension points and extensions etc. @@ -39,7 +39,7 @@ class PluginExtensionRegistry(ProviderExtensionRegistry): @observe("plugin_manager") def _update_providers(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" old, new = event.old, event.new # In practise I can't see why you would ever want (or need) to change @@ -55,12 +55,12 @@ def _update_providers(self, event): @on_trait_change("plugin_manager:plugin_added") def _on_plugin_added(self, obj, trait_name, old, event): - """ Dynamic trait change handler. """ + """Dynamic trait change handler.""" self.add_provider(event.plugin) @on_trait_change("plugin_manager:plugin_removed") def _on_plugin_removed(self, obj, trait_name, old, event): - """ Dynamic trait change handler. """ + """Dynamic trait change handler.""" self.remove_provider(event.plugin) diff --git a/envisage/plugin_manager.py b/envisage/plugin_manager.py index d7c1e9cf9..882149e62 100644 --- a/envisage/plugin_manager.py +++ b/envisage/plugin_manager.py @@ -10,9 +10,9 @@ """ A simple plugin manager implementation. """ -from fnmatch import fnmatch import logging import warnings +from fnmatch import fnmatch from traits.api import Event, HasTraits, Instance, List, observe, provides, Str @@ -21,13 +21,12 @@ from .i_plugin_manager import IPluginManager from .plugin_event import PluginEvent - logger = logging.getLogger(__name__) @provides(IPluginManager) class PluginManager(HasTraits): - """ A simple plugin manager implementation. + """A simple plugin manager implementation. This implementation manages an explicit collection of plugin instances, e.g:: @@ -54,7 +53,7 @@ class PluginManager(HasTraits): @observe("application") def _set_new_application_on_all_plugins(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" self._update_application_on_plugins([], self._plugins) @@ -74,7 +73,7 @@ def _set_new_application_on_all_plugins(self, event): #### 'object' protocol #################################################### def __init__(self, plugins=None, **traits): - """ Constructor. + """Constructor. We allow the caller to specify an initial list of plugins, but the list itself is not part of the public API. To add and remove plugins @@ -98,7 +97,7 @@ def __init__(self, plugins=None, **traits): self._plugins = plugins def __iter__(self): - """ Return an iterator over the manager's plugins. """ + """Return an iterator over the manager's plugins.""" plugins = [ plugin @@ -111,13 +110,13 @@ def __iter__(self): #### 'IPluginManager' protocol ############################################ def add_plugin(self, plugin): - """ Add a plugin to the manager. """ + """Add a plugin to the manager.""" self._plugins.append(plugin) self.plugin_added = PluginEvent(plugin=plugin) def get_plugin(self, plugin_id): - """ Return the plugin with the specified Id. """ + """Return the plugin with the specified Id.""" for plugin in self._plugins: if plugin_id == plugin.id: @@ -132,19 +131,19 @@ def get_plugin(self, plugin_id): return plugin def remove_plugin(self, plugin): - """ Remove a plugin from the manager. """ + """Remove a plugin from the manager.""" self._plugins.remove(plugin) self.plugin_removed = PluginEvent(plugin=plugin) def start(self): - """ Start the plugin manager. """ + """Start the plugin manager.""" for plugin in self._plugins: self.start_plugin(plugin) def start_plugin(self, plugin=None, plugin_id=None): - """ Start the specified plugin. """ + """Start the specified plugin.""" plugin = plugin or self.get_plugin(plugin_id) if plugin is not None: @@ -156,7 +155,7 @@ def start_plugin(self, plugin=None, plugin_id=None): raise ValueError("no such plugin %s" % plugin_id) def stop(self): - """ Stop the plugin manager. """ + """Stop the plugin manager.""" # We stop the plugins in the reverse order that they were started. stop_order = self._plugins[:] @@ -166,7 +165,7 @@ def stop(self): self.stop_plugin(plugin) def stop_plugin(self, plugin=None, plugin_id=None): - """ Stop the specified plugin. """ + """Stop the specified plugin.""" plugin = plugin or self.get_plugin(plugin_id) if plugin is not None: @@ -184,18 +183,18 @@ def stop_plugin(self, plugin=None, plugin_id=None): @observe("_plugins") def _update_application_on_all_plugins(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" old, new = event.old, event.new self._update_application_on_plugins(old, new) @observe("_plugins:items") def _update_application_on_changed_plugins(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" self._update_application_on_plugins(event.removed, event.added) def _include_plugin(self, plugin_id): - """ Return True if the plugin should be included. + """Return True if the plugin should be included. This is just shorthand for:- @@ -211,7 +210,7 @@ def _include_plugin(self, plugin_id): #### Private protocol ##################################################### def _is_excluded(self, plugin_id): - """ Return True if the plugin Id is excluded. + """Return True if the plugin Id is excluded. If no 'exclude' patterns are specified then this method returns False for all plugin Ids. @@ -228,7 +227,7 @@ def _is_excluded(self, plugin_id): return False def _is_included(self, plugin_id): - """ Return True if the plugin Id is included. + """Return True if the plugin Id is included. If no 'include' patterns are specified then this method returns True for all plugin Ids. @@ -245,7 +244,7 @@ def _is_included(self, plugin_id): return False def _update_application_on_plugins(self, removed, added): - """ Update the 'application' trait of plugins added/removed. """ + """Update the 'application' trait of plugins added/removed.""" for plugin in removed: plugin.application = None diff --git a/envisage/plugins/event_manager/plugin.py b/envisage/plugins/event_manager/plugin.py index acd4e22ff..d7ac3169e 100644 --- a/envisage/plugins/event_manager/plugin.py +++ b/envisage/plugins/event_manager/plugin.py @@ -15,13 +15,14 @@ of the application to the created event manager. """ +from traits.api import List + # Enthought library imports. from envisage.api import Plugin, ServiceOffer -from traits.api import List class EventManagerPlugin(Plugin): - """ Plugin to add event manager to the application. """ + """Plugin to add event manager to the application.""" id = "envisage.event_manager" @@ -32,6 +33,7 @@ def _service_offers_default(self): from encore.events.api import BaseEventManager, get_event_manager evt_mgr_service_offer = ServiceOffer( - protocol=BaseEventManager, factory=get_event_manager, + protocol=BaseEventManager, + factory=get_event_manager, ) return [evt_mgr_service_offer] diff --git a/envisage/plugins/python_shell/i_python_shell.py b/envisage/plugins/python_shell/i_python_shell.py index 4e7b65c59..7296544b1 100644 --- a/envisage/plugins/python_shell/i_python_shell.py +++ b/envisage/plugins/python_shell/i_python_shell.py @@ -15,24 +15,16 @@ class IPythonShell(Interface): - """ A simple interface for the Python shell. """ + """A simple interface for the Python shell.""" def bind(self, name, value): - """ Binds a name to a value in the interpreter's namespace. - - """ + """Binds a name to a value in the interpreter's namespace.""" def execute_command(self, command, hidden=True): - """ Execute a command in the interpreter. - - """ + """Execute a command in the interpreter.""" def execute_file(self, path, hidden=True): - """ Execute a file in the interpreter. - - """ + """Execute a file in the interpreter.""" def lookup(self, name): - """ Returns the value bound to a name in the interpreter's namespace. - - """ + """Returns the value bound to a name in the interpreter's namespace.""" diff --git a/envisage/plugins/python_shell/python_shell_plugin.py b/envisage/plugins/python_shell/python_shell_plugin.py index bdcd260d2..b80870c0c 100644 --- a/envisage/plugins/python_shell/python_shell_plugin.py +++ b/envisage/plugins/python_shell/python_shell_plugin.py @@ -10,13 +10,14 @@ """ The interactive Python shell plugin. """ +from traits.api import Dict, List, Str + # Enthought library imports. from envisage.api import ExtensionPoint, Plugin -from traits.api import Dict, List, Str class PythonShellPlugin(Plugin): - """ The interactive Python shell plugin. """ + """The interactive Python shell plugin.""" # Extension point Ids. BINDINGS = "envisage.plugins.python_shell.bindings" @@ -73,7 +74,7 @@ class PythonShellPlugin(Plugin): contributed_bindings = List(contributes_to=BINDINGS) def _contributed_bindings_default(self): - """ Trait initializer. """ + """Trait initializer.""" return [{"application": self.application}] @@ -81,10 +82,10 @@ def _contributed_bindings_default(self): contributed_views = List(contributes_to=VIEWS) def _contributed_views_default(self): - """ Trait initializer. """ + """Trait initializer.""" # Local imports. - from .view.python_shell_view import PythonShellView from .view.namespace_view import NamespaceView + from .view.python_shell_view import PythonShellView return [PythonShellView, NamespaceView] diff --git a/envisage/plugins/python_shell/view/namespace_view.py b/envisage/plugins/python_shell/view/namespace_view.py index 038180197..58013dfb7 100644 --- a/envisage/plugins/python_shell/view/namespace_view.py +++ b/envisage/plugins/python_shell/view/namespace_view.py @@ -11,31 +11,30 @@ # Enthought library imports. -from envisage.plugins.python_shell.api import IPythonShell -from envisage.plugins.python_shell.view.python_shell_view import ( - PythonShellView, -) - from pyface.workbench.api import View - from traits.api import ( + cached_property, + DelegatesTo, HasTraits, - Str, - Property, - List, Instance, - DelegatesTo, - cached_property, + List, + Property, + Str, ) - from traitsui.api import Item, TableEditor, VGroup from traitsui.api import View as TraitsView from traitsui.table_column import ObjectColumn -from traitsui.table_filter import RuleTableFilter -from traitsui.table_filter import MenuFilterTemplate -from traitsui.table_filter import EvalFilterTemplate -from traitsui.table_filter import RuleFilterTemplate +from traitsui.table_filter import ( + EvalFilterTemplate, + MenuFilterTemplate, + RuleFilterTemplate, + RuleTableFilter, +) +from envisage.plugins.python_shell.api import IPythonShell +from envisage.plugins.python_shell.view.python_shell_view import ( + PythonShellView, +) # Table editor definition: filters = [EvalFilterTemplate, MenuFilterTemplate, RuleFilterTemplate] @@ -82,7 +81,7 @@ def module_to_str(obj): class NamespaceView(View): - """ A view containing the contents of the Python shell namespace. """ + """A view containing the contents of the Python shell namespace.""" #### 'IView' interface #################################################### @@ -127,7 +126,7 @@ class NamespaceView(View): ########################################################################### def create_control(self, parent): - """ Creates the toolkit-specific control that represents the view. + """Creates the toolkit-specific control that represents the view. 'parent' is the toolkit-specific control that is the view's parent. @@ -149,7 +148,7 @@ def create_control(self, parent): @cached_property def _get_bindings(self): - """ Property getter. """ + """Property getter.""" if self.shell_view is None: return [] diff --git a/envisage/plugins/python_shell/view/python_shell_view.py b/envisage/plugins/python_shell/view/python_shell_view.py index 40248fc83..260a3dc1d 100644 --- a/envisage/plugins/python_shell/view/python_shell_view.py +++ b/envisage/plugins/python_shell/view/python_shell_view.py @@ -14,21 +14,20 @@ import logging import sys -# Enthought library imports. -from envisage.api import IExtensionRegistry -from envisage.api import ExtensionPoint -from envisage.plugins.python_shell.api import IPythonShell from pyface.api import PythonShell from pyface.workbench.api import View from traits.api import Any, Dict, Event, Instance, Property, provides, Str +# Enthought library imports. +from envisage.api import ExtensionPoint, IExtensionRegistry +from envisage.plugins.python_shell.api import IPythonShell + # Setup a logger for this module. logger = logging.getLogger(__name__) class PseudoFile(object): - """ Simulates a normal File object. - """ + """Simulates a normal File object.""" def __init__(self, write): self.write = write @@ -49,7 +48,7 @@ def isatty(self): @provides(IPythonShell) class PythonShellView(View): - """ A view containing an interactive Python shell. """ + """A view containing an interactive Python shell.""" #### 'IView' interface #################################################### @@ -95,7 +94,7 @@ class PythonShellView(View): ########################################################################### def _get_extension_registry(self): - """ Trait property getter. """ + """Trait property getter.""" return self.window.application @@ -104,7 +103,7 @@ def _get_extension_registry(self): ########################################################################### def create_control(self, parent): - """ Creates the toolkit-specific control that represents the view. """ + """Creates the toolkit-specific control that represents the view.""" self.shell = shell = PythonShell(parent) shell.on_trait_change(self._on_key_pressed, "key_pressed") @@ -139,9 +138,7 @@ def create_control(self, parent): return self.shell.control def destroy_control(self): - """ Destroys the toolkit-specific control that represents the view. - - """ + """Destroys the toolkit-specific control that represents the view.""" super().destroy_control() @@ -161,36 +158,34 @@ def destroy_control(self): #### Properties ########################################################### def _get_namespace(self): - """ Property getter. """ + """Property getter.""" return self.shell.interpreter().locals def _get_names(self): - """ Property getter. """ + """Property getter.""" return list(self.shell.interpreter().locals.keys()) #### Methods ############################################################## def bind(self, name, value): - """ Binds a name to a value in the interpreter's namespace. """ + """Binds a name to a value in the interpreter's namespace.""" self.shell.bind(name, value) def execute_command(self, command, hidden=True): - """ Execute a command in the interpreter. """ + """Execute a command in the interpreter.""" return self.shell.execute_command(command, hidden) def execute_file(self, path, hidden=True): - """ Execute a command in the interpreter. """ + """Execute a command in the interpreter.""" return self.shell.execute_file(path, hidden) def lookup(self, name): - """ Returns the value bound to a name in the interpreter's namespace. - - """ + """Returns the value bound to a name in the interpreter's namespace.""" return self.shell.interpreter().locals[name] @@ -199,14 +194,14 @@ def lookup(self, name): ########################################################################### def _write_stdout(self, text): - """ Handles text written to stdout. """ + """Handles text written to stdout.""" self.stdout_text = text #### Trait change handlers ################################################ def _on_command_executed(self, shell): - """ Dynamic trait change handler. """ + """Dynamic trait change handler.""" if self.control is not None: # Get the set of tuples of names and types in the current @@ -225,7 +220,7 @@ def _on_command_executed(self, shell): self.trait_property_changed("names", [], self.names) def _on_key_pressed(self, event): - """ Dynamic trait change handler. """ + """Dynamic trait change handler.""" if event.alt_down and event.key_code == 317: zoom = self.shell.control.GetZoom() @@ -238,6 +233,6 @@ def _on_key_pressed(self, event): self.shell.control.SetZoom(zoom - 1) def _on_write_stdout(self, text): - """ Dynamic trait change handler. """ + """Dynamic trait change handler.""" self.shell.control.write(text) diff --git a/envisage/plugins/tasks/python_shell_plugin.py b/envisage/plugins/tasks/python_shell_plugin.py index ee9271c48..ff611f034 100644 --- a/envisage/plugins/tasks/python_shell_plugin.py +++ b/envisage/plugins/tasks/python_shell_plugin.py @@ -17,10 +17,12 @@ # Standard library imports. import logging -# Enthought library imports. -from traits.api import Str, List, Dict, Instance, Property from pyface.tasks.contrib.python_shell import PythonShellTask -from envisage.api import Plugin, ExtensionPoint, IExtensionRegistry + +# Enthought library imports. +from traits.api import Dict, Instance, List, Property, Str + +from envisage.api import ExtensionPoint, IExtensionRegistry, Plugin from envisage.ui.tasks.api import TaskFactory logger = logging.getLogger() @@ -30,7 +32,7 @@ class EnvisagePythonShellTask(PythonShellTask): - """ Subclass of PythonShellTask that gets its bindings and commands from + """Subclass of PythonShellTask that gets its bindings and commands from an Envisage ExtensionPoint """ @@ -54,8 +56,7 @@ def _get_extension_registry(self): class PythonShellPlugin(Plugin): - """ A tasks plugin to display a simple Python shell to the user. - """ + """A tasks plugin to display a simple Python shell to the user.""" # Extension point IDs. BINDINGS = BINDINGS @@ -116,7 +117,8 @@ def start(self): logger.debug("started python shell plugin") def _contributed_bindings_default(self): - """ By default, expose the Envisage application object to the namespace + """ + By default, expose the Envisage application object to the namespace """ return [{"application": self.application}] diff --git a/envisage/plugins/text_editor/actions.py b/envisage/plugins/text_editor/actions.py index 1c8b77759..bd043d475 100644 --- a/envisage/plugins/text_editor/actions.py +++ b/envisage/plugins/text_editor/actions.py @@ -10,8 +10,8 @@ import logging from apptools.io.api import File -from pyface.api import FileDialog, OK from pyface.action.api import Action +from pyface.api import FileDialog, OK from traits.api import Any from .editor.text_editor import TextEditor @@ -20,8 +20,7 @@ class NewFileAction(Action): - """ Open a new file in the text editor. - """ + """Open a new file in the text editor.""" tooltip = "Create a new file for editing" description = "Create a new file for editing" @@ -37,8 +36,7 @@ def perform(self, event=None): class OpenFileAction(Action): - """ Open an existing file in the text editor. - """ + """Open an existing file in the text editor.""" tooltip = "Open a file for editing" description = "Open a file for editing" diff --git a/envisage/plugins/text_editor/api.py b/envisage/plugins/text_editor/api.py index f18948835..da7a1bf36 100644 --- a/envisage/plugins/text_editor/api.py +++ b/envisage/plugins/text_editor/api.py @@ -7,5 +7,5 @@ # is also available online at http://www.enthought.com/licenses/BSD.txt # # Thanks for using Enthought open source! -from .text_editor_action_set import TextEditorActionSet from .editor.text_editor import TextEditor +from .text_editor_action_set import TextEditorActionSet diff --git a/envisage/plugins/text_editor/editor/text_editor.py b/envisage/plugins/text_editor/editor/text_editor.py index f25f54d33..a063bbd8f 100644 --- a/envisage/plugins/text_editor/editor/text_editor.py +++ b/envisage/plugins/text_editor/editor/text_editor.py @@ -13,9 +13,10 @@ # Standard library imports. from os.path import basename +from pyface.api import CANCEL, FileDialog + # Enthought library imports. from pyface.workbench.api import TraitsUIEditor -from pyface.api import FileDialog, CANCEL from traits.api import Code, Instance, observe from traitsui.api import CodeEditor, Group, Item, View from traitsui.key_bindings import KeyBinding, KeyBindings @@ -26,7 +27,7 @@ def _id_generator(): - """ A generator that returns the next number for untitled files. """ + """A generator that returns the next number for untitled files.""" i = 1 while True: @@ -38,7 +39,7 @@ def _id_generator(): class TextEditor(TraitsUIEditor): - """ A text editor. """ + """A text editor.""" #### 'TextEditor' interface ############################################### @@ -53,7 +54,7 @@ class TextEditor(TraitsUIEditor): ########################################################################### def save(self): - """ Saves the text to disk. """ + """Saves the text to disk.""" # If the file has not yet been saved then prompt for the file name. if len(self.obj.path) == 0: @@ -67,7 +68,7 @@ def save(self): self.dirty = False def save_as(self): - """ Saves the text to disk after prompting for the file name. """ + """Saves the text to disk after prompting for the file name.""" dialog = FileDialog( parent=self.window.control, @@ -91,7 +92,7 @@ def save_as(self): ########################################################################### def create_ui(self, parent): - """ Creates the traits UI that represents the editor. """ + """Creates the traits UI that represents the editor.""" ui = self.edit_traits( parent=parent, view=self._create_traits_ui_view(), kind="subpanel" @@ -104,7 +105,7 @@ def create_ui(self, parent): ########################################################################### def run(self): - """ Runs the file as Python. """ + """Runs the file as Python.""" # The file must be saved first! self.save() @@ -121,7 +122,7 @@ def run(self): ) def select_line(self, lineno): - """ Selects the specified line. """ + """Selects the specified line.""" self.ui.info.text.selected_line = lineno @@ -132,7 +133,7 @@ def select_line(self, lineno): #### Trait initializers ################################################### def _key_bindings_default(self): - """ Trait initializer. """ + """Trait initializer.""" key_bindings = KeyBindings( KeyBinding( @@ -153,7 +154,7 @@ def _key_bindings_default(self): @observe("obj") def _handle_update_to_object(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" new = event.new # The path will be the empty string if we are editing a file that has # not yet been saved. @@ -170,14 +171,14 @@ def _handle_update_to_object(self, event): @observe("text") def _update_dirty(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" if self.traits_inited(): self.dirty = True @observe("dirty") def _update_name(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" dirty = event.new if len(self.obj.path) > 0: if dirty: @@ -189,7 +190,7 @@ def _update_name(self, event): #### Methods ############################################################## def _create_traits_ui_view(self): - """ Create the traits UI view used by the editor. + """Create the traits UI view used by the editor. fixme: We create the view dynamically to allow the key bindings to be created dynamically (we don't use this just yet, but obviously plugins @@ -216,7 +217,7 @@ def _create_traits_ui_view(self): return view def _get_unique_id(self, prefix="Untitled "): - """ Return a unique id for a new file. """ + """Return a unique id for a new file.""" id = prefix + str(next(_id_generator)) while self.window.get_editor_by_id(id) is not None: diff --git a/envisage/plugins/text_editor/editor/text_editor_handler.py b/envisage/plugins/text_editor/editor/text_editor_handler.py index 6844f1f27..93bc04bb9 100644 --- a/envisage/plugins/text_editor/editor/text_editor_handler.py +++ b/envisage/plugins/text_editor/editor/text_editor_handler.py @@ -15,7 +15,7 @@ class TextEditorHandler(Handler): - """ The traits UI handler for the text editor. """ + """The traits UI handler for the text editor.""" ########################################################################### # 'TextEditorHandler' interface. @@ -25,11 +25,11 @@ class TextEditorHandler(Handler): # dynamically! Plugins will want to add bindings to the editor to bind # a key to an action. def run(self, info): - """ Run the text as Python code. """ + """Run the text as Python code.""" info.object.run() def save(self, info): - """ Save the text to disk. """ + """Save the text to disk.""" info.object.save() diff --git a/envisage/plugins/text_editor/text_editor_action_set.py b/envisage/plugins/text_editor/text_editor_action_set.py index a921868e1..358f9cdd6 100644 --- a/envisage/plugins/text_editor/text_editor_action_set.py +++ b/envisage/plugins/text_editor/text_editor_action_set.py @@ -12,8 +12,7 @@ class TextEditorActionSet(ActionSet): - """ The default action set for the Text Editor plugin. - """ + """The default action set for the Text Editor plugin.""" groups = [ Group(id="TextFileGroup", path="MenuBar/File", before="ExitGroup") diff --git a/envisage/plugins/text_editor/text_editor_plugin.py b/envisage/plugins/text_editor/text_editor_plugin.py index dae5835a9..0648f6853 100644 --- a/envisage/plugins/text_editor/text_editor_plugin.py +++ b/envisage/plugins/text_editor/text_editor_plugin.py @@ -13,8 +13,8 @@ # Enthought library imports. from traits.api import List -from envisage.api import Plugin +from envisage.api import Plugin # The plugin's globally unique identifier (also used as the prefix for all # identifiers defined in this module). @@ -22,8 +22,7 @@ class TextEditorPlugin(Plugin): - """ Text Editor plugin for the Workbench UI. - """ + """Text Editor plugin for the Workbench UI.""" name = "Text Editor plugin" diff --git a/envisage/provider_extension_registry.py b/envisage/provider_extension_registry.py index 855f5317e..cd16f7457 100644 --- a/envisage/provider_extension_registry.py +++ b/envisage/provider_extension_registry.py @@ -14,21 +14,20 @@ import logging # Enthought library imports. -from traits.api import List, provides, on_trait_change +from traits.api import List, on_trait_change, provides # Local imports. from .extension_registry import ExtensionRegistry from .i_extension_provider import IExtensionProvider from .i_provider_extension_registry import IProviderExtensionRegistry - # Logging. logger = logging.getLogger(__name__) @provides(IProviderExtensionRegistry) class ProviderExtensionRegistry(ExtensionRegistry): - """ An extension registry implementation with multiple providers. """ + """An extension registry implementation with multiple providers.""" #### Protected 'ProviderExtensionRegistry' interface ###################### @@ -40,7 +39,7 @@ class ProviderExtensionRegistry(ExtensionRegistry): ########################################################################### def set_extensions(self, extension_point_id, extensions): - """ Set the extensions to an extension point. """ + """Set the extensions to an extension point.""" raise TypeError("extension points cannot be set") @@ -49,7 +48,7 @@ def set_extensions(self, extension_point_id, extensions): ########################################################################### def add_provider(self, provider): - """ Add an extension provider. """ + """Add an extension provider.""" events = self._add_provider(provider) @@ -57,12 +56,12 @@ def add_provider(self, provider): self._call_listeners(refs, extension_point_id, added, [], index) def get_providers(self): - """ Return all of the providers in the registry. """ + """Return all of the providers in the registry.""" return self._providers[:] def remove_provider(self, provider): - """ Remove an extension provider. + """Remove an extension provider. Raise a 'ValueError' if the provider is not in the registry. @@ -78,7 +77,7 @@ def remove_provider(self, provider): ########################################################################### def _get_extensions(self, extension_point_id): - """ Return the extensions for the given extension point. """ + """Return the extensions for the given extension point.""" # If we don't know about the extension point then it sure ain't got # any extensions! @@ -119,7 +118,7 @@ def _get_extensions(self, extension_point_id): ########################################################################### def _add_provider(self, provider): - """ Add a new provider. """ + """Add a new provider.""" # Add the provider's extension points. self._add_provider_extension_points(provider) @@ -133,7 +132,7 @@ def _add_provider(self, provider): return events def _add_provider_extensions(self, provider): - """ Add a provider's extensions to the registry. """ + """Add a provider's extensions to the registry.""" # Each provider can contribute to multiple extension points, so we # build up a dictionary of the 'ExtensionPointChanged' events that we @@ -158,13 +157,13 @@ def _add_provider_extensions(self, provider): return events def _add_provider_extension_points(self, provider): - """ Add a provider's extension points to the registry. """ + """Add a provider's extension points to the registry.""" for extension_point in provider.get_extension_points(): self._extension_points[extension_point.id] = extension_point def _remove_provider(self, provider): - """ Remove a provider. """ + """Remove a provider.""" # Remove the provider's extensions. events = self._remove_provider_extensions(provider) @@ -178,7 +177,7 @@ def _remove_provider(self, provider): return events def _remove_provider_extensions(self, provider): - """ Remove a provider's extensions from the registry. """ + """Remove a provider's extensions from the registry.""" # Each provider can contribute to multiple extension points, so we # build up a dictionary of the 'ExtensionPointChanged' events that we @@ -206,7 +205,7 @@ def _remove_provider_extensions(self, provider): return events def _remove_provider_extension_points(self, provider, events): - """ Remove a provider's extension points from the registry. """ + """Remove a provider's extension points from the registry.""" for extension_point in provider.get_extension_points(): # Remove the extension point. @@ -220,7 +219,7 @@ def _remove_provider_extension_points(self, provider, events): @on_trait_change("_providers:extension_point_changed") def _providers_extension_point_changed(self, obj, trait_name, old, event): - """ Dynamic trait change handler. """ + """Dynamic trait change handler.""" logger.debug("provider <%s> extension point changed", obj) @@ -270,7 +269,7 @@ def _providers_extension_point_changed(self, obj, trait_name, old, event): #### Methods ############################################################## def _initialize_extensions(self, extension_point_id): - """ Initialize the extensions to an extension point. """ + """Initialize the extensions to an extension point.""" # We store the extensions as a list of lists, with each inner list # containing the contributions from a single provider. @@ -283,7 +282,7 @@ def _initialize_extensions(self, extension_point_id): return extensions def _translate_index(self, index, offset): - """ Translate an event index by the given offset. """ + """Translate an event index by the given offset.""" if isinstance(index, slice): index = slice( diff --git a/envisage/resource/api.py b/envisage/resource/api.py index f36d08921..d368b8292 100644 --- a/envisage/resource/api.py +++ b/envisage/resource/api.py @@ -7,11 +7,10 @@ # is also available online at http://www.enthought.com/licenses/BSD.txt # # Thanks for using Enthought open source! -from .i_resource_protocol import IResourceProtocol -from .i_resource_manager import IResourceManager - from .file_resource_protocol import FileResourceProtocol from .http_resource_protocol import HTTPResourceProtocol +from .i_resource_manager import IResourceManager +from .i_resource_protocol import IResourceProtocol from .no_such_resource_error import NoSuchResourceError from .package_resource_protocol import PackageResourceProtocol from .resource_manager import ResourceManager diff --git a/envisage/resource/file_resource_protocol.py b/envisage/resource/file_resource_protocol.py index 292c02429..a51332993 100644 --- a/envisage/resource/file_resource_protocol.py +++ b/envisage/resource/file_resource_protocol.py @@ -23,14 +23,14 @@ @provides(IResourceProtocol) class FileResourceProtocol(HasTraits): - """ A resource protocol for a local file system. """ + """A resource protocol for a local file system.""" ########################################################################### # 'IResourceProtocol' interface. ########################################################################### def file(self, address): - """ Return a readable file-like object for the specified address. """ + """Return a readable file-like object for the specified address.""" # Opened in binary mode to be consistent with package resources. This # means, for example, that line-endings will not be converted. diff --git a/envisage/resource/http_resource_protocol.py b/envisage/resource/http_resource_protocol.py index d7a8f9981..26e32538e 100644 --- a/envisage/resource/http_resource_protocol.py +++ b/envisage/resource/http_resource_protocol.py @@ -19,14 +19,14 @@ @provides(IResourceProtocol) class HTTPResourceProtocol(HasTraits): - """ A resource protocol for HTTP documents. """ + """A resource protocol for HTTP documents.""" ########################################################################### # 'IResourceProtocol' interface. ########################################################################### def file(self, address): - """ Return a readable file-like object for the specified address. """ + """Return a readable file-like object for the specified address.""" # Do the imports here 'cos I'm not sure how much this will actually # be used. diff --git a/envisage/resource/i_resource_manager.py b/envisage/resource/i_resource_manager.py index 5aad0c3c2..a5dcb70c0 100644 --- a/envisage/resource/i_resource_manager.py +++ b/envisage/resource/i_resource_manager.py @@ -18,13 +18,13 @@ class IResourceManager(Interface): - """ The resource manager interface. """ + """The resource manager interface.""" # The protocols used by the manager to resolve resource URLs. resource_protocols = Instance(IResourceProtocol) def file(self, url): - """ Return a readable file-like object for the specified url. + """Return a readable file-like object for the specified url. Raise a 'NoSuchResourceError' if the resource does not exist. diff --git a/envisage/resource/i_resource_protocol.py b/envisage/resource/i_resource_protocol.py index 8ae0bda9a..5305a656a 100644 --- a/envisage/resource/i_resource_protocol.py +++ b/envisage/resource/i_resource_protocol.py @@ -15,10 +15,10 @@ class IResourceProtocol(Interface): - """ The interface for protocols that handle resource URLs. """ + """The interface for protocols that handle resource URLs.""" def file(self, address): - """ Return a readable file-like object for the specified address. + """Return a readable file-like object for the specified address. Raise a 'NoSuchResourceError' if the resource does not exist. diff --git a/envisage/resource/no_such_resource_error.py b/envisage/resource/no_such_resource_error.py index e4408ca9b..1864f63d8 100644 --- a/envisage/resource/no_such_resource_error.py +++ b/envisage/resource/no_such_resource_error.py @@ -11,9 +11,9 @@ class NoSuchResourceError(Exception): - """ The exception raised when trying to open a non-existent resource. """ + """The exception raised when trying to open a non-existent resource.""" def __init__(self, message=""): - """ Constructor. """ + """Constructor.""" Exception.__init__(self, message) diff --git a/envisage/resource/package_resource_protocol.py b/envisage/resource/package_resource_protocol.py index f7cb71c37..5ac040ceb 100644 --- a/envisage/resource/package_resource_protocol.py +++ b/envisage/resource/package_resource_protocol.py @@ -26,7 +26,7 @@ @provides(IResourceProtocol) class PackageResourceProtocol(HasTraits): - """ A resource protocol for package resources. + """A resource protocol for package resources. This protocol uses 'importlib.resources' to find and access resources. @@ -44,7 +44,7 @@ class PackageResourceProtocol(HasTraits): ########################################################################### def file(self, address): - """ Return a readable file-like object for the specified address. """ + """Return a readable file-like object for the specified address.""" package, *resource_path = address.split("/") @@ -52,7 +52,7 @@ def file(self, address): raise NoSuchResourceError(address) try: - f = files(package).joinpath(*resource_path).open('rb') + f = files(package).joinpath(*resource_path).open("rb") except ( ModuleNotFoundError, TypeError, # TypeError is raised if package is a module diff --git a/envisage/resource/resource_manager.py b/envisage/resource/resource_manager.py index e91dfa93a..c6c6742b9 100644 --- a/envisage/resource/resource_manager.py +++ b/envisage/resource/resource_manager.py @@ -11,7 +11,7 @@ # Enthought library imports. -from traits.api import Dict, HasTraits, Str, provides +from traits.api import Dict, HasTraits, provides, Str # Local imports. from .i_resource_manager import IResourceManager @@ -20,7 +20,7 @@ @provides(IResourceManager) class ResourceManager(HasTraits): - """ The default resource manager. """ + """The default resource manager.""" #### 'IResourceManager' interface ######################################### @@ -34,7 +34,7 @@ class ResourceManager(HasTraits): #### Trait initializers ################################################### def _resource_protocols_default(self): - """ Trait initializer. """ + """Trait initializer.""" # We do the import(s) here in case somebody wants a resource manager # that doesn't use the default protocol(s). @@ -53,7 +53,7 @@ def _resource_protocols_default(self): #### Methods ############################################################## def file(self, url): - """ Return a readable file-like object for the specified url. """ + """Return a readable file-like object for the specified url.""" protocol_name, address = url.split("://") diff --git a/envisage/resource/tests/test_resource_manager.py b/envisage/resource/tests/test_resource_manager.py index 44c04e697..2f0fb1892 100644 --- a/envisage/resource/tests/test_resource_manager.py +++ b/envisage/resource/tests/test_resource_manager.py @@ -12,18 +12,18 @@ # Standard library imports. import unittest +import urllib.request from io import StringIO from urllib.error import HTTPError -import urllib.request + try: - from importlib.resources import files, as_file + from importlib.resources import as_file, files except ImportError: - from importlib_resources import files, as_file + from importlib_resources import as_file, files # Enthought library imports. -from envisage.resource.api import ResourceManager -from envisage.resource.api import NoSuchResourceError +from envisage.resource.api import NoSuchResourceError, ResourceManager # Module to patch urlopen in during testing. url_library = urllib.request @@ -48,20 +48,20 @@ def stubout_urlopen(url): class ResourceManagerTestCase(unittest.TestCase): - """ Tests for the resource manager. """ + """Tests for the resource manager.""" ########################################################################### # 'TestCase' interface. ########################################################################### def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" self.stored_urlopen = url_library.urlopen url_library.urlopen = stubout_urlopen def tearDown(self): - """ Called immediately after each test method has been called. """ + """Called immediately after each test method has been called.""" url_library.urlopen = self.stored_urlopen @@ -70,14 +70,13 @@ def tearDown(self): ########################################################################### def test_file_resource(self): - """ file resource """ + """file resource""" rm = ResourceManager() # Get the filename of the 'api.py' file. resource = files("envisage.resource") / "api.py" with as_file(resource) as path: - # Open a file resource. f = rm.file(f"file://{path}") self.assertNotEqual(f, None) @@ -89,7 +88,7 @@ def test_file_resource(self): self.assertEqual(g.read(), contents) def test_no_such_file_resource(self): - """ no such file resource """ + """no such file resource""" rm = ResourceManager() @@ -98,7 +97,7 @@ def test_no_such_file_resource(self): rm.file("file://../bogus.py") def test_package_resource(self): - """ package resource """ + """package resource""" rm = ResourceManager() @@ -114,7 +113,7 @@ def test_package_resource(self): self.assertEqual(g.read(), contents) def test_package_resource_subdir(self): - """ package resource """ + """package resource""" rm = ResourceManager() @@ -130,7 +129,7 @@ def test_package_resource_subdir(self): self.assertEqual(g.read(), contents) def test_no_such_package_resource(self): - """ no such package resource """ + """no such package resource""" rm = ResourceManager() @@ -151,7 +150,7 @@ def test_no_such_package_resource(self): rm.file("pkgfile://envisage.resource.resource_manager/anything") def test_http_resource(self): - """ http resource """ + """http resource""" # Open an HTTP document resource. rm = ResourceManager() @@ -164,7 +163,7 @@ def test_http_resource(self): self.assertEqual(contents, "This is a test file.\n") def test_no_such_http_resource(self): - """ no such http resource """ + """no such http resource""" # Open an HTTP document resource. rm = ResourceManager() @@ -173,7 +172,7 @@ def test_no_such_http_resource(self): rm.file("http://localhost:1234/bogus.dat") def test_unknown_protocol(self): - """ unknown protocol """ + """unknown protocol""" # Open an HTTP document resource. rm = ResourceManager() diff --git a/envisage/service.py b/envisage/service.py index 9c2b640d6..22e1cbb71 100644 --- a/envisage/service.py +++ b/envisage/service.py @@ -21,7 +21,7 @@ class Service(TraitType): - """ A trait type used to access services. + """A trait type used to access services. Note that this is a trait *type* and hence does *NOT* have traits itself (i.e. it does *not* inherit from 'HasTraits'). @@ -35,7 +35,7 @@ class Service(TraitType): def __init__( self, protocol=None, query="", minimize="", maximize="", **metadata ): - """ Constructor. """ + """Constructor.""" super().__init__(**metadata) @@ -52,7 +52,7 @@ def __init__( self._maximize = maximize def __repr__(self): - """ String representation of a Service object """ + """String representation of a Service object""" return "Service(protocol={!r})".format(self._protocol) ########################################################################### @@ -60,7 +60,7 @@ def __repr__(self): ########################################################################### def get(self, obj, trait_name): - """ Trait type getter. """ + """Trait type getter.""" service_registry = self._get_service_registry(obj) @@ -71,7 +71,7 @@ def get(self, obj, trait_name): return obj def set(self, obj, name, value): - """ Trait type setter. """ + """Trait type setter.""" raise TraitError("Service traits cannot be set") @@ -80,7 +80,7 @@ def set(self, obj, name, value): ########################################################################### def _get_service_registry(self, obj): - """ Return the service registry in effect for an object. """ + """Return the service registry in effect for an object.""" service_registry = getattr(obj, "service_registry", None) if service_registry is None: diff --git a/envisage/service_offer.py b/envisage/service_offer.py index b25cf8280..61ffa315d 100644 --- a/envisage/service_offer.py +++ b/envisage/service_offer.py @@ -15,7 +15,7 @@ class ServiceOffer(HasTraits): - """ An offer to provide a service. """ + """An offer to provide a service.""" #### 'ServiceOffer' interface ############################################# diff --git a/envisage/service_registry.py b/envisage/service_registry.py index 2bfab4d73..97d21e88c 100644 --- a/envisage/service_registry.py +++ b/envisage/service_registry.py @@ -20,18 +20,17 @@ from .i_service_registry import IServiceRegistry from .import_manager import ImportManager - # Logging. logger = logging.getLogger(__name__) class NoSuchServiceError(Exception): - """ Raised when a required service is not found. """ + """Raised when a required service is not found.""" @provides(IServiceRegistry) class ServiceRegistry(HasTraits): - """ The service registry. """ + """The service registry.""" #### IServiceRegistry interface ########################################## @@ -69,7 +68,7 @@ class ServiceRegistry(HasTraits): def get_required_service( self, protocol, query="", minimize="", maximize="" ): - """ Return the service that matches the specified query. + """Return the service that matches the specified query. Raise a 'NoSuchServiceError' exception if no such service exists. @@ -82,7 +81,7 @@ def get_required_service( return service def get_service(self, protocol, query="", minimize="", maximize=""): - """ Return at most one service that matches the specified query. """ + """Return at most one service that matches the specified query.""" services = self.get_services(protocol, query, minimize, maximize) if len(services) > 0: @@ -94,7 +93,7 @@ def get_service(self, protocol, query="", minimize="", maximize=""): return service def get_service_from_id(self, service_id): - """ Return the service with the specified id. """ + """Return the service with the specified id.""" try: protocol, obj, properties = self._services[service_id] @@ -105,7 +104,7 @@ def get_service_from_id(self, service_id): return obj def get_services(self, protocol, query="", minimize="", maximize=""): - """ Return all services that match the specified query. """ + """Return all services that match the specified query.""" services = [] for service_id, (name, obj, properties) in self._services.items(): @@ -140,7 +139,7 @@ def get_services(self, protocol, query="", minimize="", maximize=""): return services def get_service_properties(self, service_id): - """ Return the dictionary of properties associated with a service. """ + """Return the dictionary of properties associated with a service.""" try: protocol, obj, properties = self._services[service_id] @@ -152,7 +151,7 @@ def get_service_properties(self, service_id): return properties def register_service(self, protocol, obj, properties=None): - """ Register a service. """ + """Register a service.""" protocol_name = self._get_protocol_name(protocol) @@ -169,7 +168,7 @@ def register_service(self, protocol, obj, properties=None): return service_id def set_service_properties(self, service_id, properties): - """ Set the dictionary of properties associated with a service. """ + """Set the dictionary of properties associated with a service.""" try: protocol, obj, old_properties = self._services[service_id] @@ -179,7 +178,7 @@ def set_service_properties(self, service_id, properties): raise ValueError("no service with id <%d>" % service_id) def unregister_service(self, service_id): - """ Unregister a service. """ + """Unregister a service.""" try: protocol, obj, properties = self._services.pop(service_id) @@ -195,7 +194,7 @@ def unregister_service(self, service_id): ########################################################################### def _create_namespace(self, service, properties): - """ Create a namespace in which to evaluate a query. """ + """Create a namespace in which to evaluate a query.""" namespace = {} namespace.update(service.__dict__) @@ -204,7 +203,7 @@ def _create_namespace(self, service, properties): return namespace def _eval_query(self, service, properties, query): - """ Evaluate a query over a single service. + """Evaluate a query over a single service. Return True if the service matches the query, otherwise return False. @@ -220,7 +219,7 @@ def _eval_query(self, service, properties, query): return result def _get_protocol_name(self, protocol_or_name): - """ Returns the full class name for a protocol. """ + """Returns the full class name for a protocol.""" if isinstance(protocol_or_name, str): name = protocol_or_name @@ -234,7 +233,7 @@ def _get_protocol_name(self, protocol_or_name): return name def _is_service_factory(self, protocol, obj): - """ Is the object a factory for services supporting the protocol? """ + """Is the object a factory for services supporting the protocol?""" # fixme: Should we have a formal notion of service factory with an # appropriate API, or is this good enough? An API might have lifecycle @@ -243,14 +242,14 @@ def _is_service_factory(self, protocol, obj): return not isinstance(obj, protocol) def _next_service_id(self): - """ Returns the next service ID. """ + """Returns the next service ID.""" self._service_id += 1 return self._service_id def _resolve_factory(self, protocol, name, obj, properties, service_id): - """ If 'obj' is a factory then use it to create the actual service. """ + """If 'obj' is a factory then use it to create the actual service.""" # Is the registered service actually a service *factory*? if self._is_service_factory(protocol, obj): diff --git a/envisage/tests/bad_eggs/acme-bad/acme_bad/bad_plugin.py b/envisage/tests/bad_eggs/acme-bad/acme_bad/bad_plugin.py index cb0936a6e..6bbdc986f 100644 --- a/envisage/tests/bad_eggs/acme-bad/acme_bad/bad_plugin.py +++ b/envisage/tests/bad_eggs/acme-bad/acme_bad/bad_plugin.py @@ -10,16 +10,17 @@ """ The 'Bar' plugin """ -# Enthought library imports. -from envisage.api import Plugin -from traits.api import Bool - # Deliberate bad import import busted_module # noqa: F401 +from traits.api import Bool + +# Enthought library imports. +from envisage.api import Plugin + class BadPlugin(Plugin): - """ The 'Bad' plugin """ + """The 'Bad' plugin""" #### 'IPlugin' interface ################################################## @@ -36,13 +37,13 @@ class BadPlugin(Plugin): ########################################################################### def start(self): - """ Start the plugin. """ + """Start the plugin.""" self.started = True self.stopped = False def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" self.started = False self.stopped = True diff --git a/envisage/tests/bad_eggs/acme-bad/setup.py b/envisage/tests/bad_eggs/acme-bad/setup.py index 8c55f7f7a..001a3a2fd 100644 --- a/envisage/tests/bad_eggs/acme-bad/setup.py +++ b/envisage/tests/bad_eggs/acme-bad/setup.py @@ -8,7 +8,7 @@ # # Thanks for using Enthought open source! # Major package imports. -from setuptools import setup, find_packages +from setuptools import find_packages, setup setup( name="acme-bad", diff --git a/envisage/tests/eggs/acme-bar/acme_bar/bar_plugin.py b/envisage/tests/eggs/acme-bar/acme_bar/bar_plugin.py index b6f3e34aa..911b40dc5 100644 --- a/envisage/tests/eggs/acme-bar/acme_bar/bar_plugin.py +++ b/envisage/tests/eggs/acme-bar/acme_bar/bar_plugin.py @@ -10,13 +10,14 @@ """ The 'Bar' plugin """ +from traits.api import Bool + # Enthought library imports. from envisage.api import Plugin -from traits.api import Bool class BarPlugin(Plugin): - """ The 'Bar' plugin """ + """The 'Bar' plugin""" #### 'IPlugin' interface ################################################## @@ -33,13 +34,13 @@ class BarPlugin(Plugin): ########################################################################### def start(self): - """ Start the plugin. """ + """Start the plugin.""" self.started = True self.stopped = False def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" self.started = False self.stopped = True diff --git a/envisage/tests/eggs/acme-bar/setup.py b/envisage/tests/eggs/acme-bar/setup.py index b23492d54..690e416f9 100644 --- a/envisage/tests/eggs/acme-bar/setup.py +++ b/envisage/tests/eggs/acme-bar/setup.py @@ -8,7 +8,7 @@ # # Thanks for using Enthought open source! # Major package imports. -from setuptools import setup, find_packages +from setuptools import find_packages, setup setup( name="acme-bar", diff --git a/envisage/tests/eggs/acme-baz/acme_baz/baz_plugin.py b/envisage/tests/eggs/acme-baz/acme_baz/baz_plugin.py index fe9abfbce..5c3899615 100644 --- a/envisage/tests/eggs/acme-baz/acme_baz/baz_plugin.py +++ b/envisage/tests/eggs/acme-baz/acme_baz/baz_plugin.py @@ -10,13 +10,14 @@ """ The 'Baz' plugin """ +from traits.api import Bool + # Enthought library imports. from envisage.api import Plugin -from traits.api import Bool class BazPlugin(Plugin): - """ The 'Baz' plugin """ + """The 'Baz' plugin""" #### 'IPlugin' interface ################################################## @@ -33,13 +34,13 @@ class BazPlugin(Plugin): ########################################################################### def start(self): - """ Start the plugin. """ + """Start the plugin.""" self.started = True self.stopped = False def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" self.started = False self.stopped = True diff --git a/envisage/tests/eggs/acme-baz/setup.py b/envisage/tests/eggs/acme-baz/setup.py index 3354345f0..19cc430d2 100644 --- a/envisage/tests/eggs/acme-baz/setup.py +++ b/envisage/tests/eggs/acme-baz/setup.py @@ -8,7 +8,7 @@ # # Thanks for using Enthought open source! # Major package imports. -from setuptools import setup, find_packages +from setuptools import find_packages, setup setup( name="acme-baz", diff --git a/envisage/tests/eggs/acme-foo/acme_foo/foo_plugin.py b/envisage/tests/eggs/acme-foo/acme_foo/foo_plugin.py index b13eb8a92..5417af44e 100644 --- a/envisage/tests/eggs/acme-foo/acme_foo/foo_plugin.py +++ b/envisage/tests/eggs/acme-foo/acme_foo/foo_plugin.py @@ -10,13 +10,14 @@ """ The 'Foo' plugin """ +from traits.api import Bool + # Enthought library imports. from envisage.api import Plugin -from traits.api import Bool class FooPlugin(Plugin): - """ The 'Foo' plugin """ + """The 'Foo' plugin""" #### 'IPlugin' interface ################################################## @@ -33,13 +34,13 @@ class FooPlugin(Plugin): ########################################################################### def start(self): - """ Start the plugin. """ + """Start the plugin.""" self.started = True self.stopped = False def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" self.started = False self.stopped = True diff --git a/envisage/tests/eggs/acme-foo/setup.py b/envisage/tests/eggs/acme-foo/setup.py index e36698360..36733a14a 100644 --- a/envisage/tests/eggs/acme-foo/setup.py +++ b/envisage/tests/eggs/acme-foo/setup.py @@ -8,7 +8,7 @@ # # Thanks for using Enthought open source! # Major package imports. -from setuptools import setup, find_packages +from setuptools import find_packages, setup setup( name="acme-foo", diff --git a/envisage/tests/event_tracker.py b/envisage/tests/event_tracker.py index 3d5aadc84..1e59b24fa 100644 --- a/envisage/tests/event_tracker.py +++ b/envisage/tests/event_tracker.py @@ -16,7 +16,7 @@ class EventTracker(HasTraits): - """ Used to track traits events. """ + """Used to track traits events.""" # The traits events that have fired. # @@ -49,7 +49,7 @@ class EventTracker(HasTraits): @observe("subscriptions") def _update_listeners_on_all_subscriptions(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" old, new = event.old, event.new for subscription in old: self._remove_subscription(subscription) @@ -59,7 +59,7 @@ def _update_listeners_on_all_subscriptions(self, event): @observe("subscriptions:items") def _update_listeners_on_changed_subscriptions(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" for subscription in event.removed: self._remove_subscription(subscription) @@ -68,7 +68,7 @@ def _update_listeners_on_changed_subscriptions(self, event): self._add_subscription(subscription) def _listener(self, obj, trait_name, old, new): - """ Dynamic trait change listener. """ + """Dynamic trait change listener.""" self.events.append((obj, trait_name, old, new)) self.event_names.append(trait_name) @@ -76,7 +76,7 @@ def _listener(self, obj, trait_name, old, new): #### Methods ############################################################## def _add_subscription(self, subscription): - """ Add a subscription. """ + """Add a subscription.""" obj, trait_name = subscription @@ -87,7 +87,7 @@ def _add_subscription(self, subscription): obj.on_trait_change(self._listener) def _remove_subscription(self, subscription): - """ Remove a subscription. """ + """Remove a subscription.""" obj, trait_name = subscription diff --git a/envisage/tests/mutable_extension_registry.py b/envisage/tests/mutable_extension_registry.py index 1b7c18489..405adc43f 100644 --- a/envisage/tests/mutable_extension_registry.py +++ b/envisage/tests/mutable_extension_registry.py @@ -15,19 +15,19 @@ class MutableExtensionRegistry(ExtensionRegistry): - """ A mutable, manually populated extension registry used for testing. """ + """A mutable, manually populated extension registry used for testing.""" ########################################################################### # 'MutableExtensionRegistry' interface. ########################################################################### def add_extension(self, extension_point_id, extension): - """ Contribute an extension to an extension point. """ + """Contribute an extension to an extension point.""" self.add_extensions(extension_point_id, [extension]) def add_extensions(self, extension_point_id, extensions): - """ Contribute a list of extensions to an extension point. """ + """Contribute a list of extensions to an extension point.""" self._check_extension_point(extension_point_id) @@ -40,12 +40,12 @@ def add_extensions(self, extension_point_id, extensions): self._call_listeners(refs, extension_point_id, extensions, [], index) def remove_extension(self, extension_point_id, extension): - """ Remove a contribution from an extension point. """ + """Remove a contribution from an extension point.""" self.remove_extensions(extension_point_id, [extension]) def remove_extensions(self, extension_point_id, extensions): - """ Remove a list of contributions from an extension point. """ + """Remove a list of contributions from an extension point.""" for extension in extensions: try: diff --git a/envisage/tests/plugins/banana/banana_plugin.py b/envisage/tests/plugins/banana/banana_plugin.py index 5e9369b26..3a5c35b1f 100644 --- a/envisage/tests/plugins/banana/banana_plugin.py +++ b/envisage/tests/plugins/banana/banana_plugin.py @@ -10,12 +10,13 @@ """ The 'Banana' plugin """ -from envisage.api import Plugin from traits.api import Bool +from envisage.api import Plugin + class BananaPlugin(Plugin): - """ The 'Banana' plugin """ + """The 'Banana' plugin""" #### 'IPlugin' protocol ################################################### @@ -23,13 +24,13 @@ class BananaPlugin(Plugin): id = "banana" def start(self): - """ Start the plugin. """ + """Start the plugin.""" self.started = True self.stopped = False def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" self.started = False self.stopped = True diff --git a/envisage/tests/plugins/banana/plugins.py b/envisage/tests/plugins/banana/plugins.py index a9e1f4869..37204f9f3 100644 --- a/envisage/tests/plugins/banana/plugins.py +++ b/envisage/tests/plugins/banana/plugins.py @@ -11,7 +11,7 @@ def get_plugins(): - """ Get the plugins from this package. """ + """Get the plugins from this package.""" from .banana_plugin import BananaPlugin diff --git a/envisage/tests/plugins/orange/orange_plugin.py b/envisage/tests/plugins/orange/orange_plugin.py index ddf5da8d3..a121b16db 100644 --- a/envisage/tests/plugins/orange/orange_plugin.py +++ b/envisage/tests/plugins/orange/orange_plugin.py @@ -10,12 +10,13 @@ """ The 'Orange' plugin """ -from envisage.api import Plugin from traits.api import Bool +from envisage.api import Plugin + class OrangePlugin(Plugin): - """ The 'Orange' plugin """ + """The 'Orange' plugin""" #### 'IPlugin' protocol ################################################### @@ -23,13 +24,13 @@ class OrangePlugin(Plugin): id = "orange" def start(self): - """ Start the plugin. """ + """Start the plugin.""" self.started = True self.stopped = False def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" self.started = False self.stopped = True diff --git a/envisage/tests/plugins/orange/plugins.py b/envisage/tests/plugins/orange/plugins.py index 080096d94..46cfd1825 100644 --- a/envisage/tests/plugins/orange/plugins.py +++ b/envisage/tests/plugins/orange/plugins.py @@ -11,7 +11,7 @@ def get_plugins(): - """ Get the plugins from this package. """ + """Get the plugins from this package.""" from .orange_plugin import OrangePlugin diff --git a/envisage/tests/plugins/pear/pear_plugin.py b/envisage/tests/plugins/pear/pear_plugin.py index d973a05f2..c22e54c25 100644 --- a/envisage/tests/plugins/pear/pear_plugin.py +++ b/envisage/tests/plugins/pear/pear_plugin.py @@ -10,12 +10,13 @@ """ The 'Pear' plugin """ -from envisage.api import Plugin from traits.api import Bool +from envisage.api import Plugin + class PearPlugin(Plugin): - """ The 'Pear' plugin """ + """The 'Pear' plugin""" #### 'IPlugin' protocol ################################################### @@ -23,13 +24,13 @@ class PearPlugin(Plugin): id = "pear" def start(self): - """ Start the plugin. """ + """Start the plugin.""" self.started = True self.stopped = False def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" self.started = False self.stopped = True diff --git a/envisage/tests/support.py b/envisage/tests/support.py index 5c6223ccb..348aed47c 100644 --- a/envisage/tests/support.py +++ b/envisage/tests/support.py @@ -23,7 +23,6 @@ from envisage.api import Application, ExtensionPoint, Plugin - # Skip decorator for tests that require a working GUI instance. try: GUI() @@ -51,30 +50,32 @@ # Application class used in various tests. + class SimpleApplication(Application): - """ The type of application used in the tests. """ + """The type of application used in the tests.""" id = "test" # Plugins used in multiple tests. + class PluginA(Plugin): - """ A plugin that offers an extension point. """ + """A plugin that offers an extension point.""" id = "A" x = ExtensionPoint(List, id="a.x") class PluginB(Plugin): - """ A plugin that contributes to an extension point. """ + """A plugin that contributes to an extension point.""" id = "B" x = List(Int, [1, 2, 3], contributes_to="a.x") class PluginC(Plugin): - """ Another plugin that contributes to an extension point! """ + """Another plugin that contributes to an extension point!""" id = "C" x = List(Int, [98, 99, 100], contributes_to="a.x") diff --git a/envisage/tests/test_api.py b/envisage/tests/test_api.py index e11be4658..48c5e7d98 100644 --- a/envisage/tests/test_api.py +++ b/envisage/tests/test_api.py @@ -15,13 +15,15 @@ class TestApi(unittest.TestCase): - """ Test for API """ + """Test for API""" + def test_import(self): self.assertEqual(api.BINDINGS, ids.BINDINGS) self.assertEqual(api.COMMANDS, ids.COMMANDS) self.assertEqual(api.PREFERENCES, ids.PREFERENCES) - self.assertEqual(api.PREFERENCES_CATEGORIES, - ids.PREFERENCES_CATEGORIES) + self.assertEqual( + api.PREFERENCES_CATEGORIES, ids.PREFERENCES_CATEGORIES + ) self.assertEqual(api.PREFERENCES_PANES, ids.PREFERENCES_PANES) self.assertEqual(api.SERVICE_OFFERS, ids.SERVICE_OFFERS) self.assertEqual(api.TASKS, ids.TASKS) diff --git a/envisage/tests/test_application.py b/envisage/tests/test_application.py index f6a3509f4..2dea7de4c 100644 --- a/envisage/tests/test_application.py +++ b/envisage/tests/test_application.py @@ -15,31 +15,27 @@ import shutil import unittest +from traits.api import Bool, Int, List + # Enthought library imports. from traits.etsconfig.api import ETSConfig -from envisage.api import ExtensionPoint -from envisage.api import Plugin, PluginManager -from traits.api import Bool, Int, List + +from envisage.api import ExtensionPoint, Plugin, PluginManager +from envisage.tests.ets_config_patcher import ETSConfigPatcher # Local imports. from envisage.tests.event_tracker import EventTracker -from envisage.tests.ets_config_patcher import ETSConfigPatcher -from envisage.tests.support import ( - PluginA, - PluginB, - PluginC, - SimpleApplication, -) +from envisage.tests.support import PluginA, PluginB, PluginC, SimpleApplication def vetoer(event): - """ An observer that will veto an event. """ + """An observer that will veto an event.""" event.new.veto = True class SimplePlugin(Plugin): - """ A simple plugin. """ + """A simple plugin.""" #### 'SimplePlugin' interface ############################################# @@ -51,32 +47,32 @@ class SimplePlugin(Plugin): ########################################################################### def start(self): - """ Start the plugin. """ + """Start the plugin.""" self.started = True self.stopped = False def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" self.started = False self.stopped = True class BadPlugin(Plugin): - """ A plugin that just causes trouble ;^). """ + """A plugin that just causes trouble ;^).""" ########################################################################### # 'IPlugin' interface. ########################################################################### def start(self): - """ Start the plugin. """ + """Start the plugin.""" raise 1 / 0 def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" raise 1 / 0 @@ -87,8 +83,8 @@ def stop(self): class PluginD(Plugin): - """ Plugin that expects to be started before contributing to - extension points. """ + """Plugin that expects to be started before contributing to + extension points.""" id = "D" x = ExtensionPoint(List, id="d.x") @@ -108,8 +104,8 @@ def _y_default(self): class PluginE(Plugin): - """ Another plugin that expects to be started before contributing to - extension points. """ + """Another plugin that expects to be started before contributing to + extension points.""" id = "E" x = ExtensionPoint(List, id="e.x") @@ -129,17 +125,17 @@ def _y_default(self): class ApplicationTestCase(unittest.TestCase): - """ Tests for applications and plugins. """ + """Tests for applications and plugins.""" def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" ets_config_patcher = ETSConfigPatcher() ets_config_patcher.start() self.addCleanup(ets_config_patcher.stop) def test_home(self): - """ home """ + """home""" application = SimpleApplication() @@ -159,7 +155,7 @@ def test_home(self): shutil.rmtree(application.home) def test_no_plugins(self): - """ no plugins """ + """no plugins""" application = SimpleApplication() @@ -185,7 +181,7 @@ def test_no_plugins(self): ) def test_veto_starting(self): - """ veto starting """ + """veto starting""" application = SimpleApplication() @@ -207,7 +203,7 @@ def test_veto_starting(self): self.assertTrue("started" not in tracker.event_names) def test_veto_stopping(self): - """ veto stopping """ + """veto stopping""" application = SimpleApplication() @@ -234,7 +230,7 @@ def test_veto_stopping(self): self.assertTrue("stopped" not in tracker.event_names) def test_start_and_stop_errors(self): - """ start and stop errors """ + """start and stop errors""" simple_plugin = SimplePlugin() bad_plugin = BadPlugin() @@ -257,7 +253,7 @@ def test_start_and_stop_errors(self): application.stop_plugin(plugin_id="bogus") def test_extension_point(self): - """ extension point """ + """extension point""" a = PluginA() b = PluginB() @@ -298,7 +294,7 @@ def test_extension_point_resolution_occurs_after_plugin_start(self): ) def test_add_extension_point_listener(self): - """ add extension point listener """ + """add extension point listener""" a = PluginA() b = PluginB() @@ -309,7 +305,7 @@ def test_add_extension_point_listener(self): application.start() def listener(extension_registry, event): - """ An extension point listener. """ + """An extension point listener.""" listener.extension_point_id = event.extension_point_id listener.added = event.added @@ -332,7 +328,7 @@ def listener(extension_registry, event): self.assertEqual([98, 99, 100], listener.added) def test_remove_extension_point_listener(self): - """ remove extension point listener """ + """remove extension point listener""" a = PluginA() b = PluginB() @@ -343,7 +339,7 @@ def test_remove_extension_point_listener(self): application.start() def listener(extension_registry, event): - """ An extension point listener. """ + """An extension point listener.""" listener.extension_point_id = event.extension_point_id listener.added = event.added @@ -375,7 +371,7 @@ def listener(extension_registry, event): self.assertEqual(None, listener.extension_point_id) def test_add_plugin(self): - """ add plugin """ + """add plugin""" a = PluginA() b = PluginB() @@ -409,7 +405,7 @@ def test_add_plugin(self): self.assertEqual([1, 2, 3, 98, 99, 100], extensions) def test_get_plugin(self): - """ get plugin """ + """get plugin""" a = PluginA() b = PluginB() @@ -428,7 +424,7 @@ def test_get_plugin(self): self.assertEqual(None, application.get_plugin("BOGUS")) def test_remove_plugin(self): - """ remove plugin """ + """remove plugin""" a = PluginA() b = PluginB() @@ -461,7 +457,7 @@ def test_remove_plugin(self): self.assertEqual([98, 99, 100], extensions) def test_set_plugin_manager_at_contruction_time(self): - """ set plugin manager at construction time""" + """set plugin manager at construction time""" a = PluginA() b = PluginB() diff --git a/envisage/tests/test_composite_plugin_manager.py b/envisage/tests/test_composite_plugin_manager.py index b66669228..7e103bc48 100644 --- a/envisage/tests/test_composite_plugin_manager.py +++ b/envisage/tests/test_composite_plugin_manager.py @@ -11,15 +11,16 @@ import unittest +from traits.api import Bool + from envisage.application import Application from envisage.composite_plugin_manager import CompositePluginManager -from envisage.plugin_manager import PluginManager from envisage.plugin import Plugin -from traits.api import Bool +from envisage.plugin_manager import PluginManager class SimplePlugin(Plugin): - """ A simple plugin. """ + """A simple plugin.""" #### 'SimplePlugin' protocol ############################################## @@ -29,43 +30,41 @@ class SimplePlugin(Plugin): #### 'IPlugin' protocol ################################################### def start(self): - """ Start the plugin. """ + """Start the plugin.""" self.started = True self.stopped = False def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" self.started = False self.stopped = True class CustomException(Exception): - """ Custom exception used for testing purposes. """ + """Custom exception used for testing purposes.""" pass class RaisingPluginManager(PluginManager): - """ A PluginManager that raises on iteration. """ + """A PluginManager that raises on iteration.""" def __iter__(self): raise CustomException("Something went wrong.") class CompositePluginManagerTestCase(unittest.TestCase): - """ Tests for the composite plugin manager. """ + """Tests for the composite plugin manager.""" def test_find_no_plugins_if_there_are_no_plugin_managers(self): - plugin_manager = CompositePluginManager() ids = [plugin.id for plugin in plugin_manager] self.assertEqual(0, len(ids)) def test_find_no_plugins_if_there_are_no_plugins_in_plugin_managers(self): - plugin_manager = CompositePluginManager( plugin_managers=[PluginManager(), PluginManager()] ) @@ -74,7 +73,6 @@ def test_find_no_plugins_if_there_are_no_plugins_in_plugin_managers(self): self.assertEqual(0, len(ids)) def test_find_plugins_in_a_single_plugin_manager(self): - plugin_manager = CompositePluginManager( plugin_managers=[ PluginManager( @@ -91,7 +89,6 @@ def test_find_plugins_in_a_single_plugin_manager(self): self._test_start_and_stop(plugin_manager, ["red", "yellow"]) def test_find_plugins_in_a_multiple_plugin_managers(self): - plugin_manager = CompositePluginManager( plugin_managers=[ PluginManager( @@ -110,7 +107,6 @@ def test_find_plugins_in_a_multiple_plugin_managers(self): self._test_start_and_stop(plugin_manager, ["red", "yellow", "green"]) def test_application_gets_propogated_to_plugin_managers(self): - application = Application() composite_plugin_manager = CompositePluginManager( @@ -124,7 +120,6 @@ def test_application_gets_propogated_to_plugin_managers(self): def test_propogate_plugin_added_or_remove_events_from_plugin_managers( self, ): - a = PluginManager() b = PluginManager() @@ -164,7 +159,7 @@ def test_correct_exception_propagated_from_plugin_manager(self): #### Private protocol ##################################################### def _plugin_count(self, plugin_manager): - """ Return how many plugins the plugin manager contains. """ + """Return how many plugins the plugin manager contains.""" count = 0 for plugin in plugin_manager: @@ -173,8 +168,8 @@ def _plugin_count(self, plugin_manager): return count def _test_start_and_stop(self, plugin_manager, expected): - """ Make sure the plugin manager starts and stops the expected plugins. - + """ + Make sure the plugin manager starts and stops the expected plugins. """ # Make sure the plugin manager found only the required plugins. diff --git a/envisage/tests/test_core_plugin.py b/envisage/tests/test_core_plugin.py index a3f93393e..6115435bd 100644 --- a/envisage/tests/test_core_plugin.py +++ b/envisage/tests/test_core_plugin.py @@ -15,21 +15,21 @@ # Major package imports. from pkg_resources import resource_filename +from traits.api import HasTraits, Interface, List, on_trait_change, Str + # Enthought library imports. -from envisage.api import CorePlugin, Plugin -from envisage.api import ServiceOffer +from envisage.api import CorePlugin, Plugin, ServiceOffer from envisage.tests.support import SimpleApplication -from traits.api import HasTraits, Interface, List, on_trait_change, Str # This module's package. PKG = "envisage.tests" class CorePluginTestCase(unittest.TestCase): - """ Tests for the core plugin. """ + """Tests for the core plugin.""" def test_service_offers(self): - """ service offers """ + """service offers""" class IMyService(Interface): pass @@ -40,7 +40,7 @@ class PluginA(Plugin): service_offers = List(contributes_to="envisage.service_offers") def _service_offers_default(self): - """ Trait initializer. """ + """Trait initializer.""" service_offers = [ ServiceOffer( @@ -51,7 +51,7 @@ def _service_offers_default(self): return service_offers def _my_service_factory(self, **properties): - """ Service factory. """ + """Service factory.""" return 42 @@ -71,7 +71,7 @@ def _my_service_factory(self, **properties): self.assertEqual(None, application.get_service(IMyService)) def test_dynamically_added_service_offer(self): - """ dynamically added service offer """ + """dynamically added service offer""" class IMyService(Interface): pass @@ -82,7 +82,7 @@ class PluginA(Plugin): service_offers = List(contributes_to="envisage.service_offers") def _service_offers_default(self): - """ Trait initializer. """ + """Trait initializer.""" service_offers = [ ServiceOffer( @@ -93,7 +93,7 @@ def _service_offers_default(self): return service_offers def _my_service_factory(self, **properties): - """ Service factory. """ + """Service factory.""" return 42 @@ -125,14 +125,14 @@ def _my_service_factory(self, **properties): self.assertEqual(42, service) def test_preferences(self): - """ preferences """ + """preferences""" class PluginA(Plugin): id = "A" preferences = List(contributes_to="envisage.preferences") def _preferences_default(self): - """ Trait initializer. """ + """Trait initializer.""" return ["file://" + resource_filename(PKG, "preferences.ini")] @@ -146,14 +146,14 @@ def _preferences_default(self): self.assertEqual("42", application.preferences.get("enthought.test.x")) def test_dynamically_added_preferences(self): - """ dynamically added preferences """ + """dynamically added preferences""" class PluginA(Plugin): id = "A" preferences = List(contributes_to="envisage.preferences") def _preferences_default(self): - """ Trait initializer. """ + """Trait initializer.""" return ["file://" + resource_filename(PKG, "preferences.ini")] @@ -172,7 +172,7 @@ def _preferences_default(self): # regression test for enthought/envisage#251 def test_unregister_service_offer(self): - """ Unregister a service that is contributed to the + """Unregister a service that is contributed to the "envisage.service_offers" extension point while the application is running. """ @@ -190,7 +190,6 @@ class PluginA(Plugin): service_offers = List(contributes_to=SERVICE_OFFERS) def _service_offers_default(self): - a_service_offer = ServiceOffer( protocol=IJunk, factory=self._create_junk_service, @@ -199,7 +198,7 @@ def _service_offers_default(self): return [a_service_offer] def _create_junk_service(self): - """ Factory method for the 'Junk' service. """ + """Factory method for the 'Junk' service.""" return Junk() @@ -216,9 +215,9 @@ def _unregister_junk_service(self): application.run() def test_unregister_service(self): - """ Unregister a service which was registered on the application + """Unregister a service which was registered on the application directly, not through the CorePlugin's extension point. CorePlugin - should not do anything to interfere. """ + should not do anything to interfere.""" class IJunk(Interface): trash = Str() diff --git a/envisage/tests/test_egg_based.py b/envisage/tests/test_egg_based.py index e9de3c354..b953ef1a7 100644 --- a/envisage/tests/test_egg_based.py +++ b/envisage/tests/test_egg_based.py @@ -10,12 +10,12 @@ """ Base class for Egg-based test cases. """ -from os.path import join import shutil import subprocess import sys import tempfile import unittest +from os.path import join import pkg_resources @@ -49,7 +49,7 @@ def build_egg(egg_dir, dist_dir): class EggBasedTestCase(unittest.TestCase): - """ Base class for Egg-based test cases. """ + """Base class for Egg-based test cases.""" @classmethod def setUpClass(cls): @@ -58,7 +58,8 @@ def setUpClass(cls): """ cls.egg_dir = tempfile.mkdtemp() eggs_root_dir = pkg_resources.resource_filename( - "envisage.tests", "eggs") + "envisage.tests", "eggs" + ) for egg_name in ["acme-bar", "acme-baz", "acme-foo"]: build_egg( egg_dir=join(eggs_root_dir, egg_name), @@ -73,14 +74,14 @@ def tearDownClass(cls): shutil.rmtree(cls.egg_dir) def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" # Some tests cause sys.path to be modified. Capture the original # contents so that we can restore sys.path later. self._original_sys_path_contents = sys.path[:] def tearDown(self): - """ Called immediately after each test method has been called. """ + """Called immediately after each test method has been called.""" # Undo any sys.path modifications sys.path[:] = self._original_sys_path_contents @@ -88,7 +89,7 @@ def tearDown(self): pkg_resources.working_set = pkg_resources.WorkingSet() def _add_egg(self, filename, working_set=None): - """ Create and add a distribution from the specified '.egg'. """ + """Create and add a distribution from the specified '.egg'.""" if working_set is None: working_set = pkg_resources.working_set @@ -105,7 +106,7 @@ def _add_egg(self, filename, working_set=None): working_set.add(distribution) def _add_eggs_on_path(self, path, working_set=None): - """ Add all eggs found on the path to a working set. """ + """Add all eggs found on the path to a working set.""" if working_set is None: working_set = pkg_resources.working_set diff --git a/envisage/tests/test_egg_basket_plugin_manager.py b/envisage/tests/test_egg_basket_plugin_manager.py index 2bddfae4c..1dfabaf1c 100644 --- a/envisage/tests/test_egg_basket_plugin_manager.py +++ b/envisage/tests/test_egg_basket_plugin_manager.py @@ -10,11 +10,11 @@ """ Tests for the 'Egg Basket' plugin manager. """ import glob -from os.path import basename, join import shutil import sys import tempfile import unittest +from os.path import basename, join import pkg_resources @@ -23,7 +23,7 @@ class EggBasketPluginManagerTestCase(unittest.TestCase): - """ Tests for the 'Egg Basket' plugin manager. """ + """Tests for the 'Egg Basket' plugin manager.""" #### 'unittest.TestCase' protocol ######################################### @@ -36,7 +36,8 @@ def setUpClass(cls): cls.bad_eggs_dir = tempfile.mkdtemp() eggs_root_dir = pkg_resources.resource_filename( - "envisage.tests", "eggs") + "envisage.tests", "eggs" + ) for egg_name in ["acme-bar", "acme-baz", "acme-foo"]: build_egg( egg_dir=join(eggs_root_dir, egg_name), @@ -44,7 +45,8 @@ def setUpClass(cls): ) bad_eggs_root_dir = pkg_resources.resource_filename( - "envisage.tests", "bad_eggs") + "envisage.tests", "bad_eggs" + ) for egg_name in ["acme-bad"]: build_egg( egg_dir=join(bad_eggs_root_dir, egg_name), @@ -60,14 +62,14 @@ def tearDownClass(cls): shutil.rmtree(cls.eggs_dir) def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" # Some tests cause sys.path to be modified. Capture the original # contents so that we can restore sys.path later. self._original_sys_path_contents = sys.path[:] def tearDown(self): - """ Called immediately after each test method has been called. """ + """Called immediately after each test method has been called.""" # Undo any sys.path modifications sys.path[:] = self._original_sys_path_contents @@ -79,7 +81,6 @@ def tearDown(self): #### Tests ################################################################ def test_find_plugins_in_eggs_on_the_plugin_path(self): - with self.assertWarns(DeprecationWarning): plugin_manager = EggBasketPluginManager( plugin_path=[self.eggs_dir] @@ -92,7 +93,6 @@ def test_find_plugins_in_eggs_on_the_plugin_path(self): self.assertIn("acme.baz", ids) def test_only_find_plugins_whose_ids_are_in_the_include_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. include = ["acme.foo", "acme.bar"] @@ -110,7 +110,6 @@ def test_only_find_plugins_whose_ids_are_in_the_include_list(self): self._test_start_and_stop(plugin_manager, expected) def test_only_find_plugins_matching_a_wildcard_in_the_include_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. include = ["acme.b*"] @@ -128,7 +127,6 @@ def test_only_find_plugins_matching_a_wildcard_in_the_include_list(self): self._test_start_and_stop(plugin_manager, expected) def test_ignore_plugins_whose_ids_are_in_the_exclude_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. exclude = ["acme.foo", "acme.baz"] @@ -146,7 +144,6 @@ def test_ignore_plugins_whose_ids_are_in_the_exclude_list(self): self._test_start_and_stop(plugin_manager, expected) def test_ignore_plugins_matching_a_wildcard_in_the_exclude_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. exclude = ["acme.b*"] @@ -265,8 +262,8 @@ def on_broken_distribution(dist, exc): #### Private protocol ##################################################### def _test_start_and_stop(self, plugin_manager, expected): - """ Make sure the plugin manager starts and stops the expected plugins. - + """ + Make sure the plugin manager starts and stops the expected plugins. """ # Make sure the plugin manager found only the required plugins. @@ -293,7 +290,7 @@ def _test_start_and_stop(self, plugin_manager, expected): self.assertEqual(True, plugin.stopped) def _create_broken_distribution_eggdir(self, egg_pat, replacement=None): - """ Copy a good egg to a different version egg name in a new temp dir + """Copy a good egg to a different version egg name in a new temp dir and return the new directory. Parameters diff --git a/envisage/tests/test_egg_plugin_manager.py b/envisage/tests/test_egg_plugin_manager.py index cd2621bfe..91ab73bb6 100644 --- a/envisage/tests/test_egg_plugin_manager.py +++ b/envisage/tests/test_egg_plugin_manager.py @@ -20,7 +20,7 @@ class EggPluginManagerTestCase(EggBasedTestCase): - """ Tests for the Egg plugin manager. """ + """Tests for the Egg plugin manager.""" ########################################################################### # Tests. @@ -29,7 +29,7 @@ class EggPluginManagerTestCase(EggBasedTestCase): # fixme: Depending how many eggs are on sys.path, this test may take too # long to be part of the TDD cycle. def test_no_include_or_exclude(self): - """ no include or exclude """ + """no include or exclude""" # Add all of the eggs in the egg basket. self._add_eggs_on_path([self.egg_dir]) @@ -48,7 +48,7 @@ def test_no_include_or_exclude(self): self.assertTrue("acme.baz" in ids) def test_include_specific(self): - """ include specific """ + """include specific""" # Add all of the eggs in the egg basket. self._add_eggs_on_path([self.egg_dir]) @@ -69,7 +69,7 @@ def test_include_specific(self): self._test_start_and_stop(plugin_manager, expected) def test_include_multiple(self): - """ include multiple """ + """include multiple""" # Add all of the eggs in the egg basket. self._add_eggs_on_path([self.egg_dir]) @@ -91,7 +91,7 @@ def test_include_multiple(self): self._test_start_and_stop(plugin_manager, expected) def test_exclude_specific(self): - """ exclude specific """ + """exclude specific""" # Add all of the eggs in the egg basket. self._add_eggs_on_path([self.egg_dir]) @@ -116,7 +116,7 @@ def test_exclude_specific(self): self._test_start_and_stop(plugin_manager, expected) def test_exclude_multiple(self): - """ exclude multiple """ + """exclude multiple""" # Add all of the eggs in the egg basket. self._add_eggs_on_path([self.egg_dir]) @@ -162,8 +162,8 @@ def test_uses_global_working_set_by_default(self): ########################################################################### def _test_start_and_stop(self, plugin_manager, expected): - """ Make sure the plugin manager starts and stops the expected plugins. - + """ + Make sure the plugin manager starts and stops the expected plugins. """ # Make sure the plugin manager found only the required plugins. diff --git a/envisage/tests/test_extension_point.py b/envisage/tests/test_extension_point.py index a339286b3..c078e3c70 100644 --- a/envisage/tests/test_extension_point.py +++ b/envisage/tests/test_extension_point.py @@ -12,23 +12,23 @@ # Standard library imports. import unittest -# Enthought library imports. -from envisage.api import Application, ExtensionPoint -from envisage.api import ExtensionRegistry from traits.api import HasTraits, Int, List, TraitError +# Enthought library imports. +from envisage.api import Application, ExtensionPoint, ExtensionRegistry + class HasExtensionPoints(HasTraits): - """ Base class for all test classes that use the 'ExtensionPoint' type. """ + """Base class for all test classes that use the 'ExtensionPoint' type.""" extension_registry = None class ExtensionPointTestCase(unittest.TestCase): - """ Tests for extension points. """ + """Tests for extension points.""" def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" # We do all of the testing via the application to make sure it offers # the same interface! @@ -38,7 +38,7 @@ def setUp(self): HasExtensionPoints.extension_registry = self.registry def test_invalid_extension_point_type(self): - """ invalid extension point type """ + """invalid extension point type""" # Extension points currently have to be 'List's of something! The # default is a list of anything. @@ -46,7 +46,7 @@ def test_invalid_extension_point_type(self): ExtensionPoint(Int, "my.ep") def test_no_reference_to_extension_registry(self): - """ no reference to extension registry """ + """no reference to extension registry""" registry = self.registry @@ -67,7 +67,7 @@ class Foo(HasTraits): getattr(f, "x") def test_extension_point_changed(self): - """ extension point changed """ + """extension point changed""" registry = self.registry @@ -79,7 +79,7 @@ class Foo(HasExtensionPoints): x = ExtensionPoint(id="my.ep") def _x_changed(self): - """ Static trait change handler. """ + """Static trait change handler.""" self.x_changed_called = True @@ -112,7 +112,7 @@ def _x_changed(self): self.assertEqual(False, f.x_changed_called) def test_mutate_extension_point_no_effect(self): - """ Extension point is recomputed so mutation has no effect. """ + """Extension point is recomputed so mutation has no effect.""" registry = self.registry @@ -137,7 +137,7 @@ class Foo(HasExtensionPoints): self.assertEqual(f.x, [1, 2, 3]) def test_untyped_extension_point(self): - """ untyped extension point """ + """untyped extension point""" registry = self.registry @@ -161,7 +161,7 @@ class Foo(HasExtensionPoints): self.assertEqual([42, "a string", True], g.x) def test_typed_extension_point(self): - """ typed extension point """ + """typed extension point""" registry = self.registry @@ -185,7 +185,7 @@ class Foo(HasExtensionPoints): self.assertEqual([42, 43, 44], g.x) def test_invalid_extension_point(self): - """ invalid extension point """ + """invalid extension point""" registry = self.registry @@ -206,7 +206,7 @@ class Foo(HasExtensionPoints): getattr(f, "x") def test_extension_point_with_no_id(self): - """ extension point with no Id """ + """extension point with no Id""" def factory(): class Foo(HasExtensionPoints): @@ -216,7 +216,7 @@ class Foo(HasExtensionPoints): factory() def test_set_untyped_extension_point(self): - """ set untyped extension point """ + """set untyped extension point""" registry = self.registry @@ -235,7 +235,7 @@ class Foo(HasExtensionPoints): self.assertEqual([42], registry.get_extensions("my.ep")) def test_set_typed_extension_point(self): - """ set typed extension point """ + """set typed extension point""" registry = self.registry @@ -254,7 +254,7 @@ class Foo(HasExtensionPoints): self.assertEqual([42], registry.get_extensions("my.ep")) def test_extension_point_str_representation(self): - """ test the string representation of the extension point """ + """test the string representation of the extension point""" ep_repr = "ExtensionPoint(id={!r})" ep = self._create_extension_point("my.ep") self.assertEqual(ep_repr.format("my.ep"), str(ep)) @@ -265,6 +265,6 @@ def test_extension_point_str_representation(self): ########################################################################### def _create_extension_point(self, id, trait_type=List, desc=""): - """ Create an extension point. """ + """Create an extension point.""" return ExtensionPoint(id=id, trait_type=trait_type, desc=desc) diff --git a/envisage/tests/test_extension_point_binding.py b/envisage/tests/test_extension_point_binding.py index eda98ef71..26543e82a 100644 --- a/envisage/tests/test_extension_point_binding.py +++ b/envisage/tests/test_extension_point_binding.py @@ -13,11 +13,15 @@ import unittest import weakref -# Enthought library imports. -from envisage.api import ExtensionPoint -from envisage.api import bind_extension_point, unbind_extension_point from traits.api import Any, HasTraits, List +# Enthought library imports. +from envisage.api import ( + bind_extension_point, + ExtensionPoint, + unbind_extension_point, +) + # Local imports. from envisage.tests.mutable_extension_registry import MutableExtensionRegistry @@ -32,7 +36,7 @@ class BindingTarget(HasTraits): class ExtensionPointBindingTestCase(unittest.TestCase): - """ Tests for extension point binding. """ + """Tests for extension point binding.""" def setUp(self): self.extension_registry = MutableExtensionRegistry() @@ -41,7 +45,7 @@ def tearDown(self): del self.extension_registry def test_untyped_extension_point(self): - """ untyped extension point """ + """untyped extension point""" registry = self.extension_registry @@ -83,7 +87,7 @@ class Foo(HasTraits): self.assertTrue("a string" in event.new.added) def test_set_extensions_via_trait(self): - """ set extensions via trait """ + """set extensions via trait""" registry = self.extension_registry @@ -127,7 +131,7 @@ class Foo(HasTraits): self.assertTrue("a string" in event.new) def test_set_extensions_via_registry(self): - """ set extensions via registry """ + """set extensions via registry""" registry = self.extension_registry @@ -168,7 +172,7 @@ class Foo(HasTraits): self.assertTrue("a string" in event.new) def test_explicit_extension_registry(self): - """ explicit extension registry """ + """explicit extension registry""" registry = self.extension_registry @@ -195,7 +199,6 @@ class Foo(HasTraits): self.assertEqual(0, len(f.x)) def test_should_be_able_to_bind_multiple_traits_on_a_single_object(self): - registry = self.extension_registry # Add 2 extension points. @@ -275,6 +278,6 @@ def test_unbinding_removes_references(self): ########################################################################### def _create_extension_point(self, id, trait_type=List, desc=""): - """ Create an extension point. """ + """Create an extension point.""" return ExtensionPoint(id=id, trait_type=trait_type, desc=desc) diff --git a/envisage/tests/test_extension_point_changed.py b/envisage/tests/test_extension_point_changed.py index d606fd8d7..c5ed24b4f 100644 --- a/envisage/tests/test_extension_point_changed.py +++ b/envisage/tests/test_extension_point_changed.py @@ -14,19 +14,14 @@ # Local imports. from envisage.api import ExtensionPointChangedEvent -from envisage.tests.support import ( - PluginA, - PluginB, - PluginC, - SimpleApplication, -) +from envisage.tests.support import PluginA, PluginB, PluginC, SimpleApplication class ExtensionPointChangedTestCase(unittest.TestCase): - """ Tests for the events fired when extension points are changed. """ + """Tests for the events fired when extension points are changed.""" def test_set_extension_point(self): - """ set extension point """ + """set extension point""" a = PluginA() @@ -38,7 +33,7 @@ def test_set_extension_point(self): setattr(a, "x", [1, 2, 3]) def test_mutate_extension_point_no_events(self): - """ Mutation will not emit change event for name_items """ + """Mutation will not emit change event for name_items""" events = [] @@ -57,7 +52,7 @@ def test_mutate_extension_point_no_events(self): self.assertEqual(events, []) def test_append(self): - """ append """ + """append""" events = [] @@ -102,7 +97,7 @@ def test_append(self): self.assertEqual(3, event.new.index) def test_remove(self): - """ remove """ + """remove""" events = [] @@ -147,7 +142,7 @@ def test_remove(self): self.assertEqual(2, event.new.index) def test_assign_empty_list(self): - """ assign empty list """ + """assign empty list""" events = [] @@ -193,7 +188,7 @@ def test_assign_empty_list(self): self.assertEqual(3, event.new.index.stop) def test_assign_empty_list_no_event(self): - """ assign empty list no event """ + """assign empty list no event""" events = [] @@ -227,7 +222,7 @@ def test_assign_empty_list_no_event(self): self.assertEqual(events, []) def test_assign_non_empty_list(self): - """ assign non-empty list """ + """assign non-empty list""" events = [] @@ -274,9 +269,7 @@ def test_assign_non_empty_list(self): self.assertEqual([1, 2, 3], event.new.removed) # The removed entry should match what the old values say - self.assertEqual( - event.new.removed, source_values[event.new.index] - ) + self.assertEqual(event.new.removed, source_values[event.new.index]) # If we use the index and apply the changes to the old list, we should # recover the new list @@ -287,7 +280,7 @@ def test_assign_non_empty_list(self): self.assertEqual(3, event.new.index.stop) def test_add_plugin(self): - """ add plugin """ + """add plugin""" events = [] @@ -342,7 +335,7 @@ def test_add_plugin(self): self.assertEqual(3, event.new.index) def test_remove_plugin(self): - """ remove plugin """ + """remove plugin""" events = [] @@ -396,10 +389,13 @@ def test_remove_plugin(self): self.assertEqual(0, event.new.index) def test_extension_point_change_event_str_representation(self): - """ test string representation of the ExtensionPointChangedEvent class """ - desired_repr = ("ExtensionPointChangedEvent(extension_point_id={}, " - "index=0, removed=[], added=[])") + test string representation of the ExtensionPointChangedEvent class + """ + desired_repr = ( + "ExtensionPointChangedEvent(extension_point_id={}, " + "index=0, removed=[], added=[])" + ) ext_pt_changed_evt = ExtensionPointChangedEvent(extension_point_id=1) self.assertEqual(desired_repr.format(1), str(ext_pt_changed_evt)) self.assertEqual(desired_repr.format(1), repr(ext_pt_changed_evt)) diff --git a/envisage/tests/test_extension_registry.py b/envisage/tests/test_extension_registry.py index a11e28081..1fa9fc1c9 100644 --- a/envisage/tests/test_extension_registry.py +++ b/envisage/tests/test_extension_registry.py @@ -13,28 +13,27 @@ import contextlib import unittest -# Enthought library imports. -from envisage.api import Application, ExtensionPoint -from envisage.api import ExtensionRegistry from traits.api import List +# Enthought library imports. +from envisage.api import Application, ExtensionPoint, ExtensionRegistry from envisage.tests.test_extension_registry_mixin import ( - ExtensionRegistryTestMixin + ExtensionRegistryTestMixin, ) class ExtensionRegistryTestCase(ExtensionRegistryTestMixin, unittest.TestCase): - """ Tests for the base extension registry. """ + """Tests for the base extension registry.""" def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" # We do all of the testing via the application to make sure it offers # the same interface! self.registry = Application(extension_registry=ExtensionRegistry()) def test_remove_non_empty_extension_point(self): - """ remove non-empty extension point """ + """remove non-empty extension point""" registry = self.registry @@ -55,7 +54,7 @@ def test_remove_non_empty_extension_point(self): self.assertEqual([], registry.get_extensions("my.ep")) def test_set_extensions(self): - """ set extensions """ + """set extensions""" registry = self.registry @@ -75,6 +74,7 @@ def make_function_listener(events): The listener appends events to the ``events`` list. """ + def listener(registry, event): events.append(event) @@ -85,6 +85,7 @@ class ListensToExtensionPoint: """ Class with a method that can be used as an extension point listener. """ + def __init__(self, events): self.events = events @@ -177,7 +178,8 @@ def assertAppendsTo(self, some_list): new_length = len(some_list) diff = new_length - old_length self.assertEqual( - diff, 1, + diff, + 1, msg="Expected exactly one new element; got {}".format(diff), ) @@ -194,6 +196,7 @@ def assertDoesNotModify(self, some_list): new_length = len(some_list) diff = new_length - old_length self.assertEqual( - diff, 0, + diff, + 0, msg="Expected no new elements; got {}".format(diff), ) diff --git a/envisage/tests/test_extension_registry_mixin.py b/envisage/tests/test_extension_registry_mixin.py index bdfdd85ab..fed1a5e38 100644 --- a/envisage/tests/test_extension_registry_mixin.py +++ b/envisage/tests/test_extension_registry_mixin.py @@ -12,21 +12,21 @@ mixin class. """ -# Enthought library imports. -from envisage.api import ExtensionPoint -from envisage.api import UnknownExtensionPoint from traits.api import List +# Enthought library imports. +from envisage.api import ExtensionPoint, UnknownExtensionPoint + class ExtensionRegistryTestMixin: - """ Base set of tests for extension registry and its subclasses. + """Base set of tests for extension registry and its subclasses. Test cases inherriting from this mixin should define a setUp method that defines self.registry as an instance of ExtensionPointRegistry. """ def test_empty_registry(self): - """ empty registry """ + """empty registry""" registry = self.registry @@ -39,7 +39,7 @@ def test_empty_registry(self): self.assertEqual(0, len(extension_points)) def test_add_extension_point(self): - """ add extension point """ + """add extension point""" registry = self.registry @@ -56,7 +56,7 @@ def test_add_extension_point(self): self.assertEqual("my.ep", extension_points[0].id) def test_get_extension_point(self): - """ get extension point """ + """get extension point""" registry = self.registry @@ -69,11 +69,11 @@ def test_get_extension_point(self): self.assertEqual("my.ep", extension_point.id) def test_get_extension_point_return_none_if_not_found(self): - """ get extension point return None if id is not found. """ + """get extension point return None if id is not found.""" self.assertIsNone(self.registry.get_extension_point("i.do.not.exist")) def test_get_extensions_mutation_no_effect_if_undefined(self): - """ test one cannot mutate the registry by mutating the list. """ + """test one cannot mutate the registry by mutating the list.""" # The extension point with id "my.ep" has not been defined extensions = self.registry.get_extensions("my.ep") @@ -85,7 +85,7 @@ def test_get_extensions_mutation_no_effect_if_undefined(self): self.assertEqual(self.registry.get_extensions("my.ep"), []) def test_remove_empty_extension_point(self): - """ remove empty_extension point """ + """remove empty_extension point""" registry = self.registry @@ -100,7 +100,7 @@ def test_remove_empty_extension_point(self): self.assertEqual(0, len(extension_points)) def test_remove_non_existent_extension_point(self): - """ remove non existent extension point """ + """remove non existent extension point""" registry = self.registry @@ -108,12 +108,12 @@ def test_remove_non_existent_extension_point(self): registry.remove_extension_point("my.ep") def test_remove_non_existent_listener(self): - """ remove non existent listener """ + """remove non existent listener""" registry = self.registry def listener(registry, extension_point, added, removed, index): - """ Called when an extension point has changed. """ + """Called when an extension point has changed.""" self.listener_called = (registry, extension_point, added, removed) @@ -121,6 +121,6 @@ def listener(registry, extension_point, added, removed, index): registry.remove_extension_point_listener(listener) def create_extension_point(self, id, trait_type=List, desc=""): - """ Create an extension point. """ + """Create an extension point.""" return ExtensionPoint(id=id, trait_type=trait_type, desc=desc) diff --git a/envisage/tests/test_ids.py b/envisage/tests/test_ids.py index 71bb8c32b..40d2cc612 100644 --- a/envisage/tests/test_ids.py +++ b/envisage/tests/test_ids.py @@ -57,6 +57,5 @@ def check_id_against_plugin(self, id_string, plugin_klass): The Plugin subclass to check. """ self.assertEqual( - getattr(envisage.ids, id_string), - getattr(plugin_klass, id_string) + getattr(envisage.ids, id_string), getattr(plugin_klass, id_string) ) diff --git a/envisage/tests/test_import_manager.py b/envisage/tests/test_import_manager.py index 55e7724d6..4ef9f7f60 100644 --- a/envisage/tests/test_import_manager.py +++ b/envisage/tests/test_import_manager.py @@ -17,17 +17,17 @@ class ImportManagerTestCase(unittest.TestCase): - """ Tests for the import manager. """ + """Tests for the import manager.""" def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" # We do all of the testing via the application to make sure it offers # the same interface! self.import_manager = Application(import_manager=ImportManager()) def test_import_dotted_symbol(self): - """ import dotted symbol """ + """import dotted symbol""" import tarfile @@ -35,7 +35,7 @@ def test_import_dotted_symbol(self): self.assertEqual(symbol, tarfile.TarFile) def test_import_nested_symbol(self): - """ import nested symbol """ + """import nested symbol""" import tarfile @@ -43,7 +43,7 @@ def test_import_nested_symbol(self): self.assertEqual(symbol, tarfile.TarFile.open) def test_import_dotted_module(self): - """ import dotted module """ + """import dotted module""" symbol = self.import_manager.import_symbol( "envisage.api:ImportManager" diff --git a/envisage/tests/test_package_plugin_manager.py b/envisage/tests/test_package_plugin_manager.py index 406bf38e3..5b1d8ad39 100644 --- a/envisage/tests/test_package_plugin_manager.py +++ b/envisage/tests/test_package_plugin_manager.py @@ -10,23 +10,22 @@ """ Tests for the 'Package' plugin manager. """ -from os.path import dirname, join import unittest +from os.path import dirname, join from envisage.package_plugin_manager import PackagePluginManager class PackagePluginManagerTestCase(unittest.TestCase): - """ Tests for the 'Package' plugin manager. """ + """Tests for the 'Package' plugin manager.""" def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" # The location of the 'plugins' test data directory. self.plugins_dir = join(dirname(__file__), "plugins") def test_find_plugins_in_packages_on_the_plugin_path(self): - with self.assertWarns(DeprecationWarning): plugin_manager = PackagePluginManager( plugin_path=[self.plugins_dir] @@ -39,7 +38,6 @@ def test_find_plugins_in_packages_on_the_plugin_path(self): self.assertIn("pear", ids) def test_only_find_plugins_whose_ids_are_in_the_include_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. include = ["orange", "pear"] @@ -57,7 +55,6 @@ def test_only_find_plugins_whose_ids_are_in_the_include_list(self): self._test_start_and_stop(plugin_manager, expected) def test_only_find_plugins_matching_a_wildcard_in_the_include_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. include = ["*r*"] @@ -75,7 +72,6 @@ def test_only_find_plugins_matching_a_wildcard_in_the_include_list(self): self._test_start_and_stop(plugin_manager, expected) def test_ignore_plugins_whose_ids_are_in_the_exclude_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. exclude = ["orange", "pear"] @@ -93,7 +89,6 @@ def test_ignore_plugins_whose_ids_are_in_the_exclude_list(self): self._test_start_and_stop(plugin_manager, expected) def test_ignore_plugins_matching_a_wildcard_in_the_exclude_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. exclude = ["*r*"] @@ -130,8 +125,8 @@ def test_reflect_changes_to_the_plugin_path(self): #### Private protocol ##################################################### def _test_start_and_stop(self, plugin_manager, expected): - """ Make sure the plugin manager starts and stops the expected plugins. - + """ + Make sure the plugin manager starts and stops the expected plugins. """ # Make sure the plugin manager found only the required plugins. diff --git a/envisage/tests/test_plugin.py b/envisage/tests/test_plugin.py index 36ef19fd2..01604999f 100644 --- a/envisage/tests/test_plugin.py +++ b/envisage/tests/test_plugin.py @@ -10,16 +10,17 @@ """ Tests for plugins. """ +import unittest + # Standard library imports. from os.path import exists, join -import unittest + +from traits.api import HasTraits, Instance, Int, Interface, List, provides # Enthought library imports. -from envisage.api import Application, ExtensionPoint -from envisage.api import IPluginActivator, Plugin +from envisage.api import Application, ExtensionPoint, IPluginActivator, Plugin from envisage.tests.ets_config_patcher import ETSConfigPatcher from envisage.tests.support import SimpleApplication -from traits.api import HasTraits, Instance, Int, Interface, List, provides class TestPlugin(Plugin): @@ -27,7 +28,7 @@ class TestPlugin(Plugin): class PluginTestCase(unittest.TestCase): - """ Tests for plugins. """ + """Tests for plugins.""" def setUp(self): ets_config_patcher = ETSConfigPatcher() @@ -35,7 +36,7 @@ def setUp(self): self.addCleanup(ets_config_patcher.stop) def test_id_policy(self): - """ id policy """ + """id policy""" # If no Id is specified then use 'module_name.class_name'. p = Plugin() @@ -51,7 +52,7 @@ def test_id_policy(self): self.assertEqual("fred", p.name) def test_name_policy(self): - """ name policy """ + """name policy""" # If name is specified then use the plugin's class name. p = Plugin() @@ -69,19 +70,19 @@ class ThisIsMyPlugin(Plugin): self.assertEqual("This Is My Plugin", p.name) def test_plugin_activator(self): - """ plugin activator. """ + """plugin activator.""" @provides(IPluginActivator) class NullPluginActivator(HasTraits): - """ A plugin activator that does nothing! """ + """A plugin activator that does nothing!""" def start_plugin(self, plugin): - """ Start a plugin. """ + """Start a plugin.""" self.started = plugin def stop_plugin(self, plugin): - """ Stop a plugin. """ + """Stop a plugin.""" self.stopped = plugin @@ -109,7 +110,7 @@ class PluginB(Plugin): self.assertEqual(a, plugin_activator.stopped) def test_service(self): - """ service """ + """service""" class Foo(HasTraits): pass @@ -149,7 +150,7 @@ class PluginA(Plugin): self.assertEqual(None, application.get_service(Baz)) def test_service_protocol(self): - """ service protocol """ + """service protocol""" class IFoo(Interface): pass @@ -180,7 +181,7 @@ class PluginA(Plugin): self.assertEqual(None, application.get_service(IBar)) def test_multiple_trait_contributions(self): - """ multiple trait contributions """ + """multiple trait contributions""" class PluginA(Plugin): id = "A" @@ -203,7 +204,7 @@ class PluginB(Plugin): application.get_extensions("x") def test_exception_in_trait_contribution(self): - """ exception in trait contribution """ + """exception in trait contribution""" class PluginA(Plugin): id = "A" @@ -215,7 +216,7 @@ class PluginB(Plugin): x = List(contributes_to="x") def _x_default(self): - """ Trait initializer. """ + """Trait initializer.""" raise 1 / 0 @@ -230,7 +231,7 @@ def _x_default(self): application.get_extensions("x") def test_contributes_to(self): - """ contributes to """ + """contributes to""" class PluginA(Plugin): id = "A" @@ -250,7 +251,7 @@ class PluginB(Plugin): self.assertEqual([1, 2, 3], application.get_extensions("x")) def test_add_plugins_to_empty_application(self): - """ add plugins to empty application """ + """add plugins to empty application""" class PluginA(Plugin): id = "A" @@ -326,7 +327,7 @@ class PluginC(Plugin): self.assertEqual([4, 5, 6], a.removed) def test_home(self): - """ home """ + """home""" class PluginA(Plugin): id = "A" @@ -363,7 +364,7 @@ class PluginB(Plugin): self.assertTrue(exists(b.home)) def test_no_recursion(self): - """ Regression test for #119. """ + """Regression test for #119.""" class PluginA(Plugin): id = "A" @@ -373,7 +374,7 @@ class PluginA(Plugin): application.get_extensions("bob") def test_plugin_str_representation(self): - """ test the string representation of the plugin """ + """test the string representation of the plugin""" plugin_repr = "TestPlugin(id={!r}, name={!r})" plugin = TestPlugin(id="Fred", name="Wilma") self.assertEqual(str(plugin), plugin_repr.format("Fred", "Wilma")) diff --git a/envisage/tests/test_plugin_manager.py b/envisage/tests/test_plugin_manager.py index e3615bb60..cc0cb1e1b 100644 --- a/envisage/tests/test_plugin_manager.py +++ b/envisage/tests/test_plugin_manager.py @@ -13,13 +13,14 @@ # Standard library imports. import unittest +from traits.api import Bool + # Enthought library imports. from envisage.api import Plugin, PluginManager -from traits.api import Bool class SimplePlugin(Plugin): - """ A simple plugin. """ + """A simple plugin.""" #### 'SimplePlugin' interface ############################################# @@ -31,41 +32,41 @@ class SimplePlugin(Plugin): ########################################################################### def start(self): - """ Start the plugin. """ + """Start the plugin.""" self.started = True self.stopped = False def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" self.started = False self.stopped = True class BadPlugin(Plugin): - """ A plugin that just causes trouble ;^). """ + """A plugin that just causes trouble ;^).""" ########################################################################### # 'IPlugin' interface. ########################################################################### def start(self): - """ Start the plugin. """ + """Start the plugin.""" raise 1 / 0 def stop(self): - """ Stop the plugin. """ + """Stop the plugin.""" raise 1 / 0 class PluginManagerTestCase(unittest.TestCase): - """ Tests for the plugin manager. """ + """Tests for the plugin manager.""" def test_get_plugin(self): - """ get plugin """ + """get plugin""" simple_plugin = SimplePlugin() plugin_manager = PluginManager(plugins=[simple_plugin]) @@ -78,7 +79,7 @@ def test_get_plugin(self): self.assertEqual(None, plugin_manager.get_plugin("bogus")) def test_iteration_over_plugins(self): - """ iteration over plugins """ + """iteration over plugins""" simple_plugin = SimplePlugin() bad_plugin = BadPlugin() @@ -93,7 +94,7 @@ def test_iteration_over_plugins(self): self.assertEqual([simple_plugin, bad_plugin], plugins) def test_start_and_stop(self): - """ start and stop """ + """start and stop""" simple_plugin = SimplePlugin() plugin_manager = PluginManager(plugins=[simple_plugin]) @@ -113,7 +114,7 @@ def test_start_and_stop(self): self.assertEqual(True, simple_plugin.stopped) def test_start_and_stop_errors(self): - """ start and stop errors """ + """start and stop errors""" simple_plugin = SimplePlugin() bad_plugin = BadPlugin() @@ -138,7 +139,6 @@ def test_start_and_stop_errors(self): plugin_manager.stop_plugin(plugin_id="bogus") def test_only_include_plugins_whose_ids_are_in_the_include_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. include = ["foo", "bar"] @@ -163,7 +163,6 @@ def test_only_include_plugins_whose_ids_are_in_the_include_list(self): def test_only_include_plugins_matching_a_wildcard_in_the_include_list( self, ): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. include = ["b*"] @@ -186,7 +185,6 @@ def test_only_include_plugins_matching_a_wildcard_in_the_include_list( self._test_start_and_stop(plugin_manager, expected) def test_ignore_plugins_whose_ids_are_in_the_exclude_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. exclude = ["foo", "baz"] @@ -209,7 +207,6 @@ def test_ignore_plugins_whose_ids_are_in_the_exclude_list(self): self._test_start_and_stop(plugin_manager, expected) def test_ignore_plugins_matching_a_wildcard_in_the_exclude_list(self): - # Note that the items in the list use the 'fnmatch' syntax for matching # plugins Ids. exclude = ["b*"] @@ -234,8 +231,8 @@ def test_ignore_plugins_matching_a_wildcard_in_the_exclude_list(self): #### Private protocol ##################################################### def _test_start_and_stop(self, plugin_manager, expected): - """ Make sure the plugin manager starts and stops the expected plugins. - + """ + Make sure the plugin manager starts and stops the expected plugins. """ # Make sure the plugin manager found only the required plugins. diff --git a/envisage/tests/test_provider_extension_registry.py b/envisage/tests/test_provider_extension_registry.py index 6635a3d2c..69c32221a 100644 --- a/envisage/tests/test_provider_extension_registry.py +++ b/envisage/tests/test_provider_extension_registry.py @@ -12,43 +12,48 @@ # Standard library imports. import unittest -# Enthought library imports. -from envisage.api import ExtensionPoint, ExtensionProvider -from envisage.api import ProviderExtensionRegistry from traits.api import Int, List +# Enthought library imports. +from envisage.api import ( + ExtensionPoint, + ExtensionProvider, + ProviderExtensionRegistry, +) + # Local imports. from envisage.tests.test_extension_registry_mixin import ( - ExtensionRegistryTestMixin + ExtensionRegistryTestMixin, ) class ProviderExtensionRegistryTestCase( - ExtensionRegistryTestMixin, unittest.TestCase): - """ Tests for the provider extension registry. """ + ExtensionRegistryTestMixin, unittest.TestCase +): + """Tests for the provider extension registry.""" def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" self.registry = ProviderExtensionRegistry() def test_providers(self): - """ providers """ + """providers""" registry = self.registry # Some providers. class ProviderA(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" def get_extension_points(self): - """ Return the extension points offered by the provider. """ + """Return the extension points offered by the provider.""" return [ExtensionPoint(List, "x")] def get_extensions(self, extension_point): - """ Return the provider's contributions to an extension point. - + """ + Return the provider's contributions to an extension point. """ if extension_point == "x": @@ -60,11 +65,11 @@ def get_extensions(self, extension_point): return extensions class ProviderB(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" def get_extensions(self, extension_point): - """ Return the provider's contributions to an extension point. - + """ + Return the provider's contributions to an extension point. """ if extension_point == "x": @@ -76,7 +81,7 @@ def get_extensions(self, extension_point): return extensions class ProviderC(ExtensionProvider): - """ An empty provider! """ + """An empty provider!""" # Add the providers to the registry. registry.add_provider(ProviderA()) @@ -94,24 +99,24 @@ class ProviderC(ExtensionProvider): self.assertEqual("x", extension_points[0].id) def test_provider_extensions_changed(self): - """ provider extensions changed """ + """provider extensions changed""" registry = self.registry # Some providers. class ProviderA(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" x = List(Int) def get_extension_points(self): - """ Return the extension points offered by the provider. """ + """Return the extension points offered by the provider.""" return [ExtensionPoint(List, "my.ep")] def get_extensions(self, extension_point_id): - """ Return the provider's contributions to an extension point. - + """ + Return the provider's contributions to an extension point. """ if extension_point_id == "my.ep": @@ -123,27 +128,27 @@ def get_extensions(self, extension_point_id): return extensions def _x_changed(self, old, new): - """ Static trait change handler. """ + """Static trait change handler.""" self._fire_extension_point_changed( "my.ep", new, old, slice(0, len(old)) ) def _x_items_changed(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" self._fire_extension_point_changed( "my.ep", event.added, event.removed, event.index ) class ProviderB(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" x = List(Int) def get_extensions(self, extension_point_id): - """ Return the provider's contributions to an extension point. - + """ + Return the provider's contributions to an extension point. """ if extension_point_id == "my.ep": @@ -155,14 +160,14 @@ def get_extensions(self, extension_point_id): return extensions def _x_changed(self, old, new): - """ Static trait change handler. """ + """Static trait change handler.""" self._fire_extension_point_changed( "my.ep", new, old, slice(0, len(old)) ) def _x_items_changed(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" self._fire_extension_point_changed( "my.ep", event.added, event.removed, event.index @@ -181,7 +186,7 @@ def _x_items_changed(self, event): # Add an extension listener to the registry. def listener(registry, event): - """ A useful trait change handler for testing! """ + """A useful trait change handler for testing!""" listener.registry = registry listener.extension_point = event.extension_point_id @@ -235,22 +240,22 @@ def listener(registry, event): self.assertEqual([42, 43, 1, 2], extensions) def test_add_provider(self): - """ add provider """ + """add provider""" registry = self.registry # A provider. class ProviderA(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" def get_extension_points(self): - """ Return the extension points offered by the provider. """ + """Return the extension points offered by the provider.""" return [ExtensionPoint(List, "x")] def get_extensions(self, extension_point): - """ Return the provider's contributions to an extension point. - + """ + Return the provider's contributions to an extension point. """ if extension_point == "x": @@ -262,7 +267,7 @@ def get_extensions(self, extension_point): return extensions def _x_items_changed(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" self._fire_extension_point_changed( "x", event.added, event.removed, event.index @@ -278,7 +283,7 @@ def _x_items_changed(self, event): # Add an extension listener to the registry. def listener(registry, event): - """ A useful trait change handler for testing! """ + """A useful trait change handler for testing!""" listener.registry = registry listener.extension_point = event.extension_point_id @@ -290,11 +295,11 @@ def listener(registry, event): # Add a new provider. class ProviderB(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" def get_extensions(self, extension_point): - """ Return the provider's contributions to an extension point. - + """ + Return the provider's contributions to an extension point. """ if extension_point == "x": @@ -320,16 +325,16 @@ def get_extensions(self, extension_point): self.assertTrue(44 in extensions) def test_get_providers(self): - """ get providers """ + """get providers""" registry = self.registry # Some providers. class ProviderA(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" class ProviderB(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" a = ProviderA() b = ProviderB() @@ -342,22 +347,22 @@ class ProviderB(ExtensionProvider): self.assertEqual([a, b], registry.get_providers()) def test_remove_provider(self): - """ remove provider """ + """remove provider""" registry = self.registry # Some providers. class ProviderA(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" def get_extension_points(self): - """ Return the extension points offered by the provider. """ + """Return the extension points offered by the provider.""" return [ExtensionPoint(List, "x"), ExtensionPoint(List, "y")] def get_extensions(self, extension_point): - """ Return the provider's contributions to an extension point. - + """ + Return the provider's contributions to an extension point. """ if extension_point == "x": @@ -369,18 +374,18 @@ def get_extensions(self, extension_point): return extensions def _x_items_changed(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" self._fire_extension_point_changed( "x", event.added, event.removed, event.index ) class ProviderB(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" def get_extensions(self, extension_point): - """ Return the provider's contributions to an extension point. - + """ + Return the provider's contributions to an extension point. """ if extension_point == "x": @@ -406,7 +411,7 @@ def get_extensions(self, extension_point): # Add an extension listener to the registry. def listener(registry, event): - """ A useful trait change handler for testing! """ + """A useful trait change handler for testing!""" listener.registry = registry listener.extension_point = event.extension_point_id @@ -444,22 +449,22 @@ def listener(registry, event): self.assertEqual([42], listener.removed) def test_remove_provider_with_no_contributions(self): - """ remove provider with no contributions """ + """remove provider with no contributions""" registry = self.registry # Some providers. class ProviderA(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" def get_extension_points(self): - """ Return the extension points offered by the provider. """ + """Return the extension points offered by the provider.""" return [ExtensionPoint(List, "x"), ExtensionPoint(List, "y")] def get_extensions(self, extension_point): - """ Return the provider's contributions to an extension point. - + """ + Return the provider's contributions to an extension point. """ return [] @@ -474,7 +479,7 @@ def get_extensions(self, extension_point): # Add an extension listener to the registry. def listener(registry, event): - """ A useful trait change handler for testing! """ + """A useful trait change handler for testing!""" listener.registry = registry listener.extension_point = event.extension_point_id @@ -498,13 +503,13 @@ def listener(registry, event): self.assertEqual(None, getattr(listener, "registry", None)) def test_remove_non_existent_provider(self): - """ remove provider """ + """remove provider""" registry = self.registry # Some providers. class ProviderA(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" pass @@ -515,7 +520,7 @@ class ProviderA(ExtensionProvider): registry.remove_provider(a) def test_set_extensions(self): - """ set extensions """ + """set extensions""" registry = self.registry @@ -527,22 +532,24 @@ def test_set_extensions(self): registry.set_extensions("my.ep", [1, 2, 3]) def test_remove_non_empty_extension_point(self): - """ remove non-empty extension point """ + """remove non-empty extension point""" registry = self.registry # Some providers. class ProviderA(ExtensionProvider): - """ An extension provider. """ + """An extension provider.""" def get_extension_points(self): - """ Return the extension points offered by the provider. """ + """ + Return the extension points offered by the provider. + """ return [ExtensionPoint(List, "x")] def get_extensions(self, extension_point): - """ Return the provider's contributions to an extension point. - + """ + Return the provider's contributions to an extension point. """ if extension_point == "x": diff --git a/envisage/tests/test_service.py b/envisage/tests/test_service.py index 84c8f7d0b..f43140c3d 100644 --- a/envisage/tests/test_service.py +++ b/envisage/tests/test_service.py @@ -20,10 +20,10 @@ class ServiceTestCase(unittest.TestCase): - """ Tests for the 'Service' trait type. """ + """Tests for the 'Service' trait type.""" def test_service_trait_type(self): - """ service trait type""" + """service trait type""" class Foo(HasTraits): pass @@ -56,7 +56,7 @@ class PluginB(Plugin): setattr(b, "foo", "bogus") def test_service_trait_type_with_no_service_registry(self): - """ service trait type with no service registry """ + """service trait type with no service registry""" class Foo(HasTraits): pass @@ -71,7 +71,7 @@ class Bar(HasTraits): getattr(b, "foo") def test_service_str_representation(self): - """ test the string representation of the service """ + """test the string representation of the service""" class Foo(HasTraits): pass diff --git a/envisage/tests/test_service_registry.py b/envisage/tests/test_service_registry.py index 17b62148b..5b53bc71f 100644 --- a/envisage/tests/test_service_registry.py +++ b/envisage/tests/test_service_registry.py @@ -14,30 +14,30 @@ import sys import unittest -# Enthought library imports. -from envisage.api import Application, ServiceRegistry, NoSuchServiceError from traits.api import HasTraits, Int, Interface, provides +# Enthought library imports. +from envisage.api import Application, NoSuchServiceError, ServiceRegistry # This module's package. PKG = "envisage.tests" def service_factory(**properties): - """ A factory for foos. """ + """A factory for foos.""" return HasTraits(**properties) class ServiceRegistryTestCase(unittest.TestCase): - """ Tests for the service registry. """ + """Tests for the service registry.""" ########################################################################### # 'TestCase' interface. ########################################################################### def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" # We do all of the testing via the application to make sure it offers # the same interface! @@ -72,7 +72,7 @@ class IFoo(Interface): self.service_registry.get_required_service(IFoo) def test_imported_service_factory(self): - """ imported service factory """ + """imported service factory""" class IFoo(Interface): price = Int @@ -98,7 +98,7 @@ class IFoo(Interface): self.assertTrue(service is service2) def test_function_service_factory(self): - """ function service factory """ + """function service factory""" class IFoo(Interface): price = Int @@ -108,7 +108,7 @@ class Foo(HasTraits): price = Int def foo_factory(**properties): - """ A factory for foos. """ + """A factory for foos.""" return Foo(**properties) @@ -128,11 +128,11 @@ def foo_factory(**properties): self.assertTrue(service is service2) def test_lazy_function_service_factory(self): - """ lazy function service factory """ + """lazy function service factory""" # Register a service factory by name. def foo_factory(**properties): - """ A factory for foos. """ + """A factory for foos.""" from envisage.tests.foo import Foo @@ -167,13 +167,13 @@ def foo_factory(**properties): del sys.modules[foo] def test_lazy_bound_method_service_factory(self): - """ lazy bound method service factory """ + """lazy bound method service factory""" i_foo = PKG + ".i_foo.IFoo" foo = PKG + ".foo" class ServiceProvider(HasTraits): - """ A class that provides a service. + """A class that provides a service. This is used to make sure a bound method can be used as a service factory. @@ -182,7 +182,7 @@ class ServiceProvider(HasTraits): # Register a service factory by name. def foo_factory(self, **properties): - """ A factory for foos. """ + """A factory for foos.""" from envisage.tests.foo import Foo @@ -215,7 +215,7 @@ def foo_factory(self, **properties): del sys.modules[foo] def test_get_services(self): - """ get services """ + """get services""" class IFoo(Interface): pass @@ -243,7 +243,7 @@ class IBar(Interface): self.assertEqual([], services) def test_get_services_with_strings(self): - """ get services with strings """ + """get services with strings""" from envisage.tests.foo import Foo @@ -258,7 +258,7 @@ def test_get_services_with_strings(self): self.assertEqual(2, len(services)) def test_get_services_with_query(self): - """ get services with query """ + """get services with query""" class IFoo(Interface): price = Int @@ -301,7 +301,7 @@ class IBar(Interface): self.assertEqual([], services) def test_get_service(self): - """ get service """ + """get service""" class IFoo(Interface): pass @@ -329,7 +329,7 @@ class IBar(Interface): self.assertEqual(None, service) def test_get_service_with_query(self): - """ get service with query """ + """get service with query""" class IFoo(Interface): price = Int @@ -370,7 +370,7 @@ class IBar(Interface): self.assertEqual(None, service) def test_get_and_set_service_properties(self): - """ get and set service properties """ + """get and set service properties""" class IFoo(Interface): price = Int @@ -422,7 +422,7 @@ class Foo(HasTraits): self.service_registry.set_service_properties(-1, {}) def test_unregister_service(self): - """ unregister service """ + """unregister service""" class IFoo(Interface): price = Int @@ -478,7 +478,7 @@ class Foo(HasTraits): self.service_registry.unregister_service(-1) def test_minimize_and_maximize(self): - """ minimize and maximize """ + """minimize and maximize""" class IFoo(Interface): price = Int diff --git a/envisage/tests/test_slice.py b/envisage/tests/test_slice.py index 5365953e0..04bcf20c8 100644 --- a/envisage/tests/test_slice.py +++ b/envisage/tests/test_slice.py @@ -20,13 +20,12 @@ # Enthought library imports. from traits.api import HasTraits, List - # The starting list for all tests. TEST_LIST = [7, 9, 2, 3, 4, 1, 6, 5, 8, 0] def listener(obj, trait_name, old, event): - """ Recreate a list operation from a trait list event. """ + """Recreate a list operation from a trait list event.""" clone = TEST_LIST[:] @@ -47,7 +46,7 @@ def listener(obj, trait_name, old, event): # workaroud for traits bug in Python 3 # https://github.com/enthought/traits/issues/334 index = event.index if event.index is not None else 0 - del clone[index:index + len(event.removed)] + del clone[index : index + len(event.removed)] # If nothing was removed then it is an 'append', 'insert' or 'extend' # operation. @@ -56,7 +55,7 @@ def listener(obj, trait_name, old, event): clone[event.index] = added else: - clone[event.index:event.index] = added + clone[event.index : event.index] = added # Otherwise, it is an assigment ('sort' and 'reverse' fall into this # category). @@ -65,16 +64,16 @@ def listener(obj, trait_name, old, event): clone[event.index] = added else: - clone[event.index:event.index + len(added)] = added + clone[event.index : event.index + len(added)] = added listener.clone = clone class SliceTestCase(unittest.TestCase): - """ Tests to help find out how trait list events work. """ + """Tests to help find out how trait list events work.""" def setUp(self): - """ Prepares the test fixture before each test method is called. """ + """Prepares the test fixture before each test method is called.""" class Foo(HasTraits): elts = List @@ -83,98 +82,98 @@ class Foo(HasTraits): self.f.on_trait_change(listener, "elts_items") def test_append(self): - """ append """ + """append""" self.f.elts.append(99) # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_insert(self): - """ insert """ + """insert""" self.f.elts.insert(3, 99) # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_extend(self): - """ extend """ + """extend""" self.f.elts.extend([99, 100]) # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_remove(self): - """ remove """ + """remove""" self.f.elts.remove(5) # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_reverse(self): - """ reverse """ + """reverse""" self.f.elts.reverse() # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_sort(self): - """ sort """ + """sort""" self.f.elts.sort() # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_pop(self): - """ remove """ + """remove""" self.f.elts.pop() # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_del_all(self): - """ del all """ + """del all""" del self.f.elts[:] # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_assign_item(self): - """ assign item """ + """assign item""" self.f.elts[3] = 99 # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_del_item(self): - """ del item """ + """del item""" del self.f.elts[3] # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_assign_slice(self): - """ assign slice """ + """assign slice""" self.f.elts[2:4] = [88, 99] # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_del_slice(self): - """ del slice """ + """del slice""" del self.f.elts[2:5] # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_assign_extended_slice(self): - """ assign extended slice """ + """assign extended slice""" self.f.elts[2:6:2] = [88, 99] # Make sure we successfully recreated the operation. self.assertEqual(self.f.elts, listener.clone) def test_del_extended_slice(self): - """ del extended slice """ + """del extended slice""" del self.f.elts[2:6:2] # Make sure we successfully recreated the operation. diff --git a/envisage/ui/action/abstract_action_manager_builder.py b/envisage/ui/action/abstract_action_manager_builder.py index 05789e4bf..98008ee84 100644 --- a/envisage/ui/action/abstract_action_manager_builder.py +++ b/envisage/ui/action/abstract_action_manager_builder.py @@ -23,7 +23,7 @@ @provides(IActionManagerBuilder) class AbstractActionManagerBuilder(HasTraits): - """ Builds menus, menu bars and tool bars from action sets. + """Builds menus, menu bars and tool bars from action sets. This class *must* be subclassed, and the following methods implemented:: @@ -47,7 +47,7 @@ class AbstractActionManagerBuilder(HasTraits): ########################################################################### def create_menu_bar_manager(self, root): - """ Create a menu bar manager from the builder's action sets. """ + """Create a menu bar manager from the builder's action sets.""" menu_bar_manager = self._create_menu_bar_manager() @@ -57,7 +57,7 @@ def create_menu_bar_manager(self, root): # fixme: V3 refactor loooong (and confusing) method! def create_tool_bar_managers(self, root): - """ Creates all tool bar managers from the builder's action sets. """ + """Creates all tool bar managers from the builder's action sets.""" ######################################## # New style (i.e multi) tool bars. @@ -128,7 +128,7 @@ def create_tool_bar_managers(self, root): return tool_bar_managers def initialize_action_manager(self, action_manager, root): - """ Initialize an action manager from the builder's action sets. """ + """Initialize an action manager from the builder's action sets.""" # Get all of the groups and menus for the specified root (for toolbars # there will **only** be groups). @@ -149,27 +149,27 @@ def initialize_action_manager(self, action_manager, root): ########################################################################### def _create_action(self, action_definition): - """ Creates an action implementation from a definition. """ + """Creates an action implementation from a definition.""" raise NotImplementedError def _create_group(self, group_definition): - """ Creates a group implementation from a definition. """ + """Creates a group implementation from a definition.""" raise NotImplementedError def _create_menu_manager(self, menu_manager_definition): - """ Creates a menu manager implementation from a definition. """ + """Creates a menu manager implementation from a definition.""" raise NotImplementedError def _create_menu_bar_manager(self): - """ Creates a menu bar manager implementation. """ + """Creates a menu bar manager implementation.""" raise NotImplementedError def _create_tool_bar_manager(self, tool_bar_definition): - """ Creates a tool bar manager implementation from a definition. """ + """Creates a tool bar manager implementation from a definition.""" raise NotImplementedError @@ -181,14 +181,14 @@ def _create_tool_bar_manager(self, tool_bar_definition): @observe("action_sets") def _update_action_sets_on_manager(self, event): - """ Static trait change handler. """ + """Static trait change handler.""" new = event.new self._action_set_manager.action_sets = new #### Methods ############################################################## def _add_actions(self, action_manager, actions): - """ Add the specified actions to an action manager. """ + """Add the specified actions to an action manager.""" while len(actions) > 0: start = len(actions) @@ -217,7 +217,7 @@ def _add_actions(self, action_manager, actions): raise ValueError("Could not place %s" % actions) def _add_action(self, action_manager, action): - """ Add an action to an action manager. + """Add an action to an action manager. Return True if the action was added successfully. @@ -253,7 +253,7 @@ def _add_action(self, action_manager, action): return True def _add_groups_and_menus(self, action_manager, groups_and_menus): - """ Add the specified groups and menus to an action manager. """ + """Add the specified groups and menus to an action manager.""" # The reason we put the groups and menus together is that as we iterate # over the list trying to add them, we might need to add a group before @@ -285,7 +285,7 @@ def _add_groups_and_menus(self, action_manager, groups_and_menus): raise ValueError("Could not place %s" % groups_and_menus) def _add_group(self, action_manager, group): - """ Add a group to an action manager. + """Add a group to an action manager. Return True if the group was added successfully. @@ -328,7 +328,7 @@ def _add_group(self, action_manager, group): return True def _add_menu(self, menu_manager, menu): - """ Add a menu manager to a errr, menu manager. + """Add a menu manager to a errr, menu manager. Return True if the menu was added successfully. @@ -371,7 +371,7 @@ def _add_menu(self, menu_manager, menu): return True def _find_group(self, action_manager, id): - """ Find the group with the specified ID. """ + """Find the group with the specified ID.""" if len(id) > 0: group = action_manager.find_group(id) @@ -382,7 +382,7 @@ def _find_group(self, action_manager, id): return group def _find_action_manager(self, action_manager, path): - """ Return the action manager at the specified path. + """Return the action manager at the specified path. Returns None if the action manager cannot be found. @@ -398,7 +398,7 @@ def _find_action_manager(self, action_manager, path): return action_manager def _make_submenus(self, menu_manager, path): - """ Retutn the menu manager identified by the path. + """Retutn the menu manager identified by the path. Make any intermediate menu-managers that are missing. diff --git a/envisage/ui/action/action.py b/envisage/ui/action/action.py index 3fa2d9131..ae358e747 100644 --- a/envisage/ui/action/action.py +++ b/envisage/ui/action/action.py @@ -18,7 +18,7 @@ class Action(Location): - """ The *definition* of an action in a tool bar or menu. """ + """The *definition* of an action in a tool bar or menu.""" #### Action implementation ################################################ @@ -33,7 +33,7 @@ class Action(Location): ########################################################################### def __str__(self): - """ Return the 'informal' string representation of the object. """ + """Return the 'informal' string representation of the object.""" return "Action(%s)" % self.name diff --git a/envisage/ui/action/action_set.py b/envisage/ui/action/action_set.py index d170669b1..cf59b0acc 100644 --- a/envisage/ui/action/action_set.py +++ b/envisage/ui/action/action_set.py @@ -14,16 +14,15 @@ import logging # Enthought library imports. -from traits.api import Bool, Dict, HasTraits, List, Str, provides +from traits.api import Bool, Dict, HasTraits, List, provides, Str from traits.util.camel_case import camel_case_to_words # Local imports. from .action import Action from .group import Group +from .i_action_set import IActionSet from .menu import Menu from .tool_bar import ToolBar -from .i_action_set import IActionSet - # Logging. logger = logging.getLogger(__name__) @@ -31,7 +30,7 @@ @provides(IActionSet) class ActionSet(HasTraits): - """ An action set is a collection of menus, groups, and actions. """ + """An action set is a collection of menus, groups, and actions.""" # The action set's globally unique identifier. id = Str @@ -97,7 +96,7 @@ class ActionSet(HasTraits): #### Trait initializers ################################################### def _id_default(self): - """ Trait initializer. """ + """Trait initializer.""" id = "%s.%s" % (type(self).__module__, type(self).__name__) logger.warning("action set %s has no Id - using <%s>" % (self, id)) @@ -105,7 +104,7 @@ def _id_default(self): return id def _name_default(self): - """ Trait initializer. """ + """Trait initializer.""" name = camel_case_to_words(type(self).__name__) logger.warning("action set %s has no name - using <%s>" % (self, name)) diff --git a/envisage/ui/action/action_set_manager.py b/envisage/ui/action/action_set_manager.py index a32748ee2..1b994d3cc 100644 --- a/envisage/ui/action/action_set_manager.py +++ b/envisage/ui/action/action_set_manager.py @@ -18,7 +18,7 @@ class ActionSetManager(HasTraits): - """ Manages a collection of action sets. """ + """Manages a collection of action sets.""" #### 'ActionSetManager' interface ######################################### @@ -30,22 +30,22 @@ class ActionSetManager(HasTraits): ########################################################################### def get_actions(self, root): - """ Return all action definitions for a root. """ + """Return all action definitions for a root.""" return self._get_items(self.action_sets, "actions", root) def get_groups(self, root): - """ Return all group definitions for a root. """ + """Return all group definitions for a root.""" return self._get_items(self.action_sets, "groups", root) def get_menus(self, root): - """ Return all menu definitions for a root. """ + """Return all menu definitions for a root.""" return self._get_items(self.action_sets, "menus", root) def get_tool_bars(self, root): - """ Return all tool bar definitions for a root. """ + """Return all tool bar definitions for a root.""" return self._get_items(self.action_sets, "tool_bars", root) @@ -54,7 +54,7 @@ def get_tool_bars(self, root): ########################################################################### def _get_items(self, action_sets, attribute_name, root): - """ Return all actions, groups or menus for a particular root. + """Return all actions, groups or menus for a particular root. e.g. To get all of the groups:: @@ -81,7 +81,7 @@ def _get_items(self, action_sets, attribute_name, root): return items def _get_root(self, path, aliases): - """ Return the effective root for a path. + """Return the effective root for a path. If the first component of the path matches an alias, then we return the value of the alias. diff --git a/envisage/ui/action/api.py b/envisage/ui/action/api.py index 36fb52a4a..7b462d3ce 100644 --- a/envisage/ui/action/api.py +++ b/envisage/ui/action/api.py @@ -7,12 +7,11 @@ # is also available online at http://www.enthought.com/licenses/BSD.txt # # Thanks for using Enthought open source! -from .i_action_set import IActionSet -from .i_action_manager_builder import IActionManagerBuilder - from .abstract_action_manager_builder import AbstractActionManagerBuilder from .action import Action from .action_set import ActionSet from .group import Group +from .i_action_manager_builder import IActionManagerBuilder +from .i_action_set import IActionSet from .menu import Menu from .tool_bar import ToolBar diff --git a/envisage/ui/action/group.py b/envisage/ui/action/group.py index 9c22849bf..ba4cf1d61 100644 --- a/envisage/ui/action/group.py +++ b/envisage/ui/action/group.py @@ -18,7 +18,7 @@ class Group(Location): - """ The *definition* of a group in a tool bar or menu. """ + """The *definition* of a group in a tool bar or menu.""" # The group's unique identifier (unique within the tool bar, menu bar or # menu that the group is to be added to). @@ -36,7 +36,7 @@ class Group(Location): ########################################################################### def __str__(self): - """ Return the 'informal' string representation of the object. """ + """Return the 'informal' string representation of the object.""" return "Group(%s)" % self.id diff --git a/envisage/ui/action/i_action_manager_builder.py b/envisage/ui/action/i_action_manager_builder.py index ee1cb5a0e..488c90cd9 100644 --- a/envisage/ui/action/i_action_manager_builder.py +++ b/envisage/ui/action/i_action_manager_builder.py @@ -18,7 +18,7 @@ class IActionManagerBuilder(Interface): - """ The interface for action manager builders. + """The interface for action manager builders. An action manager builder populates action managers (i.e. menus, menu bars and tool bars) from the menus, groups and actions defined in its action @@ -30,6 +30,4 @@ class IActionManagerBuilder(Interface): action_sets = List(ActionSet) def initialize_action_manager(self, action_manager, root): - """ Initialize an action manager from the builder's action sets. - - """ + """Initialize an action manager from the builder's action sets.""" diff --git a/envisage/ui/action/i_action_set.py b/envisage/ui/action/i_action_set.py index 77ecb6e2d..7aabe94da 100644 --- a/envisage/ui/action/i_action_set.py +++ b/envisage/ui/action/i_action_set.py @@ -21,7 +21,7 @@ class IActionSet(Interface): - """ The action set interface. + """The action set interface. An action set is a collection of menus, groups, and actions. diff --git a/envisage/ui/action/location.py b/envisage/ui/action/location.py index 5a67e2ca9..03772fc45 100644 --- a/envisage/ui/action/location.py +++ b/envisage/ui/action/location.py @@ -15,9 +15,7 @@ class Location(HasTraits): - """ The location of a group, menu, or action, within an action hierarchy. - - """ + """The location of a group, menu, or action, within an action hierarchy.""" # A forward-slash-separated path through the action hierarchy to the menu # to add the action, group or menu to. diff --git a/envisage/ui/action/menu.py b/envisage/ui/action/menu.py index 3f5f897fb..9cedd9273 100644 --- a/envisage/ui/action/menu.py +++ b/envisage/ui/action/menu.py @@ -18,7 +18,7 @@ class CGroup(Instance): - """ A trait type for a 'Group' or anything that can be cast to a 'Group'. + """A trait type for a 'Group' or anything that can be cast to a 'Group'. Currently, the only cast allowed is from string -> Group using the string as the group's ID. @@ -30,7 +30,7 @@ class CGroup(Instance): ########################################################################### def __init__(self, **kw): - """ Constructor. """ + """Constructor.""" super().__init__(klass=Group, **kw) @@ -39,7 +39,7 @@ def __init__(self, **kw): ########################################################################### def validate(self, object, name, value): - """ Validate a value. """ + """Validate a value.""" if isinstance(value, str): value = Group(id=value) @@ -48,7 +48,7 @@ def validate(self, object, name, value): class Menu(Location): - """ The *definition* of a menu in a menu bar or menu. """ + """The *definition* of a menu in a menu bar or menu.""" # The menu's unique identifier (unique within the group that the menu is to # be added to). @@ -69,7 +69,7 @@ class Menu(Location): ########################################################################### def __str__(self): - """ Return the 'informal' string representation of the object. """ + """Return the 'informal' string representation of the object.""" return "Menu(%s)" % self.name @@ -80,6 +80,6 @@ def __str__(self): ########################################################################### def _id_default(self): - """ Trait initializer. """ + """Trait initializer.""" return self.name.strip("&") diff --git a/envisage/ui/action/tests/dummy_action_manager_builder.py b/envisage/ui/action/tests/dummy_action_manager_builder.py index c8e6ae26f..510b67454 100644 --- a/envisage/ui/action/tests/dummy_action_manager_builder.py +++ b/envisage/ui/action/tests/dummy_action_manager_builder.py @@ -9,14 +9,14 @@ # Thanks for using Enthought open source! """ A menu builder that doesn't build real actions! """ +from pyface.action.api import Action, Group, MenuBarManager, MenuManager + # Enthought library imports. from envisage.ui.action.api import AbstractActionManagerBuilder -from pyface.action.api import Action, Group, MenuManager -from pyface.action.api import MenuBarManager class DummyActionManagerBuilder(AbstractActionManagerBuilder): - """ An action manager builder that doesn't build real actions! + """An action manager builder that doesn't build real actions! This makes it very easy to test! @@ -27,7 +27,7 @@ class DummyActionManagerBuilder(AbstractActionManagerBuilder): ########################################################################### def create_menu_bar_manager(self, root): - """ Create a menu bar manager from the builder's action sets. """ + """Create a menu bar manager from the builder's action sets.""" menu_bar_manager = MenuBarManager(id="MenuBar") @@ -40,17 +40,17 @@ def create_menu_bar_manager(self, root): ########################################################################### def _create_action(self, action_definition): - """ Create an action implementation from a definition. """ + """Create an action implementation from a definition.""" return Action(name=action_definition.class_name) def _create_group(self, group_definition): - """ Create a group implementation from a definition. """ + """Create a group implementation from a definition.""" return Group(id=group_definition.id) def _create_menu_manager(self, menu_definition): - """ Create a menu manager implementation from a definition. """ + """Create a menu manager implementation from a definition.""" menu_manager = MenuManager(id=menu_definition.id) for group_definition in menu_definition.groups: diff --git a/envisage/ui/action/tests/test_action_manager_builder.py b/envisage/ui/action/tests/test_action_manager_builder.py index eacf15b86..f71c5d099 100644 --- a/envisage/ui/action/tests/test_action_manager_builder.py +++ b/envisage/ui/action/tests/test_action_manager_builder.py @@ -20,10 +20,10 @@ class ActionManagerBuilderTestCase(unittest.TestCase): - """ Tests for the action manager builder. """ + """Tests for the action manager builder.""" def test_action_with_nonexistent_group(self): - """ action with non-existent group """ + """action with non-existent group""" action_sets = [ ActionSet( @@ -43,7 +43,7 @@ def test_action_with_nonexistent_group(self): builder.create_menu_bar_manager("MenuBar") def test_action_with_nonexistent_sibling(self): - """ action with non-existent sibling """ + """action with non-existent sibling""" action_sets = [ ActionSet( @@ -65,7 +65,7 @@ def test_action_with_nonexistent_sibling(self): builder.create_menu_bar_manager("MenuBar") def test_group_with_nonexistent_sibling(self): - """ group with non-existent sibling """ + """group with non-existent sibling""" action_sets = [ ActionSet( @@ -83,7 +83,7 @@ def test_group_with_nonexistent_sibling(self): builder.create_menu_bar_manager("MenuBar") def test_menu_with_nonexistent_sibling(self): - """ menu with non-existent sibling """ + """menu with non-existent sibling""" action_sets = [ ActionSet( @@ -99,7 +99,7 @@ def test_menu_with_nonexistent_sibling(self): builder.create_menu_bar_manager("MenuBar") def test_action_with_path_component_that_is_not_a_menu(self): - """ action with path component that is not a menu """ + """action with path component that is not a menu""" action_sets = [ ActionSet( @@ -118,7 +118,7 @@ def test_action_with_path_component_that_is_not_a_menu(self): builder.create_menu_bar_manager("MenuBar") def test_single_top_level_menu_with_no_group(self): - """ single top level menu with no group """ + """single top level menu with no group""" action_sets = [ActionSet(menus=[Menu(name="&File", path="MenuBar")])] @@ -137,7 +137,7 @@ def test_single_top_level_menu_with_no_group(self): self.assertEqual(["File"], ids) def test_single_top_level_group(self): - """ single top level group """ + """single top level group""" action_sets = [ ActionSet(groups=[Group(id="FileMenuGroup", path="MenuBar")]) @@ -156,7 +156,7 @@ def test_single_top_level_group(self): self.assertEqual(["FileMenuGroup", "additions"], ids) def test_top_level_menus_with_no_groups(self): - """ top level menus with_no groups """ + """top level menus with_no groups""" action_sets = [ ActionSet( @@ -184,7 +184,7 @@ def test_top_level_menus_with_no_groups(self): self.assertEqual(["File", "Edit", "Tools", "Help"], ids) def test_top_level_menus_no_groups_before_and_after(self): - """ top level menus no groups, before and after """ + """top level menus no groups, before and after""" action_sets = [ ActionSet( @@ -212,7 +212,7 @@ def test_top_level_menus_no_groups_before_and_after(self): self.assertEqual(["File", "Edit", "Tools", "Help"], ids) def test_top_level_menu_non_existent_group(self): - """ top level menu non-existent group """ + """top level menu non-existent group""" action_sets = [ ActionSet( @@ -230,7 +230,7 @@ def test_top_level_menu_non_existent_group(self): builder.create_menu_bar_manager("MenuBar") def test_top_level_menu_group(self): - """ top level menu group """ + """top level menu group""" action_sets = [ ActionSet( @@ -258,7 +258,7 @@ def test_top_level_menu_group(self): self.assertEqual("File", group.items[0].id) def test_sub_menus_no_groups(self): - """ sub-menus no groups """ + """sub-menus no groups""" # We split the contributions into different action sets just because # that is how it might end up in an actual application... not because @@ -289,7 +289,7 @@ def test_sub_menus_no_groups(self): self.assertEqual("New", additions.items[0].id) def test_actions_no_groups(self): - """ actions no groups """ + """actions no groups""" # We split the contributions into different action sets just because # that is how it might end up in an actual application... not because @@ -332,7 +332,7 @@ def test_actions_no_groups(self): self.assertEqual("About", additions.items[0].id) def test_actions_make_submenus(self): - """ actions make submenus """ + """actions make submenus""" action_sets = [ ActionSet( @@ -372,7 +372,7 @@ def test_actions_make_submenus(self): self.assertEqual("File", additions.items[1].id) def test_actions_make_submenus_before_and_after(self): - """ actions make submenus before and after """ + """actions make submenus before and after""" action_sets = [ ActionSet( @@ -421,7 +421,7 @@ def test_actions_make_submenus_before_and_after(self): self.assertEqual(["Project", "Folder", "File"], ids) def test_explicit_groups(self): - """ explicit groups """ + """explicit groups""" action_sets = [ ActionSet( @@ -498,7 +498,7 @@ def test_explicit_groups(self): self.assertEqual("Exit", group.items[0].id) def test_actions_and_menus_in_groups(self): - """ actions and menus in groups """ + """actions and menus in groups""" action_sets = [ ActionSet( @@ -573,7 +573,7 @@ def test_actions_and_menus_in_groups(self): self.assertEqual("Exit", group.items[0].id) def test_duplicate_menu(self): - """ duplicate menu """ + """duplicate menu""" action_sets = [ ActionSet( @@ -627,7 +627,7 @@ def test_duplicate_menu(self): ) def test_duplicate_group(self): - """ duplicate group """ + """duplicate group""" action_sets = [ ActionSet( @@ -639,7 +639,6 @@ def test_duplicate_group(self): Group(id="NewGroup", path="MenuBar/File"), Group(id="ExitGroup", path="MenuBar/File"), ], - ), ], ), diff --git a/envisage/ui/action/tool_bar.py b/envisage/ui/action/tool_bar.py index 4786eba45..b4ac5aac8 100644 --- a/envisage/ui/action/tool_bar.py +++ b/envisage/ui/action/tool_bar.py @@ -19,7 +19,7 @@ # fixme: Remove duplication (in menu.py too!) class CGroup(Instance): - """ A trait type for a 'Group' or anything that can be cast to a 'Group'. + """A trait type for a 'Group' or anything that can be cast to a 'Group'. Currently, the only cast allowed is from string -> Group using the string as the group's ID. @@ -31,7 +31,7 @@ class CGroup(Instance): ########################################################################### def __init__(self, **kw): - """ Constructor. """ + """Constructor.""" super().__init__(klass=Group, **kw) @@ -40,7 +40,7 @@ def __init__(self, **kw): ########################################################################### def validate(self, object, name, value): - """ Validate a value. """ + """Validate a value.""" if isinstance(value, str): value = Group(id=value) @@ -49,7 +49,7 @@ def validate(self, object, name, value): class ToolBar(Location): - """ The *definition* of a menu in a menu bar or menu. """ + """The *definition* of a menu in a menu bar or menu.""" # The tool bars's unique identifier (unique within the multi-toolbar # that the tool bar is to be added to). @@ -70,7 +70,7 @@ class ToolBar(Location): ########################################################################### def __str__(self): - """ Return the 'informal' string representation of the object. """ + """Return the 'informal' string representation of the object.""" return "ToolBar(%s)" % self.name @@ -81,7 +81,7 @@ def __str__(self): ########################################################################### def _path_default(self): - """ Trait initializer. """ + """Trait initializer.""" return "ToolBar" @@ -90,6 +90,6 @@ def _path_default(self): ########################################################################### def _id_default(self): - """ Trait initializer. """ + """Trait initializer.""" return self.name diff --git a/envisage/ui/gui_application.py b/envisage/ui/gui_application.py index ca9916a46..4af485a39 100644 --- a/envisage/ui/gui_application.py +++ b/envisage/ui/gui_application.py @@ -22,11 +22,12 @@ """ from traits.api import Event, Supports + from envisage.api import Application class GUIApplication(Application): - """ The entry point for an Envisage GUI application. + """The entry point for an Envisage GUI application. This class handles the life-cycle of a Pyface GUI. Plugins can display windows via mechinisms such as edit_traits(). @@ -57,7 +58,7 @@ class GUIApplication(Application): ########################################################################### def run(self): - """ Run the application. + """Run the application. Returns ------- diff --git a/envisage/ui/tasks/action/exit_action.py b/envisage/ui/tasks/action/exit_action.py index 4d35e16c5..af9af68c0 100644 --- a/envisage/ui/tasks/action/exit_action.py +++ b/envisage/ui/tasks/action/exit_action.py @@ -12,8 +12,7 @@ class ExitAction(Action): - """ An action that exits the application. - """ + """An action that exits the application.""" #### 'Action' interface ################################################### diff --git a/envisage/ui/tasks/action/preferences_action.py b/envisage/ui/tasks/action/preferences_action.py index b9771bc46..2955af976 100644 --- a/envisage/ui/tasks/action/preferences_action.py +++ b/envisage/ui/tasks/action/preferences_action.py @@ -12,8 +12,7 @@ class PreferencesAction(Action): - """ An action that displays the preferences dialog. - """ + """An action that displays the preferences dialog.""" #### 'Action' interface ################################################### @@ -42,8 +41,7 @@ def perform(self, event): class PreferencesGroup(Group): - """ A group that contains the preferences action. - """ + """A group that contains the preferences action.""" #### 'Action' interface ################################################### diff --git a/envisage/ui/tasks/action/task_window_launch_group.py b/envisage/ui/tasks/action/task_window_launch_group.py index b178d84b6..f78652633 100644 --- a/envisage/ui/tasks/action/task_window_launch_group.py +++ b/envisage/ui/tasks/action/task_window_launch_group.py @@ -10,14 +10,13 @@ # Enthought library imports. from pyface.action.api import ActionItem, Group -from pyface.tasks.api import TaskWindowLayout from pyface.tasks.action.api import TaskAction +from pyface.tasks.api import TaskWindowLayout from traits.api import List, observe, Str class TaskWindowLaunchAction(TaskAction): - """ An Action that creates a task window with a single task. - """ + """An Action that creates a task window with a single task.""" #### 'TaskWindowLaunchAction' interface ################################### @@ -40,8 +39,7 @@ def perform(self, event): @observe("task") def _update_name(self, event): - """ Name the action (unless a name has already been assigned). - """ + """Name the action (unless a name has already been assigned).""" task = event.new if task and not self.name: name = "" @@ -53,8 +51,7 @@ def _update_name(self, event): class TaskWindowLaunchGroup(Group): - """ A Group for creating task windows with a single task. - """ + """A Group for creating task windows with a single task.""" #### 'Group' interface #################################################### diff --git a/envisage/ui/tasks/action/task_window_toggle_group.py b/envisage/ui/tasks/action/task_window_toggle_group.py index 6e499a9fd..9978ae002 100644 --- a/envisage/ui/tasks/action/task_window_toggle_group.py +++ b/envisage/ui/tasks/action/task_window_toggle_group.py @@ -9,12 +9,11 @@ # Thanks for using Enthought open source! # Enthought library imports. from pyface.action.api import Action, ActionItem, Group -from traits.api import Any, Instance, List, Property, Str, on_trait_change +from traits.api import Any, Instance, List, on_trait_change, Property, Str class TaskWindowToggleAction(Action): - """ An action for activating an application window. - """ + """An action for activating an application window.""" #### 'Action' interface ################################################### @@ -53,7 +52,8 @@ def _window_deactivated(self): class TaskWindowToggleGroup(Group): - """ A Group for toggling the activation state of an application's windows. + """ + A Group for toggling the activation state of an application's windows. """ #### 'Group' interface #################################################### @@ -76,8 +76,7 @@ class TaskWindowToggleGroup(Group): ########################################################################### def destroy(self): - """ Called when the group is no longer required. - """ + """Called when the group is no longer required.""" super().destroy() if self.application: self.application.on_trait_change( diff --git a/envisage/ui/tasks/preferences_category.py b/envisage/ui/tasks/preferences_category.py index 35a6262df..7b1531550 100644 --- a/envisage/ui/tasks/preferences_category.py +++ b/envisage/ui/tasks/preferences_category.py @@ -12,8 +12,7 @@ class PreferencesCategory(HasTraits): - """ The description for a container of PreferencesPanes. - """ + """The description for a container of PreferencesPanes.""" # The globally unique identifier for the category. id = Str @@ -32,6 +31,5 @@ class PreferencesCategory(HasTraits): ########################################################################### def _name_default(self): - """ By default, use the ID for the name. - """ + """By default, use the ID for the name.""" return self.id diff --git a/envisage/ui/tasks/preferences_dialog.py b/envisage/ui/tasks/preferences_dialog.py index 9095cae34..96c0e9979 100644 --- a/envisage/ui/tasks/preferences_dialog.py +++ b/envisage/ui/tasks/preferences_dialog.py @@ -8,9 +8,9 @@ # # Thanks for using Enthought open source! # Enthought library imports. -from traits.api import Bool, HasTraits, Instance, List, Str, on_trait_change -from traitsui.api import Item, Handler, ListEditor, View from pyface.tasks.topological_sort import before_after_sort +from traits.api import Bool, HasTraits, Instance, List, on_trait_change, Str +from traitsui.api import Handler, Item, ListEditor, View # Local imports. from .preferences_category import PreferencesCategory @@ -18,8 +18,7 @@ class PreferencesTab(HasTraits): - """ An object used internally by PreferencesDialog. - """ + """An object used internally by PreferencesDialog.""" name = Str panes = List(PreferencesPane) @@ -36,8 +35,7 @@ class PreferencesTab(HasTraits): class PreferencesDialog(Handler): - """ A dialog for editing preferences. - """ + """A dialog for editing preferences.""" #### 'PreferencesDialog' interface ######################################## @@ -63,7 +61,8 @@ class PreferencesDialog(Handler): ########################################################################### def select_pane(self, pane_id): - """ Find and activate the notebook tab that contains the given pane id. + """ + Find and activate the notebook tab that contains the given pane id. """ for tab in self._tabs: for pane in tab.panes: @@ -76,14 +75,13 @@ def select_pane(self, pane_id): ########################################################################### def trait_context(self): - """ Returns the default context to use for editing or configuring - traits. + """Returns the default context to use for editing or configuring + traits. """ return {"object": self, "handler": self} def traits_view(self): - """ Build the dynamic dialog view. - """ + """Build the dynamic dialog view.""" buttons = ["OK", "Cancel"] if self.show_apply: buttons = ["Apply"] + buttons @@ -114,14 +112,14 @@ def traits_view(self): ########################################################################### def apply(self, info=None): - """ Handles the Apply button being clicked. - """ + """Handles the Apply button being clicked.""" for tab in self._tabs: for pane in tab.panes: pane.apply() def close(self, info, is_ok): - """ Handles the user attempting to close a dialog-based user interface. + """ + Handles the user attempting to close a dialog-based user interface. """ if is_ok: self.apply() diff --git a/envisage/ui/tasks/preferences_pane.py b/envisage/ui/tasks/preferences_pane.py index e7aa55dc7..bfa89aa84 100644 --- a/envisage/ui/tasks/preferences_pane.py +++ b/envisage/ui/tasks/preferences_pane.py @@ -14,8 +14,7 @@ class PreferencesPane(Controller): - """ A panel for configuring application preferences. - """ + """A panel for configuring application preferences.""" #### 'Controller' interface ############################################### @@ -55,8 +54,8 @@ class PreferencesPane(Controller): ########################################################################### def trait_context(self): - """ Re-implemented to use a copy of the model that is not connected to - the preferences node. + """Re-implemented to use a copy of the model that is not connected to + the preferences node. """ if self.model is None: if self.model_factory is not None: @@ -74,15 +73,15 @@ def trait_context(self): ########################################################################### def apply(self, info=None): - """ Handles the Apply button being clicked. - """ + """Handles the Apply button being clicked.""" trait_names = list( filter(self._model._is_preference_trait, self._model.trait_names()) ) self.model.copy_traits(self._model, trait_names) def close(self, info, is_ok): - """ Handles the user attempting to close a dialog-based user interface. + """ + Handles the user attempting to close a dialog-based user interface. """ if is_ok: self.apply() diff --git a/envisage/ui/tasks/task_extension.py b/envisage/ui/tasks/task_extension.py index 17d5442f7..6cf4310d6 100644 --- a/envisage/ui/tasks/task_extension.py +++ b/envisage/ui/tasks/task_extension.py @@ -9,12 +9,11 @@ # Thanks for using Enthought open source! # Enthought library imports. from pyface.tasks.action.api import SchemaAddition -from traits.api import HasStrictTraits, Callable, List, Str +from traits.api import Callable, HasStrictTraits, List, Str class TaskExtension(HasStrictTraits): - """ A bundle of items for extending a Task. - """ + """A bundle of items for extending a Task.""" #: The ID of the task to extend. If the ID is omitted, the extension #: applies to all tasks. diff --git a/envisage/ui/tasks/task_factory.py b/envisage/ui/tasks/task_factory.py index 3d9c13604..42b5a666f 100644 --- a/envisage/ui/tasks/task_factory.py +++ b/envisage/ui/tasks/task_factory.py @@ -12,8 +12,7 @@ class TaskFactory(HasTraits): - """ A factory for creating a Task with some additional metadata. - """ + """A factory for creating a Task with some additional metadata.""" #: The task factory's unique identifier. This ID is assigned to all tasks #: created by the factory. @@ -30,15 +29,14 @@ class TaskFactory(HasTraits): factory = Callable def create(self, **traits): - """ Creates the Task. + """Creates the Task. The default implementation simply calls the 'factory' attribute. """ return self.factory(**traits) def create_with_extensions(self, extensions, **traits): - """ Creates the Task using the specified TaskExtensions. - """ + """Creates the Task using the specified TaskExtensions.""" task = self.create(**traits) for extension in extensions: task.extra_actions.extend(extension.actions) diff --git a/envisage/ui/tasks/task_window.py b/envisage/ui/tasks/task_window.py index faf18f41c..b132d57b7 100644 --- a/envisage/ui/tasks/task_window.py +++ b/envisage/ui/tasks/task_window.py @@ -15,8 +15,7 @@ class TaskWindow(PyfaceTaskWindow): - """ A TaskWindow for use with the Envisage Tasks plugin. - """ + """A TaskWindow for use with the Envisage Tasks plugin.""" #: The application that created and is managing this window. application = Instance("envisage.ui.tasks.api.TasksApplication") @@ -34,8 +33,8 @@ class TaskWindow(PyfaceTaskWindow): ########################################################################### def _get_title(self): - """ If the application has a name, add it to the title. Otherwise, - behave like the base class. + """If the application has a name, add it to the title. Otherwise, + behave like the base class. """ if self._title or self.active_task is None: return self._title @@ -47,8 +46,7 @@ def _get_title(self): return title def _get_icon(self): - """If we have an icon return it, else delegate to the application. - """ + """If we have an icon return it, else delegate to the application.""" if self._icon is not None: return self._icon elif self.application is not None: @@ -57,6 +55,5 @@ def _get_icon(self): return None def _set_icon(self, icon): - """Explicitly set the icon to use. None is allowed. - """ + """Explicitly set the icon to use. None is allowed.""" self._icon = icon diff --git a/envisage/ui/tasks/task_window_event.py b/envisage/ui/tasks/task_window_event.py index dd500558b..90603c7b7 100644 --- a/envisage/ui/tasks/task_window_event.py +++ b/envisage/ui/tasks/task_window_event.py @@ -15,15 +15,13 @@ class TaskWindowEvent(HasTraits): - """ A task window lifecycle event. - """ + """A task window lifecycle event.""" #: The window that the event occurred on. window = Instance(TaskWindow) class VetoableTaskWindowEvent(TaskWindowEvent, Vetoable): - """ A vetoable task window lifecycle event. - """ + """A vetoable task window lifecycle event.""" pass diff --git a/envisage/ui/tasks/tasks_application.py b/envisage/ui/tasks/tasks_application.py index cb9d6ca99..40eef55df 100644 --- a/envisage/ui/tasks/tasks_application.py +++ b/envisage/ui/tasks/tasks_application.py @@ -9,11 +9,9 @@ # Thanks for using Enthought open source! # Standard library imports. import logging -import pickle import os.path +import pickle -# Enthought library imports. -from envisage.api import Application, ExtensionPoint from traits.api import ( Bool, Callable, @@ -28,6 +26,8 @@ ) from traits.etsconfig.api import ETSConfig +# Enthought library imports. +from envisage.api import Application, ExtensionPoint # Logging. logger = logging.getLogger(__name__) @@ -157,7 +157,7 @@ class TasksApplication(Application): ########################################################################### def run(self): - """ Run the application. + """Run the application. Returns ------- @@ -186,7 +186,7 @@ def run(self): ########################################################################### def create_task(self, id): - """ Creates the Task with the specified ID. + """Creates the Task with the specified ID. Returns ------- @@ -234,9 +234,10 @@ def create_window(self, layout=None, restore=True, **traits): The new TaskWindow. """ - from .task_window_event import TaskWindowEvent from pyface.tasks.task_window_layout import TaskWindowLayout + from .task_window_event import TaskWindowEvent + window = self.window_factory(application=self, **traits) # Listen for the window events. @@ -318,8 +319,8 @@ def exit(self, force=False): ########################################################################### def _create_windows(self): - """ Called at startup to create TaskWindows from the default or saved - application layout. + """Called at startup to create TaskWindows from the default or saved + application layout. """ # Build a list of TaskWindowLayouts. self._load_state() @@ -355,23 +356,21 @@ def _create_windows(self): window.open() def _get_task_factory(self, id): - """ Returns the TaskFactory with the specified ID, or None. - """ + """Returns the TaskFactory with the specified ID, or None.""" for factory in self.task_factories: if factory.id == id: return factory return None def _prepare_exit(self): - """ Called immediately before the extant windows are destroyed and the - GUI event loop is terminated. + """Called immediately before the extant windows are destroyed and the + GUI event loop is terminated. """ self.application_exiting = self self._save_state() def _load_state(self): - """ Loads saved application state, if possible. - """ + """Loads saved application state, if possible.""" state = TasksApplicationState() filename = os.path.join(self.state_location, self.state_filename) if os.path.exists(filename): @@ -400,8 +399,7 @@ def _load_state(self): self._state = state def _restore_layout_from_state(self, layout): - """ Restores an equivalent layout from saved application state. - """ + """Restores an equivalent layout from saved application state.""" # First, see if a window layout matches exactly. match = self._state.get_equivalent_window_layout(layout) if match: @@ -423,8 +421,7 @@ def _restore_layout_from_state(self, layout): return layout def _save_state(self): - """ Saves the application state. - """ + """Saves the application state.""" # Grab the current window layouts. window_layouts = [w.get_window_layout() for w in self.windows] self._state.previous_window_layouts = window_layouts @@ -442,8 +439,7 @@ def _save_state(self): logger.debug("Application state successfully saved") def _initialize_application_home(self): - """ Initialize the application directories. - """ + """Initialize the application directories.""" # Extend the base class method to ensure the state directory exists. super()._initialize_application_home() @@ -535,8 +531,8 @@ def _on_window_closed(self, window, trait_name, event): class TasksApplicationState(HasStrictTraits): - """ A class used internally by TasksApplication for saving and restoring - application state. + """A class used internally by TasksApplication for saving and restoring + application state. """ # TaskWindowLayouts for the windows extant at application @@ -557,16 +553,14 @@ class TasksApplicationState(HasStrictTraits): version = Int(1) def get_equivalent_window_layout(self, window_layout): - """ Gets an equivalent TaskWindowLayout, if there is one. - """ + """Gets an equivalent TaskWindowLayout, if there is one.""" for layout in self.window_layouts: if layout.is_equivalent_to(window_layout): return layout return None def get_task_layout(self, task_id): - """ Gets a TaskLayout with the specified ID, there is one. - """ + """Gets a TaskLayout with the specified ID, there is one.""" for window_layout in self.window_layouts: for layout in window_layout.items: if layout.id == task_id: @@ -574,8 +568,7 @@ def get_task_layout(self, task_id): return None def push_window_layout(self, window_layout): - """ Merge a TaskWindowLayout into the accumulated list. - """ + """Merge a TaskWindowLayout into the accumulated list.""" self.window_layouts = [ layout for layout in self.window_layouts diff --git a/envisage/ui/tasks/tasks_plugin.py b/envisage/ui/tasks/tasks_plugin.py index b128ce668..68720cd66 100644 --- a/envisage/ui/tasks/tasks_plugin.py +++ b/envisage/ui/tasks/tasks_plugin.py @@ -8,9 +8,10 @@ # # Thanks for using Enthought open source! # Enthought library imports. -from envisage.api import ExtensionPoint, Plugin, ServiceOffer from traits.api import Callable, Instance, List +from envisage.api import ExtensionPoint, Plugin, ServiceOffer + # Local imports. from .preferences_category import PreferencesCategory @@ -19,7 +20,7 @@ class TasksPlugin(Plugin): - """ The Envisage Tasks plugin. + """The Envisage Tasks plugin. The Tasks plugin uses Pyface Tasks to provide an extensible framework for building user interfaces. For more information, see the Tasks User Manual. @@ -126,10 +127,11 @@ def _my_service_offers_default(self): my_task_extensions = List(contributes_to=TASK_EXTENSIONS) def _my_task_extensions_default(self): + from pyface.tasks.action.api import DockPaneToggleGroup, SchemaAddition + from .action.exit_action import ExitAction from .action.preferences_action import PreferencesGroup from .task_extension import TaskExtension - from pyface.tasks.action.api import DockPaneToggleGroup, SchemaAddition actions = [ SchemaAddition(id="Exit", factory=ExitAction, path="MenuBar/File"), @@ -150,8 +152,7 @@ def _my_task_extensions_default(self): ########################################################################### def _create_preferences_dialog_service(self): - """ Factory method for preferences dialog service. - """ + """Factory method for preferences dialog service.""" from .preferences_dialog import PreferencesDialog dialog = PreferencesDialog(application=self.application) diff --git a/envisage/ui/tasks/tests/data/create_pickles.py b/envisage/ui/tasks/tests/data/create_pickles.py index 7cc471777..89cd62682 100644 --- a/envisage/ui/tasks/tests/data/create_pickles.py +++ b/envisage/ui/tasks/tests/data/create_pickles.py @@ -19,9 +19,10 @@ import pathlib import pickle -from envisage.ui.tasks.api import TasksApplicationState from pyface.tasks.api import TaskWindowLayout +from envisage.ui.tasks.api import TasksApplicationState + state = TasksApplicationState( version=1, window_layouts=[], diff --git a/envisage/ui/tasks/tests/test_tasks_application.py b/envisage/ui/tasks/tests/test_tasks_application.py index 8062fc0ae..73a59a685 100644 --- a/envisage/ui/tasks/tests/test_tasks_application.py +++ b/envisage/ui/tasks/tests/test_tasks_application.py @@ -16,6 +16,7 @@ import unittest import pkg_resources + from pyface.gui import GUI from pyface.i_gui import IGUI from traits.api import Event, HasTraits, provides @@ -100,7 +101,8 @@ def test_layout_save_with_protocol_3(self): # Create application, and set it up to exit as soon as it's launched. app = TasksApplication( - state_location=state_location, layout_save_protocol=3, + state_location=state_location, + layout_save_protocol=3, ) app.on_trait_change(app.exit, "application_initialized") @@ -174,7 +176,8 @@ def test_layout_load_pickle_protocol_3(self): # Use a non-standard filename, to exercise that machinery. app = TasksApplication( - state_location=state_location, state_filename="fancy_state.pkl", + state_location=state_location, + state_filename="fancy_state.pkl", ) app.on_trait_change(app.exit, "application_initialized") app.run() diff --git a/envisage/ui/workbench/action/about_action.py b/envisage/ui/workbench/action/about_action.py index 34c411c2c..21d03a385 100644 --- a/envisage/ui/workbench/action/about_action.py +++ b/envisage/ui/workbench/action/about_action.py @@ -15,7 +15,7 @@ class AboutAction(Action): - """ An action that shows the 'About' dialog. """ + """An action that shows the 'About' dialog.""" #### 'Action' interface ################################################### @@ -33,6 +33,6 @@ class AboutAction(Action): ########################################################################### def perform(self, event): - """ Perform the action. """ + """Perform the action.""" self.window.application.about() diff --git a/envisage/ui/workbench/action/edit_preferences_action.py b/envisage/ui/workbench/action/edit_preferences_action.py index dc455d8f7..07ba580c8 100644 --- a/envisage/ui/workbench/action/edit_preferences_action.py +++ b/envisage/ui/workbench/action/edit_preferences_action.py @@ -10,13 +10,14 @@ """ An action that displays the preferences dialog. """ +from pyface.action.api import Action + # Enthought library imports. from pyface.api import ImageResource -from pyface.action.api import Action class EditPreferencesAction(Action): - """ An action that displays the preferences dialog. """ + """An action that displays the preferences dialog.""" #### 'Action' interface ################################################### @@ -37,7 +38,7 @@ class EditPreferencesAction(Action): ########################################################################### def perform(self, event): - """ Performs the action. """ + """Performs the action.""" from apptools.preferences.ui.api import PreferencesManager diff --git a/envisage/ui/workbench/action/exit_action.py b/envisage/ui/workbench/action/exit_action.py index c64224664..cc1ea1490 100644 --- a/envisage/ui/workbench/action/exit_action.py +++ b/envisage/ui/workbench/action/exit_action.py @@ -10,13 +10,14 @@ """ An action that exits the workbench. """ +from pyface.action.api import Action + # Enthought library imports. from pyface.api import ImageResource -from pyface.action.api import Action class ExitAction(Action): - """ An action that exits the workbench. """ + """An action that exits the workbench.""" #### 'Action' interface ################################################### @@ -37,6 +38,6 @@ class ExitAction(Action): ########################################################################### def perform(self, event): - """ Perform the action. """ + """Perform the action.""" self.window.application.exit() diff --git a/envisage/ui/workbench/default_action_set.py b/envisage/ui/workbench/default_action_set.py index 89795b433..444724efe 100644 --- a/envisage/ui/workbench/default_action_set.py +++ b/envisage/ui/workbench/default_action_set.py @@ -13,13 +13,12 @@ # Enthought library imports. from envisage.ui.action.api import Action, ActionSet, Group, Menu - # This module's package. PKG = ".".join(__name__.split(".")[:-1]) class DefaultActionSet(ActionSet): - """ The default workbench action set. """ + """The default workbench action set.""" menus = [ Menu( @@ -29,7 +28,7 @@ class DefaultActionSet(ActionSet): Group(id="OpenGroup"), Group(id="SaveGroup"), Group(id="ImportGroup"), - Group(id="ExitGroup") + Group(id="ExitGroup"), ], ), Menu( @@ -37,13 +36,11 @@ class DefaultActionSet(ActionSet): class_name="pyface.workbench.action.api:ViewMenuManager", ), Menu( - name="&Tools", path="MenuBar", - groups=[Group(id="PreferencesGroup")] - ), - Menu( - name="&Help", path="MenuBar", - groups=[Group(id="AboutGroup")] + name="&Tools", + path="MenuBar", + groups=[Group(id="PreferencesGroup")], ), + Menu(name="&Help", path="MenuBar", groups=[Group(id="AboutGroup")]), ] actions = [ diff --git a/envisage/ui/workbench/workbench.py b/envisage/ui/workbench/workbench.py index 68b877e5f..e7ac23f84 100644 --- a/envisage/ui/workbench/workbench.py +++ b/envisage/ui/workbench/workbench.py @@ -12,18 +12,18 @@ # Enthought library imports. import pyface.workbench.api as pyface - -from envisage.api import IApplication from pyface.api import YES from traits.api import Delegate, Instance +from envisage.api import IApplication + # Local imports. from .workbench_preferences import WorkbenchPreferences from .workbench_window import WorkbenchWindow class Workbench(pyface.Workbench): - """ The Envisage workbench. + """The Envisage workbench. There is (usually) exactly *one* workbench per application. The workbench can create any number of workbench windows. @@ -53,7 +53,7 @@ class Workbench(pyface.Workbench): ########################################################################### def _exiting_changed(self, event): - """ Called when the workbench is exiting. """ + """Called when the workbench is exiting.""" if self.prompt_on_exit: answer = self.active_window.confirm( diff --git a/envisage/ui/workbench/workbench_action_manager_builder.py b/envisage/ui/workbench/workbench_action_manager_builder.py index 3efc2462f..d8f0dd310 100644 --- a/envisage/ui/workbench/workbench_action_manager_builder.py +++ b/envisage/ui/workbench/workbench_action_manager_builder.py @@ -13,17 +13,17 @@ # Standard library imports. import weakref -# Enthought library imports. -from envisage.ui.action.api import AbstractActionManagerBuilder from pyface.action.api import Action, Group, MenuManager -from pyface.workbench.action.api import MenuBarManager -from pyface.workbench.action.api import ToolBarManager +from pyface.workbench.action.api import MenuBarManager, ToolBarManager from traits.api import Any, Instance +# Enthought library imports. +from envisage.ui.action.api import AbstractActionManagerBuilder -class WorkbenchActionManagerBuilder(AbstractActionManagerBuilder): - """ The action manager builder used to build the workbench menu/tool bars. +class WorkbenchActionManagerBuilder(AbstractActionManagerBuilder): + """ + The action manager builder used to build the workbench menu/tool bars. """ #### 'WorkbenchActionManagerBuilder' interface ############################ @@ -41,7 +41,7 @@ class WorkbenchActionManagerBuilder(AbstractActionManagerBuilder): ########################################################################### def _create_action(self, definition): - """ Create an action implementation from an action definition. """ + """Create an action implementation from an action definition.""" traits = {"window": self.window} @@ -69,7 +69,7 @@ def _create_action(self, definition): return action def _create_group(self, definition): - """ Create a group implementation from a group definition. """ + """Create a group implementation from a group definition.""" traits = {} @@ -93,7 +93,7 @@ def _create_group(self, definition): return group def _create_menu_manager(self, definition): - """ Create a menu manager implementation from a menu definition. """ + """Create a menu manager implementation from a menu definition.""" # fixme: 'window' is not actually a trait on 'MenuManager'! We set # it here to allow the 'View' menu to be created. However, it seems @@ -129,12 +129,12 @@ def _create_menu_manager(self, definition): return menu_manager def _create_menu_bar_manager(self): - """ Create a menu bar manager from the builder's action sets. """ + """Create a menu bar manager from the builder's action sets.""" return MenuBarManager(window=self.window) def _create_tool_bar_manager(self, definition): - """ Create a tool bar manager implementation from a definition. """ + """Create a tool bar manager implementation from a definition.""" traits = {"window": self.window, "show_tool_names": False} @@ -173,11 +173,11 @@ def _create_tool_bar_manager(self, definition): ########################################################################### def __actions_default(self): - """ Trait initializer. """ + """Trait initializer.""" return weakref.WeakValueDictionary() def _import_symbol(self, symbol_path): - """ Import a symbol. """ + """Import a symbol.""" return self.window.application.import_symbol(symbol_path) diff --git a/envisage/ui/workbench/workbench_action_set.py b/envisage/ui/workbench/workbench_action_set.py index 91880aeb7..43e2fc6cd 100644 --- a/envisage/ui/workbench/workbench_action_set.py +++ b/envisage/ui/workbench/workbench_action_set.py @@ -10,13 +10,14 @@ """ An action set in a workbench window. """ +from traits.api import Instance, List, Str + # Enthought library imports. from envisage.ui.action.api import ActionSet -from traits.api import Instance, List, Str class WorkbenchActionSet(ActionSet): - """ An action set in a workbench window. + """An action set in a workbench window. This class adds a 'window' trait which is the workbench window that the action set is in. The trait is set by the framework when the action set is @@ -62,14 +63,14 @@ class WorkbenchActionSet(ActionSet): ########################################################################### def _enabled_changed(self, trait_name, old, new): - """ Static trait change handler. """ + """Static trait change handler.""" if self.window is not None: self._update_tool_bars(self.window, "enabled", new) self._update_actions(self.window, "enabled", new) def _visible_changed(self, trait_name, old, new): - """ Static trait change handler. """ + """Static trait change handler.""" if self.window is not None: self._update_tool_bars(self.window, "visible", new) @@ -80,7 +81,7 @@ def _visible_changed(self, trait_name, old, new): ########################################################################### def initialize(self): - """ Called when the action set has been added to a window. + """Called when the action set has been added to a window. Use this method to hook up any listeners that you need to control the enabled and/or visible state of the action set. @@ -105,7 +106,7 @@ def initialize(self): #### Trait change handlers ################################################ def _window_changed(self): - """ Static trait change handler. """ + """Static trait change handler.""" # fixme: We put the code into an 'initialize' method because it seems # easier to explain that we expect it to be overridden. It seems a bit @@ -115,7 +116,7 @@ def _window_changed(self): #### Methods ############################################################## def _refresh(self): - """ Refresh the enabled/visible state of the action set. """ + """Refresh the enabled/visible state of the action set.""" window = self.window @@ -150,10 +151,10 @@ def _refresh(self): ) def _update_actions(self, window, trait_name, value): - """ Update the state of the tool bars in the action set. """ + """Update the state of the tool bars in the action set.""" def visitor(item): - """ Called when we visit each item in an action manager. """ + """Called when we visit each item in an action manager.""" # fixme: The 'additions' group gets created by default and hence # has no '_action_set_' attribute. This smells because of the fact @@ -172,7 +173,7 @@ def visitor(item): tool_bar_manager.walk(visitor) def _update_tool_bars(self, window, trait_name, value): - """ Update the state of the tool bars in the action set. """ + """Update the state of the tool bars in the action set.""" for tool_bar_manager in window.tool_bar_managers: if tool_bar_manager._action_set_ is self: diff --git a/envisage/ui/workbench/workbench_application.py b/envisage/ui/workbench/workbench_application.py index f56b47979..3ef0b44b6 100644 --- a/envisage/ui/workbench/workbench_application.py +++ b/envisage/ui/workbench/workbench_application.py @@ -13,23 +13,22 @@ # Standard library imports. import logging -# Enthought library imports. -from envisage.api import Application -from pyface.api import AboutDialog, Dialog, GUI, ImageResource -from pyface.api import SplashScreen +from pyface.api import AboutDialog, Dialog, GUI, ImageResource, SplashScreen from pyface.workbench.api import IWorkbench from traits.api import Callable, Instance, Str, Tuple +# Enthought library imports. +from envisage.api import Application + # Local imports. from .workbench import Workbench - # Logging. logger = logging.getLogger(__name__) class WorkbenchApplication(Application): - """ The entry point for an Envisage Workbench application. + """The entry point for an Envisage Workbench application. i.e. a GUI application whose user interface is provided by the workbench plugin. @@ -80,7 +79,7 @@ class WorkbenchApplication(Application): ########################################################################### def run(self): - """ Run the application. + """Run the application. This does the following (so you don't have to ;^):- @@ -120,24 +119,24 @@ def run(self): #### Initializers ######################################################### def _about_dialog_default(self): - """ Trait initializer. """ + """Trait initializer.""" return AboutDialog(image=ImageResource("about")) def _gui_default(self): - """ Trait initializer. """ + """Trait initializer.""" return GUI(splash_screen=self.splash_screen) def _workbench_default(self): - """ Trait initializer. """ + """Trait initializer.""" return self.create_workbench() #### Methods ############################################################## def about(self): - """ Display the about dialog. """ + """Display the about dialog.""" # fixme: We really need to create a new 'about dialog' every time so # that it can have the active window as its parent. @@ -146,14 +145,14 @@ def about(self): # fixme: Is this needed on the public API? Why can't we just do this in # the default initializer (_workbench_default)? def create_workbench(self): - """ Create the workbench. """ + """Create the workbench.""" logger.debug("workbench factory %s", self.workbench_factory) return self.workbench_factory(application=self) def exit(self): - """ Exit the application. + """Exit the application. This closes all open windows and hence exits the GUI event loop. @@ -166,7 +165,7 @@ def exit(self): ########################################################################### def _on_workbench_exited(self): - """ Dynamic trait change handler. """ + """Dynamic trait change handler.""" # We don't invoke 'stop' directly because:- # diff --git a/envisage/ui/workbench/workbench_editor_manager.py b/envisage/ui/workbench/workbench_editor_manager.py index 603676b42..ee81276e5 100644 --- a/envisage/ui/workbench/workbench_editor_manager.py +++ b/envisage/ui/workbench/workbench_editor_manager.py @@ -14,14 +14,14 @@ class WorkbenchEditorManager(EditorManager): - """ An editor manager that uses contributed editors. """ + """An editor manager that uses contributed editors.""" ########################################################################### # 'IEditorManager' interface. ########################################################################### def create_editor(self, window, obj, kind): - """ Create an editor for an object. + """Create an editor for an object. For now, the 'kind' is actually a factory that produces editors. It should be a callable with the following signature:: @@ -43,7 +43,7 @@ def create_editor(self, window, obj, kind): ########################################################################### def _is_editing(self, editor, obj, kind): - """ Return True if the editor is editing the object. """ + """Return True if the editor is editing the object.""" if kind is None: kind = TraitsUIEditor diff --git a/envisage/ui/workbench/workbench_plugin.py b/envisage/ui/workbench/workbench_plugin.py index c5f2d654a..4bc3a3571 100644 --- a/envisage/ui/workbench/workbench_plugin.py +++ b/envisage/ui/workbench/workbench_plugin.py @@ -10,17 +10,17 @@ """ The Envisage workbench plugin. """ -# Enthought library imports. -from envisage.api import ExtensionPoint, Plugin, ServiceOffer from traits.api import Callable, List +# Enthought library imports. +from envisage.api import ExtensionPoint, Plugin, ServiceOffer # This module's package. PKG = ".".join(__name__.split(".")[:-1]) class WorkbenchPlugin(Plugin): - """ The Envisage workbench plugin. + """The Envisage workbench plugin. The workbench plugin uses the Pyface workbench to provide the basis of an IDE-like user interface. The interface is made up of perspectives, views @@ -180,7 +180,7 @@ def foo_view_factory(**traits): my_action_sets = List(contributes_to=ACTION_SETS) def _my_action_sets_default(self): - """ Trait initializer. """ + """Trait initializer.""" from .default_action_set import DefaultActionSet @@ -189,14 +189,14 @@ def _my_action_sets_default(self): my_preferences = List(contributes_to=PREFERENCES) def _my_preferences_default(self): - """ Trait initializer. """ + """Trait initializer.""" return ["pkgfile://envisage.ui.workbench/preferences.ini"] my_preferences_pages = List(contributes_to=PREFERENCES_PAGES) def _my_preferences_pages_default(self): - """ Trait initializer. """ + """Trait initializer.""" from .workbench_preferences_page import WorkbenchPreferencesPage @@ -205,7 +205,7 @@ def _my_preferences_pages_default(self): my_service_offers = List(contributes_to=SERVICE_OFFERS) def _my_service_offers_default(self): - """ Trait initializer. """ + """Trait initializer.""" preferences_manager_service_offer = ServiceOffer( protocol="apptools.preferences.ui.preferences_manager" @@ -225,7 +225,7 @@ def _my_service_offers_default(self): ########################################################################### def _create_preferences_manager_service(self, **properties): - """ Factory method for the preferences manager service. """ + """Factory method for the preferences manager service.""" from apptools.preferences.ui.api import PreferencesManager @@ -236,7 +236,7 @@ def _create_preferences_manager_service(self, **properties): return preferences_manager def _create_workbench_service(self, **properties): - """ Factory method for the workbench service. """ + """Factory method for the workbench service.""" # We don't actually create the workbench here, we just return a # reference to it. diff --git a/envisage/ui/workbench/workbench_preferences.py b/envisage/ui/workbench/workbench_preferences.py index 1d9b9be91..06ddce586 100644 --- a/envisage/ui/workbench/workbench_preferences.py +++ b/envisage/ui/workbench/workbench_preferences.py @@ -16,7 +16,7 @@ class WorkbenchPreferences(PreferencesHelper): - """ Helper for the workbench preferences. """ + """Helper for the workbench preferences.""" #### 'PreferencesHelper' interface ######################################## diff --git a/envisage/ui/workbench/workbench_preferences_page.py b/envisage/ui/workbench/workbench_preferences_page.py index c945e0044..8288f6819 100644 --- a/envisage/ui/workbench/workbench_preferences_page.py +++ b/envisage/ui/workbench/workbench_preferences_page.py @@ -17,7 +17,7 @@ class WorkbenchPreferencesPage(PreferencesPage): - """ The main preferences page for the workbench. """ + """The main preferences page for the workbench.""" #### 'PreferencesPage' interface ########################################## diff --git a/envisage/ui/workbench/workbench_window.py b/envisage/ui/workbench/workbench_window.py index 4ff8a509f..225a1df60 100644 --- a/envisage/ui/workbench/workbench_window.py +++ b/envisage/ui/workbench/workbench_window.py @@ -15,26 +15,29 @@ # Enthought library imports. import pyface.workbench.api as pyface - -from envisage.api import IExtensionPointUser, IExtensionRegistry -from envisage.api import IServiceRegistry -from envisage.api import ExtensionPoint, ServiceRegistry -from envisage.ui.action.api import ActionSet from pyface.action.api import StatusBarManager from traits.api import Delegate, Instance, List, Property, provides +from envisage.api import ( + ExtensionPoint, + IExtensionPointUser, + IExtensionRegistry, + IServiceRegistry, + ServiceRegistry, +) +from envisage.ui.action.api import ActionSet + # Local imports. from .workbench_action_manager_builder import WorkbenchActionManagerBuilder from .workbench_editor_manager import WorkbenchEditorManager - # Logging. logger = logging.getLogger(__name__) @provides(IServiceRegistry, IExtensionPointUser) class WorkbenchWindow(pyface.WorkbenchWindow): - """ An extensible workbench window. """ + """An extensible workbench window.""" # Extension point Ids. ACTION_SETS = "envisage.ui.workbench.action_sets" @@ -90,7 +93,7 @@ class WorkbenchWindow(pyface.WorkbenchWindow): ########################################################################### def _get_extension_registry(self): - """ Trait property getter. """ + """Trait property getter.""" return self.application @@ -101,29 +104,29 @@ def _get_extension_registry(self): #### Trait initializers ################################################### def _menu_bar_manager_default(self): - """ Trait initializer. """ + """Trait initializer.""" return self._action_manager_builder.create_menu_bar_manager("MenuBar") def _status_bar_manager_default(self): - """ Trait initializer. """ + """Trait initializer.""" return StatusBarManager() def _tool_bar_managers_default(self): - """ Trait initializer. """ + """Trait initializer.""" return self._action_manager_builder.create_tool_bar_managers("ToolBar") #### Trait change handlers ################################################ def _opening_changed(self): - """ Static trait change handler. """ + """Static trait change handler.""" self._service_ids = self._register_service_offers(self._service_offers) def _closed_changed(self): - """ Static trait change handler. """ + """Static trait change handler.""" self._unregister_service_offers(self._service_ids) @@ -134,27 +137,27 @@ def _closed_changed(self): #### Trait initializers ################################################### def _editor_manager_default(self): - """ Trait initializer. """ + """Trait initializer.""" return WorkbenchEditorManager(window=self) def _icon_default(self): - """ Trait initializer. """ + """Trait initializer.""" return self.workbench.application.icon def _perspectives_default(self): - """ Trait initializer. """ + """Trait initializer.""" return [factory() for factory in self._perspectives] def _title_default(self): - """ Trait initializer. """ + """Trait initializer.""" return self.workbench.application.name def _views_default(self): - """ Trait initializer. """ + """Trait initializer.""" return [factory(window=self) for factory in self._views] @@ -163,7 +166,7 @@ def _views_default(self): ########################################################################### def _action_sets_default(self): - """ Trait initializer. """ + """Trait initializer.""" return [factory(window=self) for factory in self._action_sets] @@ -172,7 +175,7 @@ def _action_sets_default(self): ########################################################################### def get_service(self, protocol, query="", minimize="", maximize=""): - """ Return at most one service that matches the specified query. """ + """Return at most one service that matches the specified query.""" service = self.service_registry.get_service( protocol, query, minimize, maximize @@ -181,12 +184,12 @@ def get_service(self, protocol, query="", minimize="", maximize=""): return service def get_service_properties(self, service_id): - """ Return the dictionary of properties associated with a service. """ + """Return the dictionary of properties associated with a service.""" return self.service_registry.get_service_properties(service_id) def get_services(self, protocol, query="", minimize="", maximize=""): - """ Return all services that match the specified query. """ + """Return all services that match the specified query.""" services = self.service_registry.get_services( protocol, query, minimize, maximize @@ -195,7 +198,7 @@ def get_services(self, protocol, query="", minimize="", maximize=""): return services def register_service(self, protocol, obj, properties=None): - """ Register a service. """ + """Register a service.""" service_id = self.service_registry.register_service( protocol, obj, properties @@ -204,12 +207,12 @@ def register_service(self, protocol, obj, properties=None): return service_id def set_service_properties(self, service_id, properties): - """ Set the dictionary of properties associated with a service. """ + """Set the dictionary of properties associated with a service.""" self.service_registry.set_service_properties(service_id, properties) def unregister_service(self, service_id): - """ Unregister a service. """ + """Unregister a service.""" self.service_registry.unregister_service(service_id) @@ -218,7 +221,7 @@ def unregister_service(self, service_id): ########################################################################### def __action_manager_builder_default(self): - """ Trait initializer. """ + """Trait initializer.""" action_manager_builder = WorkbenchActionManagerBuilder( window=self, action_sets=self.action_sets @@ -227,12 +230,12 @@ def __action_manager_builder_default(self): return action_manager_builder def _register_service_offers(self, service_offers): - """ Register all service offers. """ + """Register all service offers.""" return list(map(self._register_service_offer, service_offers)) def _register_service_offer(self, service_offer): - """ Register a service offer. """ + """Register a service offer.""" # Add the window to the service offer properties (this is so that it # is available to the factory when it is called to create the actual @@ -248,7 +251,7 @@ def _register_service_offer(self, service_offer): return service_id def _unregister_service_offers(self, service_ids): - """ Unregister all service offers. """ + """Unregister all service offers.""" # Unregister the services in the reverse order that we registered # them. diff --git a/envisage/unknown_extension.py b/envisage/unknown_extension.py index e49ce0303..f5ee969c6 100644 --- a/envisage/unknown_extension.py +++ b/envisage/unknown_extension.py @@ -11,4 +11,4 @@ class UnknownExtension(Exception): - """ The exception raised when an unknown extension is referenced. """ + """The exception raised when an unknown extension is referenced.""" diff --git a/envisage/unknown_extension_point.py b/envisage/unknown_extension_point.py index 0b5eac9ec..617009a26 100644 --- a/envisage/unknown_extension_point.py +++ b/envisage/unknown_extension_point.py @@ -11,4 +11,4 @@ class UnknownExtensionPoint(Exception): - """ The exception raised when an unknown extension point is referenced. """ + """The exception raised when an unknown extension point is referenced.""" diff --git a/etstool.py b/etstool.py index d7d511643..efd51fc8d 100644 --- a/etstool.py +++ b/etstool.py @@ -106,8 +106,6 @@ "apptools", "coverage", "enthought_sphinx_theme", - "flake8", - "flake8_ets", "pyface", "sphinx", "sphinx_copybutton", @@ -116,7 +114,14 @@ } # Dependencies we install from PyPI -pypi_dependencies = {} +pypi_dependencies = { + # style packages; install from PyPI to make sure that we're compatible + # with the style checks used in the check-style.yml workflow + "black~=23.0", + "flake8", + "flake8-ets", + "isort", +} # Dependencies we install from source for cron tests # Order from packages with the most dependencies to one with the least @@ -187,6 +192,16 @@ def cli(): pass +# Subgroup for checking and fixing style + + +@cli.group() +def style(): + """ + Commands for checking style and applying style fixes. + """ + + @cli.command() @edm_option @runtime_option @@ -195,9 +210,7 @@ def cli(): @editable_option @source_option def install(edm, runtime, toolkit, environment, editable, source): - """ Install project and dependencies into a clean EDM environment. - - """ + """Install project and dependencies into a clean EDM environment.""" parameters = get_parameters(edm, runtime, toolkit, environment) packages = " ".join( dependencies @@ -264,7 +277,7 @@ def install(edm, runtime, toolkit, environment, editable, source): @toolkit_option @environment_option def shell(edm, runtime, toolkit, environment): - """ Create a shell into the EDM development environment + """Create a shell into the EDM development environment (aka 'activate' it). """ @@ -275,17 +288,41 @@ def shell(edm, runtime, toolkit, environment): execute(commands, parameters) -@cli.command() +@style.command(name="check") @edm_option @runtime_option @toolkit_option @environment_option -def flake8(edm, runtime, toolkit, environment): - """ Run a flake8 check in a given environment. +def style_check(edm, runtime, toolkit, environment): + """ + Run style checks. + """ + parameters = get_parameters(edm, runtime, toolkit, environment) + commands = [ + "{edm} run -e {environment} -- python -m black --check --diff .", + "{edm} run -e {environment} -- python -m isort --check --diff .", + "{edm} run -e {environment} -- python -m flake8 .", + ] + execute(commands, parameters) + +@style.command(name="fix") +@edm_option +@runtime_option +@toolkit_option +@environment_option +def style_fix(edm, runtime, toolkit, environment): + """ + Run style fixers. + + This automatically fixes any black or isort failures, but it won't + automatically fix all flake8 errors. """ parameters = get_parameters(edm, runtime, toolkit, environment) - commands = ["{edm} run -e {environment} -- python -m flake8"] + commands = [ + "{edm} run -e {environment} -- python -m black .", + "{edm} run -e {environment} -- python -m isort .", + ] execute(commands, parameters) @@ -295,9 +332,7 @@ def flake8(edm, runtime, toolkit, environment): @toolkit_option @environment_option def test(edm, runtime, toolkit, environment): - """ Run the test suite in a given environment with the specified toolkit. - - """ + """Run the test suite in a given environment with the specified toolkit.""" parameters = get_parameters(edm, runtime, toolkit, environment) environ = dict(PYTHONUNBUFFERED="1") commands = [ @@ -324,9 +359,7 @@ def test(edm, runtime, toolkit, environment): @toolkit_option @environment_option def cleanup(edm, runtime, toolkit, environment): - """ Remove a development environment. - - """ + """Remove a development environment.""" parameters = get_parameters(edm, runtime, toolkit, environment) commands = [ "{edm} environments remove {environment} --purge -y", @@ -341,9 +374,7 @@ def cleanup(edm, runtime, toolkit, environment): @runtime_option @toolkit_option def test_clean(edm, runtime, toolkit): - """ Run tests in a clean environment, cleaning up afterwards - - """ + """Run tests in a clean environment, cleaning up afterwards""" args = ["--toolkit={}".format(toolkit), "--runtime={}".format(runtime)] if edm is not None: args.append("--edm={}".format(edm)) @@ -362,9 +393,7 @@ def test_clean(edm, runtime, toolkit): @environment_option @editable_option def update(edm, runtime, toolkit, environment, editable): - """ Update/Reinstall package into environment. - - """ + """Update/Reinstall package into environment.""" parameters = get_parameters(edm, runtime, toolkit, environment) if editable: install_cmd = ( @@ -385,9 +414,7 @@ def update(edm, runtime, toolkit, environment, editable): @cli.command() @edm_option def test_all(edm): - """ Run test_clean across all supported environment combinations. - - """ + """Run test_clean across all supported environment combinations.""" failed_command = False for runtime, toolkits in supported_combinations.items(): for toolkit in toolkits: @@ -412,7 +439,7 @@ def test_all(edm): @toolkit_option @environment_option def docs(edm, runtime, toolkit, environment): - """ Build HTML documentation. """ + """Build HTML documentation.""" parameters = get_parameters(edm, runtime, toolkit, environment) parameters["docs_source"] = "docs/source" @@ -422,9 +449,10 @@ def docs(edm, runtime, toolkit, environment): # Remove any previously autogenerated API documentation. doc_api_files = os.listdir(docs_source_api) - permanent = ['envisage.api.rst', 'templates'] - previously_autogenerated = \ - [file for file in doc_api_files if file not in permanent] + permanent = ["envisage.api.rst", "templates"] + previously_autogenerated = [ + file for file in doc_api_files if file not in permanent + ] for file in previously_autogenerated: os.remove(os.path.join(docs_source_api, file)) @@ -443,8 +471,9 @@ def docs(edm, runtime, toolkit, environment): # Utility routines + def get_parameters(edm, runtime, toolkit, environment): - """ Set up parameters dictionary for format() substitution """ + """Set up parameters dictionary for format() substitution""" if edm is None: edm = locate_edm() @@ -472,7 +501,7 @@ def get_parameters(edm, runtime, toolkit, environment): @contextmanager def do_in_tempdir(files=(), capture_files=()): - """ Create a temporary directory, cleaning up after done. + """Create a temporary directory, cleaning up after done. Creates the temporary directory, and changes into it. On exit returns to original directory and removes temporary dir. diff --git a/examples/legacy/workbench/AcmeLab/acme/acmelab/acmelab.py b/examples/legacy/workbench/AcmeLab/acme/acmelab/acmelab.py index f6f804116..2eac099fe 100644 --- a/examples/legacy/workbench/AcmeLab/acme/acmelab/acmelab.py +++ b/examples/legacy/workbench/AcmeLab/acme/acmelab/acmelab.py @@ -14,13 +14,14 @@ # Standard library imports. from logging import DEBUG +from pyface.api import AboutDialog, ImageResource, SplashScreen + # Enthought library imports. from envisage.ui.workbench.api import WorkbenchApplication -from pyface.api import AboutDialog, ImageResource, SplashScreen class Acmelab(WorkbenchApplication): - """ The Acme Lab application. """ + """The Acme Lab application.""" #### 'IApplication' interface ############################################# @@ -42,7 +43,7 @@ class Acmelab(WorkbenchApplication): ########################################################################### def _about_dialog_default(self): - """ Trait initializer. """ + """Trait initializer.""" about_dialog = AboutDialog( parent=self.workbench.active_window.control, @@ -52,7 +53,7 @@ def _about_dialog_default(self): return about_dialog def _splash_screen_default(self): - """ Trait initializer. """ + """Trait initializer.""" splash_screen = SplashScreen( image=ImageResource("splash"), diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/acme_preferences_page.py b/examples/legacy/workbench/AcmeLab/acme/workbench/acme_preferences_page.py index e5bf6fba1..5d887258e 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/acme_preferences_page.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/acme_preferences_page.py @@ -13,12 +13,12 @@ # Enthought library imports. from apptools.preferences.ui.api import PreferencesPage -from traits.api import Color, Int, Float, Font +from traits.api import Color, Float, Font, Int from traitsui.api import View class AcmePreferencesPage(PreferencesPage): - """ The preferences page for the Acme workbench. """ + """The preferences page for the Acme workbench.""" #### 'PreferencesPage' interface ########################################## diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/acme_workbench_plugin.py b/examples/legacy/workbench/AcmeLab/acme/workbench/acme_workbench_plugin.py index 4200cd648..65b06f130 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/acme_workbench_plugin.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/acme_workbench_plugin.py @@ -11,13 +11,14 @@ """ The AcmeLab Workbench plugin. """ +from traits.api import List + # Enthought library imports. from envisage.api import Plugin -from traits.api import List class AcmeWorkbenchPlugin(Plugin): - """ The AcmeLab Workbench plugin. + """The AcmeLab Workbench plugin. This plugin is part of the 'AcmeLab' example application. @@ -43,7 +44,7 @@ class AcmeWorkbenchPlugin(Plugin): action_sets = List(contributes_to=ACTION_SETS) def _action_sets_default(self): - """ Trait initializer. """ + """Trait initializer.""" from .example_action_set import ExampleActionSet @@ -53,10 +54,12 @@ def _action_sets_default(self): perspectives = List(contributes_to=PERSPECTIVES) def _perspectives_default(self): - """ Trait initializer. """ + """Trait initializer.""" - from acme.workbench.perspective.api import FooPerspective - from acme.workbench.perspective.api import BarPerspective + from acme.workbench.perspective.api import ( + BarPerspective, + FooPerspective, + ) return [FooPerspective, BarPerspective] @@ -64,7 +67,7 @@ def _perspectives_default(self): preferences_pages = List(contributes_to=PREFERENCES_PAGES) def _preferences_pages_default(self): - """ Trait initializer. """ + """Trait initializer.""" from acme_preferences_page import AcmePreferencesPage @@ -74,9 +77,14 @@ def _preferences_pages_default(self): views = List(contributes_to=VIEWS) def _views_default(self): - """ Trait initializer. """ - - from acme.workbench.view.api import BlackView, BlueView, GreenView - from acme.workbench.view.api import RedView, YellowView + """Trait initializer.""" + + from acme.workbench.view.api import ( + BlackView, + BlueView, + GreenView, + RedView, + YellowView, + ) return [BlackView, BlueView, GreenView, RedView, YellowView] diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/action/new_view_action.py b/examples/legacy/workbench/AcmeLab/acme/workbench/action/new_view_action.py index 36d88ca4a..8a8f383ca 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/action/new_view_action.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/action/new_view_action.py @@ -17,7 +17,7 @@ class NewViewAction(Action): - """ An action that dynamically creates and adds a view. """ + """An action that dynamically creates and adds a view.""" #### 'Action' interface ################################################### @@ -35,7 +35,7 @@ class NewViewAction(Action): ########################################################################### def perform(self, event): - """ Perform the action. """ + """Perform the action.""" # You can give the view a position... (it default to 'left')... view = View(id="my.view.fred", name="Fred", position="right") diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/example_action_set.py b/examples/legacy/workbench/AcmeLab/acme/workbench/example_action_set.py index 2d6b6cfff..d81e92fa8 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/example_action_set.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/example_action_set.py @@ -17,7 +17,7 @@ class ExampleActionSet(WorkbenchActionSet): - """ An action test useful for testing. """ + """An action test useful for testing.""" #### 'ActionSet' interface ################################################ @@ -29,26 +29,17 @@ class ExampleActionSet(WorkbenchActionSet): name="&Test", path="MenuBar", before="Help", - groups=[ - Group(id="XGroup"), - Group(id="YGroup") - ], + groups=[Group(id="XGroup"), Group(id="YGroup")], ), Menu( name="Foo", path="MenuBar/Test", - groups=[ - Group(id="XGroup"), - Group(id="YGroup") - ], + groups=[Group(id="XGroup"), Group(id="YGroup")], ), Menu( name="Bar", path="MenuBar/Test", - groups=[ - Group(id="XGroup"), - Group(id="YGroup") - ], + groups=[Group(id="XGroup"), Group(id="YGroup")], ), ] diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/perspective/bar_perspective.py b/examples/legacy/workbench/AcmeLab/acme/workbench/perspective/bar_perspective.py index b76c89ee8..e06fc0343 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/perspective/bar_perspective.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/perspective/bar_perspective.py @@ -16,7 +16,7 @@ class BarPerspective(Perspective): - """ An example perspective. """ + """An example perspective.""" # The perspective's name. name = "Bar" diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/perspective/foo_perspective.py b/examples/legacy/workbench/AcmeLab/acme/workbench/perspective/foo_perspective.py index 452bfff13..becea6af2 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/perspective/foo_perspective.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/perspective/foo_perspective.py @@ -16,7 +16,7 @@ class FooPerspective(Perspective): - """ An example perspective. """ + """An example perspective.""" # The perspective's name. name = "Foo" diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/view/black_view.py b/examples/legacy/workbench/AcmeLab/acme/workbench/view/black_view.py index a00adc497..a78f46f8e 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/view/black_view.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/view/black_view.py @@ -16,7 +16,7 @@ class BlackView(ColorView): - """ A view containing a black panel! """ + """A view containing a black panel!""" #### 'IView' interface #################################################### diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/view/blue_view.py b/examples/legacy/workbench/AcmeLab/acme/workbench/view/blue_view.py index cc667cc11..74ef6e656 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/view/blue_view.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/view/blue_view.py @@ -16,7 +16,7 @@ class BlueView(ColorView): - """ A view containing a blue panel! """ + """A view containing a blue panel!""" #### 'IView' interface #################################################### diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/view/color_view.py b/examples/legacy/workbench/AcmeLab/acme/workbench/view/color_view.py index d643d72d0..371adbe51 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/view/color_view.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/view/color_view.py @@ -11,10 +11,10 @@ """ A view containing a colored panel! """ -# Enthought library imports. -from traits.etsconfig.api import ETSConfig from pyface.workbench.api import View +# Enthought library imports. +from traits.etsconfig.api import ETSConfig _TOOLKIT_MAPPING = { "qt4": "qt", @@ -22,14 +22,14 @@ def _normalize_toolkit_name(toolkit): - """ Convert legacy toolkit names to current toolkit names. """ + """Convert legacy toolkit names to current toolkit names.""" toolkit = toolkit.lower() return _TOOLKIT_MAPPING.get(toolkit, toolkit) class ColorView(View): - """ A view containing a colored panel! + """A view containing a colored panel! This view is written so that it works with *both* wx and Qt4. Your own views obviously do not have to do this! @@ -48,7 +48,7 @@ class ColorView(View): #### Trait initializers ################################################### def _id_default(self): - """ Trait initializer. """ + """Trait initializer.""" # By making the Id the same as the name, we make it easy to specify # the views in the example perspectives. Note for larger applications @@ -59,7 +59,7 @@ def _id_default(self): #### Methods ############################################################## def create_control(self, parent): - """ Creates the toolkit-specific control that represents the view. + """Creates the toolkit-specific control that represents the view. 'parent' is the toolkit-specific control that is the view's parent. @@ -79,7 +79,7 @@ def create_control(self, parent): ########################################################################### def _wx_create_control(self, parent, color): - """ Create a wx version of the control. """ + """Create a wx version of the control.""" import wx @@ -89,7 +89,7 @@ def _wx_create_control(self, parent, color): return panel def _qt_create_control(self, parent, color): - """ Create a Qt version of the control. """ + """Create a Qt version of the control.""" from pyface.qt import QtGui diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/view/green_view.py b/examples/legacy/workbench/AcmeLab/acme/workbench/view/green_view.py index 8167fb829..85708a7bc 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/view/green_view.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/view/green_view.py @@ -16,7 +16,7 @@ class GreenView(ColorView): - """ A view containing a green panel! """ + """A view containing a green panel!""" #### 'IView' interface #################################################### diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/view/red_view.py b/examples/legacy/workbench/AcmeLab/acme/workbench/view/red_view.py index 2739973fb..4d55834a0 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/view/red_view.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/view/red_view.py @@ -16,7 +16,7 @@ class RedView(ColorView): - """ A view containing a red panel! """ + """A view containing a red panel!""" #### 'IView' interface #################################################### diff --git a/examples/legacy/workbench/AcmeLab/acme/workbench/view/yellow_view.py b/examples/legacy/workbench/AcmeLab/acme/workbench/view/yellow_view.py index 2ac2e7e97..98c1289f9 100644 --- a/examples/legacy/workbench/AcmeLab/acme/workbench/view/yellow_view.py +++ b/examples/legacy/workbench/AcmeLab/acme/workbench/view/yellow_view.py @@ -16,7 +16,7 @@ class YellowView(ColorView): - """ A view containing a yellow panel! """ + """A view containing a yellow panel!""" #### 'IView' interface #################################################### diff --git a/examples/legacy/workbench/AcmeLab/run.py b/examples/legacy/workbench/AcmeLab/run.py index 2861f6f0c..edc1f1240 100644 --- a/examples/legacy/workbench/AcmeLab/run.py +++ b/examples/legacy/workbench/AcmeLab/run.py @@ -17,13 +17,12 @@ # Example imports. from acme.acmelab.api import Acmelab -# Enthought plugins. -from envisage.api import CorePlugin -from envisage.ui.workbench.workbench_plugin import WorkbenchPlugin - # Example plugins. from acme.workbench.acme_workbench_plugin import AcmeWorkbenchPlugin +# Enthought plugins. +from envisage.api import CorePlugin +from envisage.ui.workbench.workbench_plugin import WorkbenchPlugin # Do whatever you want to do with log messages! Here we create a log file. logger = logging.getLogger() @@ -33,7 +32,7 @@ def main(): - """ Run the application. """ + """Run the application.""" # Create an application with the specified plugins. acmelab = Acmelab(