diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4e52103..989de17 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 diff --git a/poetry.lock b/poetry.lock index c067b29..ebfb5cb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -183,7 +183,7 @@ typing-extensions = ">=3.7.4.2" typing-inspect = ">=0.4.0" [package.extras] -dev = ["black (==21.10b0)", "coverage (>=4.5.4)", "fixit (==0.1.1)", "flake8 (>=3.7.8)", "hypothesis (>=4.36.0)", "hypothesmith (>=0.0.4)", "jupyter (>=1.0.0)", "maturin (>=0.8.3,<0.9)", "nbsphinx (>=0.4.2)", "prompt-toolkit (>=2.0.9)", "setuptools-scm (>=6.0.1)", "sphinx-rtd-theme (>=0.4.3)", "ufmt (==1.3)", "usort (==1.0.0rc1)", "setuptools-rust (>=0.12.1)", "slotscheck (>=0.7.1)", "pyre-check (==0.9.9)"] +dev = ["pyre-check (==0.9.9)", "slotscheck (>=0.7.1)", "setuptools-rust (>=0.12.1)", "usort (==1.0.0rc1)", "ufmt (==1.3)", "sphinx-rtd-theme (>=0.4.3)", "setuptools-scm (>=6.0.1)", "prompt-toolkit (>=2.0.9)", "nbsphinx (>=0.4.2)", "maturin (>=0.8.3,<0.9)", "jupyter (>=1.0.0)", "hypothesmith (>=0.0.4)", "hypothesis (>=4.36.0)", "flake8 (>=3.7.8)", "fixit (==0.1.1)", "coverage (>=4.5.4)", "black (==21.10b0)"] [[package]] name = "mypy-extensions" @@ -292,7 +292,7 @@ coverage = {version = ">=5.2.1", extras = ["toml"]} pytest = ">=4.6" [package.extras] -testing = ["fields", "hunter", "process-tests", "six", "pytest-xdist", "virtualenv"] +testing = ["virtualenv", "pytest-xdist", "six", "process-tests", "hunter", "fields"] [[package]] name = "pytest-randomly" @@ -356,14 +356,6 @@ category = "dev" optional = false python-versions = "*" -[[package]] -name = "toml" -version = "0.10.2" -description = "Python Library for Tom's Obvious, Minimal Language" -category = "main" -optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" - [[package]] name = "tomli" version = "1.2.3" @@ -372,6 +364,14 @@ category = "dev" optional = false python-versions = ">=3.6" +[[package]] +name = "tomlkit" +version = "0.11.1" +description = "Style preserving TOML library" +category = "main" +optional = false +python-versions = ">=3.6,<4.0" + [[package]] name = "typer" version = "0.6.1" @@ -384,10 +384,10 @@ python-versions = ">=3.6" click = ">=7.1.1,<9.0.0" [package.extras] -all = ["colorama (>=0.4.3,<0.5.0)", "shellingham (>=1.3.0,<2.0.0)", "rich (>=10.11.0,<13.0.0)"] -dev = ["autoflake (>=1.3.1,<2.0.0)", "flake8 (>=3.8.3,<4.0.0)", "pre-commit (>=2.17.0,<3.0.0)"] -doc = ["mkdocs (>=1.1.2,<2.0.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "mdx-include (>=1.4.1,<2.0.0)"] -test = ["shellingham (>=1.3.0,<2.0.0)", "pytest (>=4.4.0,<5.4.0)", "pytest-cov (>=2.10.0,<3.0.0)", "coverage (>=5.2,<6.0)", "pytest-xdist (>=1.32.0,<2.0.0)", "pytest-sugar (>=0.9.4,<0.10.0)", "mypy (==0.910)", "black (>=22.3.0,<23.0.0)", "isort (>=5.0.6,<6.0.0)", "rich (>=10.11.0,<13.0.0)"] +test = ["rich (>=10.11.0,<13.0.0)", "isort (>=5.0.6,<6.0.0)", "black (>=22.3.0,<23.0.0)", "mypy (==0.910)", "pytest-sugar (>=0.9.4,<0.10.0)", "pytest-xdist (>=1.32.0,<2.0.0)", "coverage (>=5.2,<6.0)", "pytest-cov (>=2.10.0,<3.0.0)", "pytest (>=4.4.0,<5.4.0)", "shellingham (>=1.3.0,<2.0.0)"] +doc = ["mdx-include (>=1.4.1,<2.0.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "mkdocs (>=1.1.2,<2.0.0)"] +dev = ["pre-commit (>=2.17.0,<3.0.0)", "flake8 (>=3.8.3,<4.0.0)", "autoflake (>=1.3.1,<2.0.0)"] +all = ["rich (>=10.11.0,<13.0.0)", "shellingham (>=1.3.0,<2.0.0)", "colorama (>=0.4.3,<0.5.0)"] [[package]] name = "typing-extensions" @@ -437,7 +437,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytes [metadata] lock-version = "1.1" python-versions = ">=3.6.2, <4" -content-hash = "ab5305e050c049dd3e87ca241946224ff80280cab4eeafa8df9e686adf7abb55" +content-hash = "c2e6cf551855171a81949f6c4c3dfd872ef19fc09c4a2192e4f8a00165662c40" [metadata.files] atomicwrites = [ @@ -673,14 +673,14 @@ sortedcontainers = [ {file = "sortedcontainers-2.4.0-py2.py3-none-any.whl", hash = "sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0"}, {file = "sortedcontainers-2.4.0.tar.gz", hash = "sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88"}, ] -toml = [ - {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, - {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, -] tomli = [ {file = "tomli-1.2.3-py3-none-any.whl", hash = "sha256:e3069e4be3ead9668e21cb9b074cd948f7b3113fd9c8bba083f48247aab8b11c"}, {file = "tomli-1.2.3.tar.gz", hash = "sha256:05b6166bff487dc068d322585c7ea4ef78deed501cc124060e0f238e89a9231f"}, ] +tomlkit = [ + {file = "tomlkit-0.11.1-py3-none-any.whl", hash = "sha256:1c5bebdf19d5051e2e1de6cf70adfc5948d47221f097fcff7a3ffc91e953eaf5"}, + {file = "tomlkit-0.11.1.tar.gz", hash = "sha256:61901f81ff4017951119cd0d1ed9b7af31c821d6845c8c477587bbdcd5e5854e"}, +] typer = [ {file = "typer-0.6.1-py3-none-any.whl", hash = "sha256:54b19e5df18654070a82f8c2aa1da456a4ac16a2a83e6dcd9f170e291c56338e"}, {file = "typer-0.6.1.tar.gz", hash = "sha256:2d5720a5e63f73eaf31edaa15f6ab87f35f0690f8ca233017d7d23d743a91d73"}, diff --git a/pycln/__init__.py b/pycln/__init__.py index bf5bf25..6af1b07 100644 --- a/pycln/__init__.py +++ b/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 @@ -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"] diff --git a/pycln/utils/config.py b/pycln/utils/config.py index 0f35b1e..e0c2b70 100644 --- a/pycln/utils/config.py +++ b/pycln/utils/config.py @@ -6,7 +6,7 @@ from pathlib import Path from typing import List, Optional, Pattern, Set, Union -import toml +import tomlkit import typer import yaml @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 7be546f..5fce217 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/test_metadata.py b/tests/test_metadata.py index d3cb7eb..9bdd68c 100644 --- a/tests/test_metadata.py +++ b/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 @@ -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__}/"