Skip to content

Commit

Permalink
Change: toml ~> tomlkit (supporting toml v1.0.0). (#165)
Browse files Browse the repository at this point in the history
* Change: toml ~> tomlkit (supporting toml v1.0.0).

* Adding CHANGELOG

* Use tomlkit instead.
  • Loading branch information
hadialqattan committed Jul 28, 2022
1 parent f6d3f13 commit a72d59b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 26 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Expand Up @@ -10,6 +10,10 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Changed

- [Now Pycln uses `tomlkit` instead of `toml` library for parsing toml config files in order to support toml v1.0.0 by @hadialqattan](https://github.com/hadialqattan/pycln/pull/165)

## [2.0.4] - 2022-07-18 (a quick release solving v2.0.3 problem \[affects PY3.9+\])

### Fixed
Expand Down
38 changes: 19 additions & 19 deletions poetry.lock

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

7 changes: 5 additions & 2 deletions pycln/__init__.py
@@ -1,9 +1,10 @@
import io
import os
import sys
import tokenize
from pathlib import Path

import toml
import tomlkit
import typer

#: Add vendor directory to module search path
Expand All @@ -20,7 +21,9 @@

ISWIN = os.name == "nt"
PYPROJECT_PATH = Path(__file__).parent.parent.joinpath("pyproject.toml")
pycln = toml.load(PYPROJECT_PATH)["tool"]["poetry"]

with tokenize.open(PYPROJECT_PATH) as toml_f:
pycln = tomlkit.parse(toml_f.read())["tool"]["poetry"]

__name__ = pycln["name"]
__version__ = pycln["version"]
Expand Down
5 changes: 3 additions & 2 deletions pycln/utils/config.py
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from typing import List, Optional, Pattern, Set, Union

import toml
import tomlkit
import typer
import yaml

Expand Down Expand Up @@ -179,7 +179,8 @@ def cast_bool(v: str) -> Union[str, bool]:

def _parse_toml(self) -> None:
# Parse `.toml` file.
parsed_toml = toml.load(self._path)
with tokenize.open(self._path) as stream:
parsed_toml = tomlkit.parse(stream.read())
tool, pycln = self._section.split(".")
configs = parsed_toml.get(tool, {}).get(pycln, {})
self._config_loader(configs)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -26,11 +26,11 @@ pycln = "pycln.cli:app"
[tool.poetry.dependencies]
python = ">=3.6.2, <4"
typer = ">=0.4.1,<0.7.0"
toml = "^0.10.1"
dataclasses = {version = "^0.7", python = "3.6"}
libcst = ">=0.3.10,<0.5.0"
pyyaml = ">=5.3.1,<7.0.0"
pathspec = "^0.9.0"
tomlkit = "^0.11.1"

[tool.poetry.dev-dependencies]
requests = "^2.24.0"
Expand Down
7 changes: 5 additions & 2 deletions tests/test_metadata.py
@@ -1,11 +1,12 @@
"""pycln `__init__.py`/`pyproject.toml` metadata tests."""
# pylint: disable=R0201,W0613
import sys
import tokenize
from os import getenv

import pytest
import requests
import toml
import tomlkit
from semver import VersionInfo
from typer import Exit

Expand All @@ -21,7 +22,9 @@
from .utils import sysu

# Constants.
PYCLN_METADATA = toml.load(PYPROJECT_PATH)["tool"]["poetry"]
with tokenize.open(PYPROJECT_PATH) as toml_f:
PYCLN_METADATA = tomlkit.parse(toml_f.read())["tool"]["poetry"]

PYCLN_PYPI_JSON_URL = f"https://pypi.org/pypi/{__name__}/json"
PYCLN_PYPI_URL = f"https://pypi.org/project/{__name__}/"

Expand Down

0 comments on commit a72d59b

Please sign in to comment.