plaster_yaml 0.1.1__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.
- plaster_yaml-0.1.1/CHANGELOG.md +7 -0
- plaster_yaml-0.1.1/LICENSE +24 -0
- plaster_yaml-0.1.1/PKG-INFO +90 -0
- plaster_yaml-0.1.1/README.md +72 -0
- plaster_yaml-0.1.1/pyproject.toml +27 -0
- plaster_yaml-0.1.1/setup.py +34 -0
- plaster_yaml-0.1.1/src/plaster_yaml/__init__.py +5 -0
- plaster_yaml-0.1.1/src/plaster_yaml/loader.py +92 -0
|
@@ -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,72 @@
|
|
|
1
|
+
# Plaster Yaml
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
By default, Pyramid use a paste format file to loads its configuration,
|
|
6
|
+
|
|
7
|
+
here is a plugin to use a yaml file instead to configure your pyramid
|
|
8
|
+
application.
|
|
9
|
+
|
|
10
|
+
e.g.
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
pserve development.yaml
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
## With poetry
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
poetry add plaster-yaml
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## With pip
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
pip install plaster-yaml
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
## With poetry
|
|
33
|
+
|
|
34
|
+
You need to register this plugin in your `pyproject.toml`:
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
[tool.poetry.plugins."paste.app_factory"]
|
|
39
|
+
main = "<PATH_TO_MODULE_CONTAINING_MAIN>:main"
|
|
40
|
+
|
|
41
|
+
[tool.poetry.plugins."plaster.loader_factory"]
|
|
42
|
+
"file+yaml" = "plaster_yaml:Loader"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
You must run `poetry install` to finalize the registration.
|
|
46
|
+
|
|
47
|
+
## With setuptools
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
setup(
|
|
51
|
+
...,
|
|
52
|
+
entry_points={
|
|
53
|
+
'paste.app_factory': ['main = <my_app>:main'],
|
|
54
|
+
'plaster.loader_factory': ['yaml = plaster_yaml:Loader'],
|
|
55
|
+
...
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
You must run `pip install -e .` to finallize the registration.
|
|
61
|
+
|
|
62
|
+
## Troubleshouting
|
|
63
|
+
|
|
64
|
+
If you get the following exception:
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
plaster.exceptions.LoaderNotFound: Could not find a matching loader for the scheme "file+yaml", protocol "wsgi".
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
It meast that you did not register the pluging. Read the usage section
|
|
71
|
+
for to register it properly.
|
|
72
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "plaster_yaml"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "A plaster plugin to configure pyramid app with Yaml"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = ["Guillaume Gauvrit <guillaume@gauvr.it>"]
|
|
7
|
+
include = ["CHANGELOG.md"]
|
|
8
|
+
license = "BSD-derived (http://www.repoze.org/LICENSE.txt)"
|
|
9
|
+
|
|
10
|
+
[tool.poetry.dependencies]
|
|
11
|
+
python = "^3.7"
|
|
12
|
+
plaster = "^1.0"
|
|
13
|
+
PyYAML = "^5.4.1"
|
|
14
|
+
|
|
15
|
+
[tool.poetry.dev-dependencies]
|
|
16
|
+
black = "^21.4b0"
|
|
17
|
+
isort = "^5.8.0"
|
|
18
|
+
# Tests
|
|
19
|
+
gunicorn = "^20.1.0"
|
|
20
|
+
PasteDeploy = "^2.1.1"
|
|
21
|
+
pytest = "^5.2"
|
|
22
|
+
waitress = "^2.0.0"
|
|
23
|
+
pyramid-helloworld = "^0.1.2"
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["poetry-core>=1.0.0"]
|
|
27
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
package_dir = \
|
|
5
|
+
{'': 'src'}
|
|
6
|
+
|
|
7
|
+
packages = \
|
|
8
|
+
['plaster_yaml']
|
|
9
|
+
|
|
10
|
+
package_data = \
|
|
11
|
+
{'': ['*']}
|
|
12
|
+
|
|
13
|
+
install_requires = \
|
|
14
|
+
['PyYAML>=5.4.1,<6.0.0', 'plaster>=1.0,<2.0']
|
|
15
|
+
|
|
16
|
+
setup_kwargs = {
|
|
17
|
+
'name': 'plaster-yaml',
|
|
18
|
+
'version': '0.1.1',
|
|
19
|
+
'description': 'A plaster plugin to configure pyramid app with Yaml',
|
|
20
|
+
'long_description': '# Plaster Yaml\n\n## Introduction\n\nBy default, Pyramid use a paste format file to loads its configuration,\n\nhere is a plugin to use a yaml file instead to configure your pyramid\napplication.\n\ne.g.\n\n```\npserve development.yaml\n```\n\n## Installation\n\n## With poetry\n\n```\npoetry add plaster-yaml\n```\n\n## With pip\n\n```\npip install plaster-yaml\n```\n\n## Usage\n\n## With poetry\n\nYou need to register this plugin in your `pyproject.toml`:\n\n\n```\n[tool.poetry.plugins."paste.app_factory"]\nmain = "<PATH_TO_MODULE_CONTAINING_MAIN>:main"\n\n[tool.poetry.plugins."plaster.loader_factory"]\n"file+yaml" = "plaster_yaml:Loader"\n```\n\nYou must run `poetry install` to finalize the registration.\n\n## With setuptools\n\n```\nsetup(\n ...,\n entry_points={\n \'paste.app_factory\': [\'main = <my_app>:main\'],\n \'plaster.loader_factory\': [\'yaml = plaster_yaml:Loader\'],\n ...\n },\n)\n```\n\nYou must run `pip install -e .` to finallize the registration.\n\n## Troubleshouting\n\nIf you get the following exception:\n\n```\nplaster.exceptions.LoaderNotFound: Could not find a matching loader for the scheme "file+yaml", protocol "wsgi".\n```\n\nIt meast that you did not register the pluging. Read the usage section\nfor to register it properly.\n\n',
|
|
21
|
+
'author': 'Guillaume Gauvrit',
|
|
22
|
+
'author_email': 'guillaume@gauvr.it',
|
|
23
|
+
'maintainer': None,
|
|
24
|
+
'maintainer_email': None,
|
|
25
|
+
'url': None,
|
|
26
|
+
'package_dir': package_dir,
|
|
27
|
+
'packages': packages,
|
|
28
|
+
'package_data': package_data,
|
|
29
|
+
'install_requires': install_requires,
|
|
30
|
+
'python_requires': '>=3.7,<4.0',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
setup(**setup_kwargs)
|
|
@@ -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)
|