-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: reloading relative imports on plugin updates (#323)
- Loading branch information
1 parent
9fafe24
commit 42f34f8
Showing
24 changed files
with
481 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/CANVAS_MANIFEST.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"sdk_version": "0.1.4", | ||
"plugin_version": "0.0.1", | ||
"name": "test_implicit_imports_plugin", | ||
"description": "Edit the description in CANVAS_MANIFEST.json", | ||
"components": { | ||
"protocols": [ | ||
{ | ||
"class": "test_implicit_imports_plugin.protocols.my_protocol:Forbidden", | ||
"description": "A protocol that does xyz...", | ||
"data_access": { | ||
"event": "", | ||
"read": [], | ||
"write": [] | ||
} | ||
}, | ||
{ | ||
"class": "test_implicit_imports_plugin.protocols.my_protocol:Allowed", | ||
"description": "A protocol that does xyz...", | ||
"data_access": { | ||
"event": "", | ||
"read": [], | ||
"write": [] | ||
} | ||
} | ||
], | ||
"commands": [], | ||
"content": [], | ||
"effects": [], | ||
"views": [] | ||
}, | ||
"secrets": [], | ||
"tags": {}, | ||
"references": [], | ||
"license": "", | ||
"diagram": false, | ||
"readme": "./README.md" | ||
} |
11 changes: 11 additions & 0 deletions
11
plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
test_forbiden_implicit_imports_plugin | ||
===================================== | ||
|
||
## Description | ||
|
||
A description of this plugin | ||
|
||
### Important Note! | ||
|
||
The CANVAS_MANIFEST.json is used when installing your plugin. Please ensure it | ||
gets updated if you add, remove, or rename protocols. |
Empty file.
33 changes: 33 additions & 0 deletions
33
plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/protocols/my_protocol.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from canvas_sdk.effects import Effect | ||
from canvas_sdk.events import EventType | ||
from canvas_sdk.protocols import BaseProtocol | ||
from logger import log | ||
|
||
|
||
class Forbidden(BaseProtocol): | ||
"""You should put a helpful description of this protocol's behavior here.""" | ||
|
||
# Name the event type you wish to run in response to | ||
RESPONDS_TO = EventType.Name(EventType.UNKNOWN) | ||
|
||
def compute(self) -> list[Effect]: | ||
"""This method gets called when an event of the type RESPONDS_TO is fired.""" | ||
from test_implicit_imports_plugin.utils.base import OtherClass | ||
|
||
OtherClass() | ||
|
||
return [] | ||
|
||
|
||
class Allowed(BaseProtocol): | ||
"""You should put a helpful description of this protocol's behavior here.""" | ||
|
||
RESPONDS_TO = EventType.Name(EventType.UNKNOWN) | ||
|
||
def compute(self) -> list[Effect]: | ||
"""This method gets called when an event of the type RESPONDS_TO is fired.""" | ||
from test_implicit_imports_plugin.templates import Template | ||
|
||
log.info(Template().render()) | ||
|
||
return [] |
3 changes: 3 additions & 0 deletions
3
plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/templates/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from test_implicit_imports_plugin.templates.base import Template | ||
|
||
__all__ = ("Template",) |
6 changes: 6 additions & 0 deletions
6
plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/templates/base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Template: | ||
"""A template class for testing implicit imports.""" | ||
|
||
def render(self) -> str: | ||
"""Renders the template.""" | ||
return "Hello, World!" |
5 changes: 5 additions & 0 deletions
5
plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/utils/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import os | ||
|
||
from logger import log | ||
|
||
log.info(f"os list dir: {os.listdir('.')}") |
4 changes: 4 additions & 0 deletions
4
plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/utils/base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class OtherClass: | ||
"""This class is used to test implicit imports.""" | ||
|
||
pass |
29 changes: 29 additions & 0 deletions
29
...n_runner/tests/fixtures/plugins/test_module_forbidden_imports_plugin/CANVAS_MANIFEST.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"sdk_version": "0.1.4", | ||
"plugin_version": "0.0.1", | ||
"name": "test_module_forbidden_imports_plugin", | ||
"description": "Edit the description in CANVAS_MANIFEST.json", | ||
"components": { | ||
"protocols": [ | ||
{ | ||
"class": "test_module_forbidden_imports_plugin.protocols.my_protocol:Protocol", | ||
"description": "A protocol that does xyz...", | ||
"data_access": { | ||
"event": "", | ||
"read": [], | ||
"write": [] | ||
} | ||
} | ||
], | ||
"commands": [], | ||
"content": [], | ||
"effects": [], | ||
"views": [] | ||
}, | ||
"secrets": [], | ||
"tags": {}, | ||
"references": [], | ||
"license": "", | ||
"diagram": false, | ||
"readme": "./README.md" | ||
} |
12 changes: 12 additions & 0 deletions
12
...in_runner/tests/fixtures/plugins/test_module_forbidden_imports_plugin/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
========================== | ||
test_module_forbidden_imports_plugin | ||
========================== | ||
|
||
## Description | ||
|
||
A description of this plugin | ||
|
||
### Important Note! | ||
|
||
The CANVAS_MANIFEST.json is used when installing your plugin. Please ensure it | ||
gets updated if you add, remove, or rename protocols. |
Empty file.
10 changes: 10 additions & 0 deletions
10
...n_runner/tests/fixtures/plugins/test_module_forbidden_imports_plugin/other_module/base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
|
||
from logger import log | ||
|
||
log.info(f"This is a forbidden import. {os}") | ||
|
||
|
||
def import_me() -> str: | ||
"""Test method.""" | ||
return "Successfully imported!" |
Empty file.
18 changes: 18 additions & 0 deletions
18
...nner/tests/fixtures/plugins/test_module_forbidden_imports_plugin/protocols/my_protocol.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from test_module_forbidden_imports_plugin.other_module.base import import_me | ||
|
||
from canvas_sdk.effects import Effect, EffectType | ||
from canvas_sdk.events import EventType | ||
from canvas_sdk.protocols import BaseProtocol | ||
|
||
|
||
class Protocol(BaseProtocol): | ||
""" | ||
You should put a helpful description of this protocol's behavior here. | ||
""" | ||
|
||
# Name the event type you wish to run in response to | ||
RESPONDS_TO = EventType.Name(EventType.UNKNOWN) | ||
|
||
def compute(self) -> list[Effect]: | ||
"""This method gets called when an event of the type RESPONDS_TO is fired.""" | ||
return [Effect(type=EffectType.LOG, payload=import_me())] |
Oops, something went wrong.