Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
f8594570
Commit
f8594570
authored
Jun 29, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache loaded plugins in memory
parent
520fac1a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
14 deletions
+22
-14
common/lib/xmodule/x_module.py
+22
-14
No files found.
common/lib/xmodule/x_module.py
View file @
f8594570
...
@@ -23,6 +23,9 @@ class Plugin(object):
...
@@ -23,6 +23,9 @@ class Plugin(object):
entry_point: The name of the entry point to load plugins from
entry_point: The name of the entry point to load plugins from
"""
"""
_plugin_cache
=
None
@classmethod
@classmethod
def
load_class
(
cls
,
identifier
,
default
=
None
):
def
load_class
(
cls
,
identifier
,
default
=
None
):
"""
"""
...
@@ -33,20 +36,25 @@ class Plugin(object):
...
@@ -33,20 +36,25 @@ class Plugin(object):
If default is not None, will return default if no entry_point matching identifier
If default is not None, will return default if no entry_point matching identifier
is found. Otherwise, will raise a ModuleMissingError
is found. Otherwise, will raise a ModuleMissingError
"""
"""
identifier
=
identifier
.
lower
()
if
cls
.
_plugin_cache
is
None
:
classes
=
list
(
pkg_resources
.
iter_entry_points
(
cls
.
entry_point
,
name
=
identifier
))
cls
.
_plugin_cache
=
{}
if
len
(
classes
)
>
1
:
log
.
warning
(
"Found multiple classes for {entry_point} with identifier {id}: {classes}. Returning the first one."
.
format
(
if
identifier
not
in
cls
.
_plugin_cache
:
entry_point
=
cls
.
entry_point
,
identifier
=
identifier
.
lower
()
id
=
identifier
,
classes
=
list
(
pkg_resources
.
iter_entry_points
(
cls
.
entry_point
,
name
=
identifier
))
classes
=
", "
.
join
(
class_
.
module_name
for
class_
in
classes
)))
if
len
(
classes
)
>
1
:
log
.
warning
(
"Found multiple classes for {entry_point} with identifier {id}: {classes}. Returning the first one."
.
format
(
if
len
(
classes
)
==
0
:
entry_point
=
cls
.
entry_point
,
if
default
is
not
None
:
id
=
identifier
,
return
default
classes
=
", "
.
join
(
class_
.
module_name
for
class_
in
classes
)))
raise
ModuleMissingError
(
identifier
)
if
len
(
classes
)
==
0
:
return
classes
[
0
]
.
load
()
if
default
is
not
None
:
return
default
raise
ModuleMissingError
(
identifier
)
cls
.
_plugin_cache
[
identifier
]
=
classes
[
0
]
.
load
()
return
cls
.
_plugin_cache
[
identifier
]
@classmethod
@classmethod
def
load_classes
(
cls
):
def
load_classes
(
cls
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment