-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Temporal.io related code encapsulation
- Loading branch information
Showing
21 changed files
with
129 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 1.0.0 (2024-05-16) | ||
|
||
* Initial release | ||
|
||
## 1.1.0 (2024-05-30) | ||
|
||
* add Temporal.io related code encapsulation |
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
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
File renamed without changes.
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
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
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,32 @@ | ||
from importlib import import_module | ||
from unittest import TestCase, mock | ||
|
||
from django.test import override_settings | ||
|
||
from django_temporalio.conf import settings, SETTINGS_KEY, SettingIsNotSetError | ||
from django_temporalio.utils import autodiscover_modules | ||
|
||
|
||
class AutodiscoverModulesTestCase(TestCase): | ||
""" | ||
Test case for utils.autodiscover_modules. | ||
""" | ||
|
||
@override_settings(**{SETTINGS_KEY: {"BASE_MODULE": "dev.temporalio"}}) | ||
@mock.patch("django_temporalio.utils.import_module", wraps=import_module) | ||
def test_autodiscover_modules(self, import_module_mock): | ||
autodiscover_modules("*workflows*") | ||
|
||
import_module_mock.assert_has_calls( | ||
[ | ||
mock.call("dev.temporalio"), | ||
mock.call("dev.temporalio.workflows"), | ||
mock.call("dev.temporalio.foo.foo_workflows"), | ||
mock.call("dev.temporalio.foo.bar.workflows_bar"), | ||
] | ||
) | ||
|
||
def test_autodiscover_modules_raises_exception(self): | ||
self.assertIsNone(settings.BASE_MODULE) | ||
with self.assertRaises(SettingIsNotSetError): | ||
autodiscover_modules("*workflows*") |
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
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,46 @@ | ||
import fnmatch | ||
import os | ||
from importlib import import_module | ||
|
||
from django_temporalio.conf import settings, SettingIsNotSetError | ||
|
||
|
||
def autodiscover_modules(related_name_pattern: str): | ||
""" | ||
Autodiscover modules matching the related name pattern in the base module. | ||
Example for the following directory structure: | ||
foo/ | ||
workflows.py | ||
activities.py | ||
bar/ | ||
bar_workflows.py | ||
activities.py | ||
baz/ | ||
workflows_baz.py | ||
activities.py | ||
Calling `autodiscover_modules('foo', '*workflows*')` will discover the following modules: | ||
- foo.workflows | ||
- foo.bar.bar_workflows | ||
- foo.bar.baz.workflows_baz | ||
""" | ||
base_module_name = settings.BASE_MODULE | ||
|
||
if not base_module_name: | ||
raise SettingIsNotSetError("BASE_MODULE setting must be set.") | ||
|
||
base_module = import_module(base_module_name) | ||
base_module_path = base_module.__path__[0] | ||
|
||
for root, _, files in os.walk(base_module_path): | ||
for file in files: | ||
if not fnmatch.fnmatch(file, f"{related_name_pattern}.py"): | ||
continue | ||
|
||
module_name = root.replace(base_module_path, base_module_name).replace( | ||
os.sep, "." | ||
) | ||
# import pdb; pdb.set_trace() | ||
import_module(f"{module_name}.{file[:-3]}") |