Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remplacement de toml par tomli #6418

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ lxml==4.9.1
Pillow==9.2.0
pymemcache==3.5.2
requests==2.28.1
toml==0.10.2

# Api dependencies
django-cors-headers==3.13.0
Expand All @@ -33,3 +32,7 @@ drf_yasg==1.21.3
# Dependencies for slug generation, please be extra careful with those
django-uuslug==2.0.0
python-slugify==6.1.2

# tomllib was added to the standard library in Python 3.11
# tomli is only needed for older Python versions
tomli==2.0.1 ; python_version < "3.11"
12 changes: 10 additions & 2 deletions zds/settings/abstract_base/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import os
from pathlib import Path
import toml

Situphen marked this conversation as resolved.
Show resolved Hide resolved
# tomllib was added to the standard library in Python 3.11
# tomli is only needed for older Python versions
# both libraries are strictly identical, only the name differs
try:
import tomllib
except ModuleNotFoundError:
import tomli as tomllib


default_config_path = str(Path.cwd() / "config.toml")
config_path = os.environ.get("ZDS_CONFIG", default_config_path)

try:
config = toml.load(config_path)
with open(config_path, "rb") as f:
config = tomllib.load(f)
print(f"Using the config file at {config_path!r}")
except OSError:
config = {}
Expand Down