plaster_yaml 0.1.1__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.
CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## Version 0.1.1 - 2021-04-26
2
+
3
+ * Fix default logging
4
+
5
+ ## Version 0.1.0 - 2021-04-26
6
+
7
+ * Initial Release
@@ -0,0 +1,5 @@
1
+ import pkg_resources
2
+
3
+ from .loader import Loader # noqa
4
+
5
+ __version__ = pkg_resources.get_distribution("plaster-yaml").version
plaster_yaml/loader.py ADDED
@@ -0,0 +1,92 @@
1
+ """Implement a loader for plaster using yaml format."""
2
+ import pathlib
3
+ from logging.config import dictConfig
4
+ from typing import Callable
5
+
6
+ import pkg_resources
7
+ import plaster
8
+ import yaml
9
+
10
+ DEFAULT_LOGGING_CONFIG = {
11
+ "version": 1,
12
+ "disable_existing_loggers": False,
13
+ "formatters": {
14
+ "console": {
15
+ "format": "%(asctime)s [%(levelname)s]: %(name)s - %(message)s",
16
+ },
17
+ },
18
+ "handlers": {
19
+ "console": {
20
+ "class": "logging.StreamHandler",
21
+ "level": "INFO",
22
+ "stream": "ext://sys.stderr",
23
+ "formatter": "console",
24
+ },
25
+ },
26
+ "root": {"level": "ERROR", "handlers": ["console"]},
27
+ }
28
+
29
+
30
+ def resolve_use(use: str, entrypoint: str) -> Callable:
31
+ try:
32
+ pkg, name = use.split("#")
33
+ except ValueError:
34
+ pkg, name = use, "main"
35
+ try:
36
+ scheme, pkg = pkg.split(":")
37
+ except ValueError:
38
+ scheme = "egg"
39
+ if scheme != "egg":
40
+ raise ValueError(f"{use}: unsupported scheme {scheme}")
41
+
42
+ distribution = pkg_resources.get_distribution(pkg)
43
+ runner = distribution.get_entry_info(entrypoint, name)
44
+ return runner.load()
45
+
46
+
47
+ class Loader(plaster.ILoader):
48
+ def __init__(self, uri):
49
+ self.uri = uri
50
+
51
+ path = pathlib.Path(self.uri.path)
52
+ self.defaults = {
53
+ "__file__": str(path.absolute()),
54
+ "here": str(path.parent),
55
+ }
56
+ with open(self.uri.path, "r") as stream:
57
+ self._conf = yaml.safe_load(stream)
58
+
59
+ def get_sections(self):
60
+ return ["app"]
61
+
62
+ def get_settings(self, section=None, defaults=None):
63
+ # fallback to the fragment from config_uri if no section is given
64
+ if not section:
65
+ section = self.uri.fragment or "app"
66
+ # if section is still none we could fallback to some
67
+ # loader-specific default
68
+
69
+ result = self.defaults.copy()
70
+ if defaults is not None:
71
+ result.update(defaults)
72
+
73
+ settings = self._conf[section].copy()
74
+
75
+ for key, val in settings.items():
76
+ if isinstance(val, str):
77
+ if "%(here)s" in val:
78
+ settings[key] = val % self.defaults
79
+ return settings
80
+
81
+ def setup_logging(self, config_vars):
82
+ dictConfig(self._conf.get("logging", DEFAULT_LOGGING_CONFIG))
83
+
84
+ def get_wsgi_server(self, name=None, defaults=None):
85
+ settings = self.get_settings("server", defaults)
86
+ server = resolve_use(settings.pop("use"), "paste.server_runner")
87
+ return lambda app: server(app, self.defaults, **settings)
88
+
89
+ def get_wsgi_app(self, name=None, defaults=None):
90
+ settings = self.get_settings(name, defaults)
91
+ use = resolve_use(settings.pop("use"), "paste.app_factory")
92
+ return use(defaults, **settings)
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2021, Guillaume Gauvrit and Contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the <organization> nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,90 @@
1
+ Metadata-Version: 2.1
2
+ Name: plaster-yaml
3
+ Version: 0.1.1
4
+ Summary: A plaster plugin to configure pyramid app with Yaml
5
+ License: BSD-derived (http://www.repoze.org/LICENSE.txt)
6
+ Author: Guillaume Gauvrit
7
+ Author-email: guillaume@gauvr.it
8
+ Requires-Python: >=3.7,<4.0
9
+ Classifier: License :: Other/Proprietary License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.7
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Requires-Dist: PyYAML (>=5.4.1,<6.0.0)
15
+ Requires-Dist: plaster (>=1.0,<2.0)
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Plaster Yaml
19
+
20
+ ## Introduction
21
+
22
+ By default, Pyramid use a paste format file to loads its configuration,
23
+
24
+ here is a plugin to use a yaml file instead to configure your pyramid
25
+ application.
26
+
27
+ e.g.
28
+
29
+ ```
30
+ pserve development.yaml
31
+ ```
32
+
33
+ ## Installation
34
+
35
+ ## With poetry
36
+
37
+ ```
38
+ poetry add plaster-yaml
39
+ ```
40
+
41
+ ## With pip
42
+
43
+ ```
44
+ pip install plaster-yaml
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ## With poetry
50
+
51
+ You need to register this plugin in your `pyproject.toml`:
52
+
53
+
54
+ ```
55
+ [tool.poetry.plugins."paste.app_factory"]
56
+ main = "<PATH_TO_MODULE_CONTAINING_MAIN>:main"
57
+
58
+ [tool.poetry.plugins."plaster.loader_factory"]
59
+ "file+yaml" = "plaster_yaml:Loader"
60
+ ```
61
+
62
+ You must run `poetry install` to finalize the registration.
63
+
64
+ ## With setuptools
65
+
66
+ ```
67
+ setup(
68
+ ...,
69
+ entry_points={
70
+ 'paste.app_factory': ['main = <my_app>:main'],
71
+ 'plaster.loader_factory': ['yaml = plaster_yaml:Loader'],
72
+ ...
73
+ },
74
+ )
75
+ ```
76
+
77
+ You must run `pip install -e .` to finallize the registration.
78
+
79
+ ## Troubleshouting
80
+
81
+ If you get the following exception:
82
+
83
+ ```
84
+ plaster.exceptions.LoaderNotFound: Could not find a matching loader for the scheme "file+yaml", protocol "wsgi".
85
+ ```
86
+
87
+ It meast that you did not register the pluging. Read the usage section
88
+ for to register it properly.
89
+
90
+
@@ -0,0 +1,7 @@
1
+ CHANGELOG.md,sha256=Wp31zrmyzshlRSwNORAY5PHlt9f1OyVROLpQ6jKqeu4,103
2
+ plaster_yaml/__init__.py,sha256=Opf3zyCA1yUQCq91LYUc1z4AfIeoRgex-DVZGjajDww,127
3
+ plaster_yaml/loader.py,sha256=Ekx-wlr-LmZHDoa00vLPzGCdD2dQWOC4ULGeiKXGvHc,2788
4
+ plaster_yaml-0.1.1.dist-info/LICENSE,sha256=V32F3pzX0PY1vHGqIq3DV-as9q6cglrNA60gA70oN4U,1521
5
+ plaster_yaml-0.1.1.dist-info/WHEEL,sha256=V7iVckP-GYreevsTDnv1eAinQt_aArwnAxmnP0gygBY,83
6
+ plaster_yaml-0.1.1.dist-info/METADATA,sha256=lvVqP5FeP8wOHsuSiYgIrwDzftMKn7TlYAsVQgrBKTk,1838
7
+ plaster_yaml-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry 1.0.3
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any