Skip to content

Commit

Permalink
deps: Use tomli instead of toml on Python less than 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Oct 25, 2023
1 parent 34b08aa commit 37f7cf1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
7 changes: 4 additions & 3 deletions pyproject.toml
Expand Up @@ -34,10 +34,10 @@ classifiers = [
"Typing :: Typed",
]
dependencies = [
"appdirs",
"Jinja2>=2.10,<4",
"appdirs>=1.4",
"Jinja2>=2.10",
"semver>=2.13",
"toml>=0.10",
"tomli>=2.0; python_version < '3.11'",
]

[project.urls]
Expand Down Expand Up @@ -92,6 +92,7 @@ tests = [
"pytest-cov>=4.1",
"pytest-randomly>=3.15",
"pytest-xdist>=3.3",
"tomli-w>=1.0",
]
typing = [
"mypy>=1.5",
Expand Down
10 changes: 8 additions & 2 deletions src/git_changelog/cli.py
Expand Up @@ -21,7 +21,6 @@
from pathlib import Path
from typing import Any, Pattern, Sequence, TextIO

import toml
from appdirs import user_config_dir
from jinja2.exceptions import TemplateNotFound

Expand All @@ -35,6 +34,12 @@
)
from git_changelog.providers import Bitbucket, GitHub, GitLab, ProviderRefParser

# TODO: Remove once support for Python 3.10 is dropped.
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

DEFAULT_VERSION_REGEX = r"^## \[(?P<version>v?[^\]]+)"
DEFAULT_MARKER_LINE = "<!-- insertion marker -->"
DEFAULT_CHANGELOG_FILE = "CHANGELOG.md"
Expand Down Expand Up @@ -351,7 +356,8 @@ def read_config(
if not _path.exists():
continue

new_settings = toml.load(_path)
with _path.open("rb") as file:
new_settings = tomllib.load(file)
if _path.name == "pyproject.toml":
new_settings = new_settings.get("tool", {}).get("git-changelog", {}) or new_settings.get(
"tool.git-changelog",
Expand Down
11 changes: 5 additions & 6 deletions tests/test_cli.py
Expand Up @@ -7,7 +7,7 @@
from typing import TYPE_CHECKING, Any, Iterator

import pytest
import toml
import tomli_w

from git_changelog import cli, debug

Expand Down Expand Up @@ -83,7 +83,6 @@ def test_passing_repository_and_sections(tmp_path: Path, args: tuple[str]) -> No
(None, None),
("", None),
(",,", None),
("force-null", None),
("a, b, ", ["a", "b"]),
("a, , ", ["a"]),
("a, b, c", ["a", "b", "c"]),
Expand Down Expand Up @@ -116,15 +115,15 @@ def test_config_reading(
config_content: dict[str, Any] = {}

if sections is not None:
config_content["sections"] = None if sections == "force-null" else sections
config_content["sections"] = sections

if parse_refs is not None:
config_content["parse_refs"] = parse_refs

config_fname = "custom-file.toml" if is_pyproject is None else ".git-changelog.toml"
config_fname = "pyproject.toml" if is_pyproject else config_fname
(tmp_path / config_fname).write_text(
toml.dumps(
tmp_path.joinpath(config_fname).write_text(
tomli_w.dumps(
config_content if not is_pyproject else {"tool": {"git-changelog": config_content}},
),
)
Expand Down Expand Up @@ -152,7 +151,7 @@ def test_settings_warning(
args: list[str] = []
if value is not None:
(tmp_path / ".git-changelog.toml").write_text(
toml.dumps({"bump_latest": value}),
tomli_w.dumps({"bump_latest": value}),
)
else:
args = ["--bump-latest"]
Expand Down

0 comments on commit 37f7cf1

Please sign in to comment.