Changeset View
Changeset View
Standalone View
Standalone View
pillar/extension.py
| Show All 10 Lines | can then be registered to the application at app creation time: | ||||
| app.process_extensions() # Always process extensions after the last one is loaded. | app.process_extensions() # Always process extensions after the last one is loaded. | ||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||
| app.run('::0', 5000) | app.run('::0', 5000) | ||||
| """ | """ | ||||
| import abc | import abc | ||||
| import inspect | |||||
| import pathlib | |||||
| import typing | import typing | ||||
| import flask | import flask | ||||
| import pillarsdk | import pillarsdk | ||||
| class PillarExtension(object, metaclass=abc.ABCMeta): | class PillarExtension(object, metaclass=abc.ABCMeta): | ||||
| # Set to True when your extension implements the project_settings() method. | # Set to True when your extension implements the project_settings() method. | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | def static_path(self): | ||||
| Registers an endpoint named 'static_<extension name>', to use like: | Registers an endpoint named 'static_<extension name>', to use like: | ||||
| `url_for('static_attract', filename='js/somefile.js')` | `url_for('static_attract', filename='js/somefile.js')` | ||||
| May return None, in which case the extension will not be able to serve | May return None, in which case the extension will not be able to serve | ||||
| static files. | static files. | ||||
| """ | """ | ||||
| return None | return None | ||||
| @property | |||||
| def translations_path(self) -> typing.Union[pathlib.Path, None]: | |||||
| """Returns the path where the translations for this extension are stored. | |||||
| This is top folder that contains a "translations" sub-folder | |||||
| May return None, in which case English will always be used for this extension. | |||||
sybren: Returning `""` is in violation of the declared return type. | |||||
| """ | |||||
| class_filename = pathlib.Path(inspect.getfile(self.__class__)) | |||||
Done Inline ActionsWhy use parents[1]? Does this always exist? sybren: Why use `parents[1]`? Does this always exist? | |||||
| # Pillar extensions instantiate the PillarExtension from a sub-folder in | |||||
| # the main project (e.g. //blender_cloud/blender_cloud/__init__.py), but | |||||
Done Inline ActionsReturning None is in violation of the declared return type and the docstring. sybren: Returning `None` is in violation of the declared return type and the docstring.
| |||||
| # the translations folders is in the main project folder. | |||||
| translations_path = class_filename.parents[1] / 'translations' | |||||
| return translations_path if translations_path.is_dir() else None | |||||
| def setup_app(self, app): | def setup_app(self, app): | ||||
| """Called during app startup, after all extensions have loaded.""" | """Called during app startup, after all extensions have loaded.""" | ||||
| def sidebar_links(self, project: pillarsdk.Project) -> str: | def sidebar_links(self, project: pillarsdk.Project) -> str: | ||||
| """Returns the sidebar link(s) for the given projects. | """Returns the sidebar link(s) for the given projects. | ||||
| :returns: HTML as a string for the sidebar. | :returns: HTML as a string for the sidebar. | ||||
| """ | """ | ||||
| Show All 20 Lines | |||||
Returning "" is in violation of the declared return type.