platzky 0.2.13__tar.gz → 0.2.15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {platzky-0.2.13 → platzky-0.2.15}/PKG-INFO +2 -2
  2. platzky-0.2.15/platzky/plugin_loader.py +81 -0
  3. {platzky-0.2.13 → platzky-0.2.15}/pyproject.toml +1 -1
  4. platzky-0.2.13/platzky/plugin_loader.py +0 -39
  5. {platzky-0.2.13 → platzky-0.2.15}/README.md +0 -0
  6. {platzky-0.2.13 → platzky-0.2.15}/platzky/__init__.py +0 -0
  7. {platzky-0.2.13 → platzky-0.2.15}/platzky/blog/__init__.py +0 -0
  8. {platzky-0.2.13 → platzky-0.2.15}/platzky/blog/blog.py +0 -0
  9. {platzky-0.2.13 → platzky-0.2.15}/platzky/blog/comment_form.py +0 -0
  10. {platzky-0.2.13 → platzky-0.2.15}/platzky/config.py +0 -0
  11. {platzky-0.2.13 → platzky-0.2.15}/platzky/db/__init__.py +0 -0
  12. {platzky-0.2.13 → platzky-0.2.15}/platzky/db/db.py +0 -0
  13. {platzky-0.2.13 → platzky-0.2.15}/platzky/db/db_loader.py +0 -0
  14. {platzky-0.2.13 → platzky-0.2.15}/platzky/db/google_json_db.py +0 -0
  15. {platzky-0.2.13 → platzky-0.2.15}/platzky/db/graph_ql_db.py +0 -0
  16. {platzky-0.2.13 → platzky-0.2.15}/platzky/db/json_db.py +0 -0
  17. {platzky-0.2.13 → platzky-0.2.15}/platzky/db/json_file_db.py +0 -0
  18. {platzky-0.2.13 → platzky-0.2.15}/platzky/locale/en/LC_MESSAGES/messages.po +0 -0
  19. {platzky-0.2.13 → platzky-0.2.15}/platzky/locale/pl/LC_MESSAGES/messages.po +0 -0
  20. {platzky-0.2.13 → platzky-0.2.15}/platzky/models.py +0 -0
  21. {platzky-0.2.13 → platzky-0.2.15}/platzky/platzky.py +0 -0
  22. {platzky-0.2.13 → platzky-0.2.15}/platzky/plugins/google-tag-manager/entrypoint.py +0 -0
  23. {platzky-0.2.13 → platzky-0.2.15}/platzky/plugins/redirections/entrypoint.py +0 -0
  24. {platzky-0.2.13 → platzky-0.2.15}/platzky/plugins/sendmail/entrypoint.py +0 -0
  25. {platzky-0.2.13 → platzky-0.2.15}/platzky/seo/seo.py +0 -0
  26. {platzky-0.2.13 → platzky-0.2.15}/platzky/static/blog.css +0 -0
  27. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/404.html +0 -0
  28. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/base.html +0 -0
  29. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/blog.html +0 -0
  30. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/body_meta.html +0 -0
  31. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/feed.xml +0 -0
  32. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/head_meta.html +0 -0
  33. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/home.html +0 -0
  34. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/page.html +0 -0
  35. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/post.html +0 -0
  36. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/robots.txt +0 -0
  37. {platzky-0.2.13 → platzky-0.2.15}/platzky/templates/sitemap.xml +0 -0
  38. {platzky-0.2.13 → platzky-0.2.15}/platzky/www_handler.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: platzky
3
- Version: 0.2.13
3
+ Version: 0.2.15
4
4
  Summary: Not only blog engine
5
5
  License: MIT
6
6
  Requires-Python: >=3.10,<4.0
@@ -0,0 +1,81 @@
1
+ import importlib.util
2
+ import logging
3
+ import os
4
+ import sys
5
+ from os.path import abspath, dirname
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ class PluginError(Exception):
11
+ pass
12
+
13
+
14
+ # TODO remove find_local_plugin after all plugins will be extracted
15
+ def find_local_plugin(plugin_name):
16
+ """Find plugin by name and return it as module.
17
+ :param plugin_name: name of plugin to find
18
+ :return: module of plugin
19
+ """
20
+ plugins_dir = os.path.join(dirname(abspath(__file__)), "plugins")
21
+ module_name = plugin_name.removesuffix(".py")
22
+ spec = importlib.util.spec_from_file_location(
23
+ module_name, os.path.join(plugins_dir, plugin_name, "entrypoint.py")
24
+ )
25
+ assert spec is not None
26
+ plugin = importlib.util.module_from_spec(spec)
27
+ sys.modules[module_name] = plugin
28
+ assert spec.loader is not None
29
+ spec.loader.exec_module(plugin)
30
+ return plugin
31
+
32
+
33
+ def find_installed_plugin(plugin_name):
34
+ """Find plugin by name and return it as module.
35
+ :param plugin_name: name of plugin to find
36
+ :raises PluginError: if plugin cannot be imported
37
+ :return: module of plugin
38
+ """
39
+ try:
40
+ return importlib.import_module(f"platzky_{plugin_name}")
41
+ except ImportError as e:
42
+ raise PluginError(
43
+ f"Plugin {plugin_name} not found. Ensure it's installed and follows "
44
+ f"the 'platzky_<plugin_name>' naming convention"
45
+ ) from e
46
+
47
+
48
+ def find_plugin(plugin_name):
49
+ """Find plugin by name and return it as module.
50
+ :param plugin_name: name of plugin to find
51
+ :raises PluginError: if plugin cannot be found or imported
52
+ :return: module of plugin
53
+ """
54
+ plugin = None
55
+ try:
56
+ plugin = find_local_plugin(plugin_name)
57
+ except FileNotFoundError:
58
+ logger.info(f"Local plugin {plugin_name} not found, trying installed version")
59
+ plugin = find_installed_plugin(plugin_name)
60
+
61
+ return plugin
62
+
63
+
64
+ def plugify(app):
65
+ """Load plugins and run their entrypoints.
66
+ :param app: Flask app
67
+ :return: Flask app
68
+ """
69
+
70
+ plugins_data = app.db.get_plugins_data()
71
+
72
+ for plugin_data in plugins_data:
73
+ plugin_config = plugin_data["config"]
74
+ plugin_name = plugin_data["name"]
75
+ try:
76
+ plugin = find_plugin(plugin_name)
77
+ plugin.process(app, plugin_config)
78
+ except Exception as e:
79
+ raise PluginError(f"Error processing plugin {plugin_name}: {e}") from e
80
+
81
+ return app
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "platzky"
3
- version = "0.2.13"
3
+ version = "0.2.15"
4
4
  description = "Not only blog engine"
5
5
  authors = []
6
6
  license = "MIT"
@@ -1,39 +0,0 @@
1
- import importlib.util
2
- import os
3
- import sys
4
- from os.path import abspath, dirname
5
-
6
-
7
- def find_plugin(plugin_name):
8
- """Find plugin by name and return it as module.
9
- :param plugin_name: name of plugin to find
10
- :return: module of plugin
11
- """
12
- plugins_dir = os.path.join(dirname(abspath(__file__)), "plugins")
13
- module_name = plugin_name.removesuffix(".py")
14
- spec = importlib.util.spec_from_file_location(
15
- module_name, os.path.join(plugins_dir, plugin_name, "entrypoint.py")
16
- )
17
- assert spec is not None
18
- plugin = importlib.util.module_from_spec(spec)
19
- sys.modules[module_name] = plugin
20
- assert spec.loader is not None
21
- spec.loader.exec_module(plugin)
22
- return plugin
23
-
24
-
25
- def plugify(app):
26
- """Load plugins and run their entrypoints.
27
- :param app: Flask app
28
- :return: Flask app
29
- """
30
-
31
- plugins_data = app.db.get_plugins_data()
32
-
33
- for plugin_data in plugins_data:
34
- plugin_config = plugin_data["config"]
35
- plugin_name = plugin_data["name"]
36
- plugin = find_plugin(plugin_name)
37
- plugin.process(app, plugin_config)
38
-
39
- return app
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes