Skip to content

Commit

Permalink
Remove TOML dependency (#82)
Browse files Browse the repository at this point in the history
* Remove TOML dependency in favour of tomllib from stdlib

* Update Metricity to use tomllib
  • Loading branch information
jb3 authored Sep 13, 2023
1 parent 15c40d2 commit 4f1bceb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 42 deletions.
6 changes: 3 additions & 3 deletions metricity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import asyncio
import logging
import os
import tomllib
from pathlib import Path
from typing import TYPE_CHECKING

import coloredlogs
import toml
from pydis_core.utils import apply_monkey_patches

from metricity.config import PythonConfig
Expand All @@ -16,8 +16,8 @@
from metricity.bot import Bot

# Read the version from the pyproject.toml file.
with Path.open("pyproject.toml") as f:
package_vers = toml.load(f)["tool"]["poetry"]["version"]
with Path.open("pyproject.toml", "rb") as f:
package_vers = tomllib.load(f)["tool"]["poetry"]["version"]

__version__ = package_vers

Expand Down
10 changes: 5 additions & 5 deletions metricity/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Configuration reader for Metricity."""
import logging
import tomllib
from os import environ
from pathlib import Path
from typing import Any

import toml
from deepmerge import Merger
from dotenv import load_dotenv

Expand All @@ -29,16 +29,16 @@ def get_section(section: str) -> dict[str, Any]:
if not default_config_file.exists():
raise MetricityConfigurationError("config-default.toml is missing")

with default_config_file.open() as default_config_file:
default_config = toml.load(default_config_file)
with default_config_file.open("rb") as default_config_file:
default_config = tomllib.load(default_config_file)

# Load user configuration
user_config = {}
user_config_location = Path(environ.get("CONFIG_LOCATION", "./config.toml"))

if user_config_location.exists():
with Path.open(user_config_location) as user_config_file:
user_config = toml.load(user_config_file)
with Path.open(user_config_location, "rb") as user_config_file:
user_config = tomllib.load(user_config_file)

# Merge the configuration
merger = Merger(
Expand Down
45 changes: 12 additions & 33 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ coloredlogs = "15.0.1"
deepmerge = "1.1.0"
sqlalchemy = { extras = ["asyncio"], version = "2.0.20" }
python-dotenv = "1.0.0"
toml = "0.10.2"
asyncpg = "0.28.0"

[tool.poetry.dev-dependencies]
Expand Down

0 comments on commit 4f1bceb

Please sign in to comment.