forked from Github-Mirrors/canaille
Merge branch 'toml' into 'main'
use the standard tomllib python module instead of `toml` starting from python 3.11 See merge request yaal/canaille!167
This commit is contained in:
commit
fa17c518d2
4 changed files with 27 additions and 11 deletions
|
@ -8,6 +8,7 @@ Changed
|
||||||
|
|
||||||
- Use default python logging configuration format. :issue:`188` :pr:`165`
|
- Use default python logging configuration format. :issue:`188` :pr:`165`
|
||||||
- Bump to htmx 1.99.11 :pr:`166`
|
- Bump to htmx 1.99.11 :pr:`166`
|
||||||
|
- Use the standard tomllib python module instead of `toml` starting from python 3.11 :pr:`167`
|
||||||
|
|
||||||
[0.0.42] - 2023-12-29
|
[0.0.42] - 2023-12-29
|
||||||
=====================
|
=====================
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import smtplib
|
import smtplib
|
||||||
import socket
|
import socket
|
||||||
|
import sys
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
@ -38,14 +39,25 @@ def parse_file_keys(config):
|
||||||
return new_config
|
return new_config
|
||||||
|
|
||||||
|
|
||||||
|
def toml_content(file_path):
|
||||||
|
try:
|
||||||
|
if sys.version_info < (3, 11): # pragma: no cover
|
||||||
|
import toml
|
||||||
|
|
||||||
|
return toml.load(file_path)
|
||||||
|
|
||||||
|
import tomllib
|
||||||
|
|
||||||
|
with open(file_path, "rb") as fd:
|
||||||
|
return tomllib.load(fd)
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
raise Exception("toml library not installed. Cannot load configuration.")
|
||||||
|
|
||||||
|
|
||||||
def setup_config(app, config=None, validate_config=True):
|
def setup_config(app, config=None, validate_config=True):
|
||||||
from canaille.oidc.installation import install
|
from canaille.oidc.installation import install
|
||||||
|
|
||||||
try:
|
|
||||||
import toml
|
|
||||||
except ImportError:
|
|
||||||
toml = None
|
|
||||||
|
|
||||||
app.config.from_mapping(
|
app.config.from_mapping(
|
||||||
{
|
{
|
||||||
"SESSION_COOKIE_NAME": "canaille",
|
"SESSION_COOKIE_NAME": "canaille",
|
||||||
|
@ -53,12 +65,13 @@ def setup_config(app, config=None, validate_config=True):
|
||||||
"OAUTH2_ACCESS_TOKEN_GENERATOR": "canaille.oidc.oauth.generate_access_token",
|
"OAUTH2_ACCESS_TOKEN_GENERATOR": "canaille.oidc.oauth.generate_access_token",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if config:
|
if config:
|
||||||
app.config.from_mapping(parse_file_keys(config))
|
app.config.from_mapping(parse_file_keys(config))
|
||||||
|
|
||||||
elif "CONFIG" in os.environ:
|
elif "CONFIG" in os.environ:
|
||||||
if not toml: # pragma: no cover
|
app.config.from_mapping(parse_file_keys(toml_content(os.environ["CONFIG"])))
|
||||||
raise Exception("toml library not installed. Cannot load configuration.")
|
|
||||||
app.config.from_mapping(parse_file_keys(toml.load(os.environ.get("CONFIG"))))
|
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"No configuration file found. "
|
"No configuration file found. "
|
||||||
|
|
5
poetry.lock
generated
5
poetry.lock
generated
|
@ -1458,6 +1458,7 @@ files = [
|
||||||
{file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"},
|
{file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"},
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"},
|
{file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"},
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"},
|
{file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"},
|
||||||
|
{file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"},
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"},
|
{file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"},
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"},
|
{file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"},
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"},
|
{file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"},
|
||||||
|
@ -1954,7 +1955,7 @@ url = ["furl (>=0.4.1)"]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
description = "Python Library for Tom's Obvious, Minimal Language"
|
description = "Python Library for Tom's Obvious, Minimal Language"
|
||||||
optional = true
|
optional = false
|
||||||
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
|
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
|
||||||
files = [
|
files = [
|
||||||
{file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
|
{file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
|
||||||
|
@ -2130,4 +2131,4 @@ sql = ["passlib", "sqlalchemy", "sqlalchemy-json", "sqlalchemy-utils"]
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.8"
|
python-versions = "^3.8"
|
||||||
content-hash = "ca8c56f66b37ca75b874e2d421c5c92db41328335f5d95ef94032f2de076db74"
|
content-hash = "812f97ff8a162310df85100383de335d0c53f06b1d12a4ac9fb5145ff51789dc"
|
||||||
|
|
|
@ -48,7 +48,7 @@ flask-babel = {version = "^4.0.0", optional=true}
|
||||||
flask-themer = {version = "^2.0.0", optional=true}
|
flask-themer = {version = "^2.0.0", optional=true}
|
||||||
pycountry = {version = ">=22.1.10", optional=true}
|
pycountry = {version = ">=22.1.10", optional=true}
|
||||||
pytz = {version = ">=2022.7", optional=true}
|
pytz = {version = ">=2022.7", optional=true}
|
||||||
toml = {version = "^0.10.0", optional=true}
|
toml = {version = "^0.10.0", optional=true, python = "<3.11"}
|
||||||
|
|
||||||
# extra : oidc
|
# extra : oidc
|
||||||
authlib = {version = "^1.2.1", optional=true}
|
authlib = {version = "^1.2.1", optional=true}
|
||||||
|
@ -87,6 +87,7 @@ pytest-lazy-fixture = "==0.6.3"
|
||||||
pytest-smtpd = "^0.1.0"
|
pytest-smtpd = "^0.1.0"
|
||||||
pytest-xdist = "^3.3.1"
|
pytest-xdist = "^3.3.1"
|
||||||
slapd = "*"
|
slapd = "*"
|
||||||
|
toml = "^0.10.0"
|
||||||
|
|
||||||
[tool.poetry.group.demo]
|
[tool.poetry.group.demo]
|
||||||
optional = true
|
optional = true
|
||||||
|
|
Loading…
Reference in a new issue