platzky 0.2.13__py3-none-any.whl → 0.2.15__py3-none-any.whl

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.
platzky/plugin_loader.py CHANGED
@@ -1,10 +1,18 @@
1
1
  import importlib.util
2
+ import logging
2
3
  import os
3
4
  import sys
4
5
  from os.path import abspath, dirname
5
6
 
7
+ logger = logging.getLogger(__name__)
6
8
 
7
- def find_plugin(plugin_name):
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):
8
16
  """Find plugin by name and return it as module.
9
17
  :param plugin_name: name of plugin to find
10
18
  :return: module of plugin
@@ -22,6 +30,37 @@ def find_plugin(plugin_name):
22
30
  return plugin
23
31
 
24
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
+
25
64
  def plugify(app):
26
65
  """Load plugins and run their entrypoints.
27
66
  :param app: Flask app
@@ -33,7 +72,10 @@ def plugify(app):
33
72
  for plugin_data in plugins_data:
34
73
  plugin_config = plugin_data["config"]
35
74
  plugin_name = plugin_data["name"]
36
- plugin = find_plugin(plugin_name)
37
- plugin.process(app, plugin_config)
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
38
80
 
39
81
  return app
@@ -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
@@ -14,7 +14,7 @@ platzky/locale/en/LC_MESSAGES/messages.po,sha256=WaZGlFAegKRq7CSz69dWKic-mKvQFhV
14
14
  platzky/locale/pl/LC_MESSAGES/messages.po,sha256=sUPxMKDeEOoZ5UIg94rGxZD06YVWiAMWIby2XE51Hrc,1624
15
15
  platzky/models.py,sha256=-IIlyeLzACeTUpzuzvzJYxtT57E6wRiERoRgXJYMMtY,1502
16
16
  platzky/platzky.py,sha256=h4oeC3B8cxbzv-Ut7iGKvsBmRTmxDKcK-R4PzUTZ-fE,4910
17
- platzky/plugin_loader.py,sha256=KYLDSEd_hseAgBuSbikerU_IFx-YmcYK5UwYw7kla2E,1106
17
+ platzky/plugin_loader.py,sha256=kYLaBOc8MA4b0T2yhVpSxZsX1rTxfcAnyGJCNKPGBXY,2428
18
18
  platzky/plugins/google-tag-manager/entrypoint.py,sha256=Z4npXtmCdrSuUG_ZvFdPhUZg5QcwIPGQWj9Uw9dcm8A,1021
19
19
  platzky/plugins/redirections/entrypoint.py,sha256=yoqHsRLqRALdICs5_UMSREkfEo1Lbsjj9tqEA7dsseg,1555
20
20
  platzky/plugins/sendmail/entrypoint.py,sha256=16GszfLaYhVUSuCdL4SPVKYN9-mONp-hK5ZWSiLluPo,1215
@@ -32,6 +32,6 @@ platzky/templates/post.html,sha256=GSgjIZsOQKtNx3cEbquSjZ5L4whPnG6MzRyoq9k4B8Q,1
32
32
  platzky/templates/robots.txt,sha256=2_j2tiYtYJnzZUrANiX9pvBxyw5Dp27fR_co18BPEJ0,116
33
33
  platzky/templates/sitemap.xml,sha256=iIJZ91_B5ZuNLCHsRtsGKZlBAXojOTP8kffqKLacgvs,578
34
34
  platzky/www_handler.py,sha256=pF6Rmvem1sdVqHD7z3RLrDuG-CwAqfGCti50_NPsB2w,725
35
- platzky-0.2.13.dist-info/METADATA,sha256=T_KA9bQOEypmy-fFR4sznSTuQA6iQhUuD3cMZdgADts,1643
36
- platzky-0.2.13.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
37
- platzky-0.2.13.dist-info/RECORD,,
35
+ platzky-0.2.15.dist-info/METADATA,sha256=PCyQWLEQkuh0zG6giZjLMwJxtzXFh6OGM8BiK7rCgKM,1643
36
+ platzky-0.2.15.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
37
+ platzky-0.2.15.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.1
2
+ Generator: poetry-core 2.0.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any