Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pylint warnings #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main_application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Main applicatoin that demonstrates the functionality of
"""Main application that demonstrates the functionality of
the dynamic plugins and the PluginCollection class
"""

Expand Down
33 changes: 22 additions & 11 deletions plugin_collection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
""" Simple Plugin implementation in Python
"""

import inspect
import os
import pkgutil


class Plugin(object):
"""Base class that each plugin must inherit from. within this class
class Plugin():
"""Base class that each plugin must inherit from. Within this class
you must define the methods that all of your plugins must implement
"""
# pylint: disable=too-few-public-methods

def __init__(self):
self.description = 'UNKNOWN'
Expand All @@ -20,7 +24,7 @@ def perform_operation(self, argument):



class PluginCollection(object):
class PluginCollection():
"""Upon creation, this class will read the plugins package for modules
that contain a class definition that is inheriting from the Plugin class
"""
Expand Down Expand Up @@ -50,22 +54,25 @@ def apply_all_plugins_on_value(self, argument):
print()
print(f'Applying all plugins on value {argument}:')
for plugin in self.plugins:
print(f' Applying {plugin.description} on value {argument} yields value {plugin.perform_operation(argument)}')
print(f' Applying {plugin.description} on value {argument}'\
f' yields value {plugin.perform_operation(argument)}')

def walk_package(self, package):
"""Recursively walk the supplied package to retrieve all plugins
"""
imported_package = __import__(package, fromlist=['blah'])

for _, pluginname, ispkg in pkgutil.iter_modules(imported_package.__path__, imported_package.__name__ + '.'):
for _, pluginname, ispkg in pkgutil.iter_modules(
imported_package.__path__, imported_package.__name__ + '.'
):
if not ispkg:
plugin_module = __import__(pluginname, fromlist=['blah'])
clsmembers = inspect.getmembers(plugin_module, inspect.isclass)
for (_, c) in clsmembers:
for (_, cls) in clsmembers:
# Only add classes that are a sub class of Plugin, but NOT Plugin itself
if issubclass(c, Plugin) & (c is not Plugin):
print(f' Found plugin class: {c.__module__}.{c.__name__}')
self.plugins.append(c())
if issubclass(cls, Plugin) & (cls is not Plugin):
print(f' Found plugin class: {cls.__module__}.{cls.__name__}')
self.plugins.append(cls())


# Now that we have looked at all the modules in the current package, start looking
Expand All @@ -74,14 +81,18 @@ def walk_package(self, package):
if isinstance(imported_package.__path__, str):
all_current_paths.append(imported_package.__path__)
else:
all_current_paths.extend([x for x in imported_package.__path__])
all_current_paths.extend(imported_package.__path__)

for pkg_path in all_current_paths:
if pkg_path not in self.seen_paths:
self.seen_paths.append(pkg_path)

# Get all sub directory of the current package path directory
child_pkgs = [p for p in os.listdir(pkg_path) if os.path.isdir(os.path.join(pkg_path, p))]
child_pkgs = [
p for p in os.listdir(pkg_path)
if os.path.isdir(os.path.join(pkg_path, p))
]


# For each sub directory, apply the walk_package method recursively
for child_pkg in child_pkgs:
Expand Down
9 changes: 7 additions & 2 deletions plugins/double/double_negative.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import plugin_collection
"""Negative double function
"""

class DoubleNegative(plugin_collection.Plugin):
from plugin_collection import Plugin

class DoubleNegative(Plugin):
"""This plugin will just multiply the argument with the value -2
"""
# pylint: disable=too-few-public-methods

def __init__(self):
super().__init__()
self.description = 'Negative double function'
Expand Down
5 changes: 5 additions & 0 deletions plugins/double/double_positive.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
"""Double function
"""

from plugin_collection import Plugin

class DoublePositive(Plugin):
"""This plugin will just multiply the argument with the value 2
"""
# pylint: disable=too-few-public-methods

def __init__(self):
super().__init__()
self.description = 'Double function'
Expand Down
9 changes: 7 additions & 2 deletions plugins/identity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import plugin_collection
"""Identity function
"""

class Identity(plugin_collection.Plugin):
from plugin_collection import Plugin

class Identity(Plugin):
"""This plugin is just the identity function: it returns the argument
"""
# pylint: disable=too-few-public-methods

def __init__(self):
super().__init__()
self.description = 'Identity function'
Expand Down