Skip to content

Commit

Permalink
Add support for plug-ins
Browse files Browse the repository at this point in the history
  • Loading branch information
gheinrich committed Jul 25, 2016
1 parent 286a739 commit ab66843
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 28 deletions.
37 changes: 24 additions & 13 deletions digits/extensions/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
from __future__ import absolute_import

import copy
from pkg_resources import iter_entry_points

from . import imageGradients
from . import objectDetection

data_extensions = [
# Set show=True if extension should be shown by default
# on DIGITS home page. These defaults can be changed by
# editing DIGITS config option 'data_extension_list'
{'class': imageGradients.DataIngestion, 'show': False},
{'class': objectDetection.DataIngestion, 'show': True},

# Entry point group (this is the key we use to register and
# find installed plug-ins)
GROUP = "digits.plugins.data"


# built-in extensions
builtin_data_extensions = [
imageGradients.DataIngestion,
objectDetection.DataIngestion,
]


def get_extensions(show_all=False):
"""
return set of data data extensions
"""
return [extension['class']
for extension in data_extensions
if show_all or extension['show']]
extensions = copy.copy(builtin_data_extensions)
# find installed extension plug-ins
for entry_point in iter_entry_points(group=GROUP, name=None):
extensions.append(entry_point.load())

return [extension
for extension in extensions
if show_all or extension.get_default_visibility()]


def get_extension(extension_id):
"""
return extension associated with specified extension_id
"""
for extension in data_extensions:
extension_class = extension['class']
if extension_class.get_id() == extension_id:
return extension_class
for extension in get_extensions(show_all=True):
if extension.get_id() == extension_id:
return extension
return None
8 changes: 8 additions & 0 deletions digits/extensions/data/imageGradients/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def encode_entry(self, entry):
def get_category():
return "Images"

@staticmethod
def get_default_visibility():
"""
Return whether to show extension in GUI (can be overridden through
DIGITS configuration options)
"""
return False

@staticmethod
@override
def get_id():
Expand Down
8 changes: 8 additions & 0 deletions digits/extensions/data/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def get_dataset_form():
"""
raise NotImplementedError

@staticmethod
def get_default_visibility():
"""
Return whether to show extension in GUI (can be overridden through
DIGITS configuration options)
"""
return True

@staticmethod
def get_dataset_template(form):
"""
Expand Down
40 changes: 25 additions & 15 deletions digits/extensions/view/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
from __future__ import absolute_import

import copy
from pkg_resources import iter_entry_points

from . import boundingBox
from . import imageGradients
from . import rawData

view_extensions = [
# Set show=True if extension should be shown by default
# in the 'Select Visualization Method' dialog. These defaults
# can be changed by editing DIGITS config option
# 'view_extension_list'
{'class': boundingBox.Visualization, 'show': True},
{'class': imageGradients.Visualization, 'show': False},
{'class': rawData.Visualization, 'show': True},

# Entry point group (this is the key we use to register and
# find installed plug-ins)
GROUP = "digits.plugins.view"


# built-in extensions
builtin_view_extensions = [
boundingBox.Visualization,
imageGradients.Visualization,
rawData.Visualization,
]


Expand All @@ -27,17 +33,21 @@ def get_extensions(show_all=False):
"""
return set of data data extensions
"""
return [extension['class']
for extension in view_extensions
if show_all or extension['show']]
extensions = copy.copy(builtin_view_extensions)
# find installed extension plug-ins
for entry_point in iter_entry_points(group=GROUP, name=None):
extensions.append(entry_point.load())

return [extension
for extension in extensions
if show_all or extension.get_default_visibility()]


def get_extension(extension_id):
"""
return extension associated with specified extension_id
"""
for extension in view_extensions:
extension_class = extension['class']
if extension_class.get_id() == extension_id:
return extension_class
for extension in get_extensions(show_all=True):
if extension.get_id() == extension_id:
return extension
return None
8 changes: 8 additions & 0 deletions digits/extensions/view/imageGradients/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ def get_config_template(form):
context = {'form': form}
return (template, context)

@staticmethod
def get_default_visibility():
"""
Return whether to show extension in GUI (can be overridden through
DIGITS configuration options)
"""
return False

@staticmethod
def get_id():
return digits.extensions.data.imageGradients.data.DataIngestion.get_id()
Expand Down
8 changes: 8 additions & 0 deletions digits/extensions/view/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def get_config_template(form):
"""
raise NotImplementedError

@staticmethod
def get_default_visibility():
"""
Return whether to show extension in GUI (can be overridden through
DIGITS configuration options)
"""
return True

def get_header_template(self):
"""
This returns the content to be rendered at the top of the result
Expand Down
7 changes: 7 additions & 0 deletions docs/BuildDigits.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ Several PyPI packages need to be installed:
sudo pip install -r $DIGITS_HOME/requirements.txt
```

# [Optional] Enable support for plug-ins

DIGITS needs to be installed to enable loading data and visualization plug-ins:
```
sudo pip install $DIGITS_HOME
```

# Starting the server

You can run DIGITS in two modes:
Expand Down
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from setuptools import setup, find_packages

import digits

setup(
name = "digits",
packages = find_packages(),
version = digits.__version__
)

0 comments on commit ab66843

Please sign in to comment.