-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loading of periodic tasks and clean up extension loading. (#4064)
* Fix loading of periodic tasks and clean up extension loading. This does a few things: - add tests for extension loading - refactor the extension and periodic task loading - better handle assertions raised by extensions (e.g. when an extension tries to override an already registered view) - attach exception traceback to error log during loading for improved debugging * Use site.addsitedir instead of calling pip. * Use sys.path instead of site.addsitedir and also the setup.py egg_info command.
- Loading branch information
Showing
12 changed files
with
177 additions
and
37 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
Empty file.
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,22 @@ | ||
# How to update the dummy extension? | ||
|
||
If you'd like to extend the dummy extension, please update the ``setup.py`` | ||
file and the ``redash_dummy.py`` module. | ||
|
||
Please make sure to regenerate the *.egg-info directory. See below. | ||
|
||
# How to generate the redash_dummy.egg-info directory? | ||
|
||
The `egg-info` directory is what is usually created in the | ||
site-packages directory when running `pip install <packagename>` and | ||
contains the metadata derived from the `setup.py` file. | ||
|
||
In other words, it's auto-generated and you'll need to follow the following | ||
steps to update it (e.g. when extending the extension tests). From the | ||
host computer (assuming the Docker development environment) run: | ||
|
||
- `make bash` -- to create container running with Bash and entering it | ||
- `cd tests/extensions/redash-dummy/` -- change the directory to the directory with the dummy extension | ||
- `python setup.py egg_info` -- to create/update the egg-info directory | ||
|
||
The egg-info directory is *not* cleaned up by pip, just the link in the `~/.local` site-packages directory. |
10 changes: 10 additions & 0 deletions
10
tests/extensions/redash-dummy/redash_dummy.egg-info/PKG-INFO
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 @@ | ||
Metadata-Version: 1.0 | ||
Name: redash-dummy | ||
Version: 0.1 | ||
Summary: Redash extensions for testing | ||
Home-page: UNKNOWN | ||
Author: Redash authors | ||
Author-email: UNKNOWN | ||
License: MIT | ||
Description: UNKNOWN | ||
Platform: UNKNOWN |
8 changes: 8 additions & 0 deletions
8
tests/extensions/redash-dummy/redash_dummy.egg-info/SOURCES.txt
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,8 @@ | ||
README.md | ||
redash_dummy.py | ||
setup.py | ||
redash_dummy.egg-info/PKG-INFO | ||
redash_dummy.egg-info/SOURCES.txt | ||
redash_dummy.egg-info/dependency_links.txt | ||
redash_dummy.egg-info/entry_points.txt | ||
redash_dummy.egg-info/top_level.txt |
1 change: 1 addition & 0 deletions
1
tests/extensions/redash-dummy/redash_dummy.egg-info/dependency_links.txt
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 changes: 10 additions & 0 deletions
10
tests/extensions/redash-dummy/redash_dummy.egg-info/entry_points.txt
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 @@ | ||
[redash.extensions] | ||
assertive_extension = redash_dummy:assertive_extension | ||
non_callable_extension = redash_dummy:module_attribute | ||
not_findable_extension = redash_dummy:missing_attribute | ||
not_importable_extension = missing_extension_module:extension | ||
working_extension = redash_dummy:extension | ||
|
||
[redash.periodic_tasks] | ||
dummy_periodic_task = redash_dummy:periodic_task | ||
|
1 change: 1 addition & 0 deletions
1
tests/extensions/redash-dummy/redash_dummy.egg-info/top_level.txt
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 @@ | ||
redash_dummy |
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,15 @@ | ||
module_attribute = "hello!" | ||
|
||
|
||
def extension(app): | ||
"""This extension will work""" | ||
return "extension loaded" | ||
|
||
|
||
def assertive_extension(app): | ||
"""This extension won't work""" | ||
assert False | ||
|
||
|
||
def periodic_task(*args, **kwargs): | ||
"""This periodic task will successfully load""" |
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,23 @@ | ||
from setuptools import setup | ||
|
||
|
||
setup( | ||
name="redash-dummy", | ||
version="0.1", | ||
description="Redash extensions for testing", | ||
author="Redash authors", | ||
license="MIT", | ||
entry_points={ | ||
"redash.extensions": [ | ||
"working_extension = redash_dummy:extension", | ||
"non_callable_extension = redash_dummy:module_attribute", | ||
"not_findable_extension = redash_dummy:missing_attribute", | ||
"not_importable_extension = missing_extension_module:extension", | ||
"assertive_extension = redash_dummy:assertive_extension", | ||
], | ||
"redash.periodic_tasks": [ | ||
"dummy_periodic_task = redash_dummy:periodic_task" | ||
], | ||
}, | ||
py_modules=["redash_dummy"], | ||
) |
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,45 @@ | ||
import logging | ||
import os | ||
import sys | ||
|
||
from redash import extensions | ||
from tests import BaseTestCase | ||
|
||
logger = logging.getLogger(__name__) | ||
dummy_extension = "redash-dummy" | ||
dummy_path = os.path.join(os.path.dirname(__file__), dummy_extension) | ||
|
||
|
||
class TestExtensions(BaseTestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
sys.path.insert(0, dummy_path) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
sys.path.remove(dummy_path) | ||
|
||
def test_working_extension(self): | ||
self.assertIn("working_extension", extensions.extensions.keys()) | ||
self.assertEqual( | ||
extensions.extensions.get("working_extension"), "extension loaded" | ||
) | ||
|
||
def test_assertive_extension(self): | ||
self.assertNotIn("assertive_extension", extensions.extensions.keys()) | ||
|
||
def test_not_findable_extension(self): | ||
self.assertNotIn("not_findable_extension", extensions.extensions.keys()) | ||
|
||
def test_not_importable_extension(self): | ||
self.assertNotIn("not_importable_extension", extensions.extensions.keys()) | ||
|
||
def test_non_callable_extension(self): | ||
self.assertNotIn("non_callable_extension", extensions.extensions.keys()) | ||
|
||
def test_dummy_periodic_task(self): | ||
# need to load the periodic tasks manually since this isn't | ||
# done automatically on test suite start but only part of | ||
# the worker configuration | ||
extensions.load_periodic_tasks(logger) | ||
self.assertIn("dummy_periodic_task", extensions.periodic_tasks.keys()) |