From a12065d16c5fd32ea7386f3b5027c08f7fdd13c2 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 16 Sep 2022 16:28:44 +0200 Subject: [PATCH] Migrate from dependency toml because it has not yet reached v1.0 --- pre_commit/languages/rust.py | 10 +++++++--- setup.cfg | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pre_commit/languages/rust.py b/pre_commit/languages/rust.py index 01c37306..76dd8145 100644 --- a/pre_commit/languages/rust.py +++ b/pre_commit/languages/rust.py @@ -5,7 +5,11 @@ import os.path from typing import Generator from typing import Sequence -import toml +try: + from tomllib import load as toml_load +except ModuleNotFoundError: # Python < 3.11 + from tomli import load as toml_load +from tomli_w import dump as toml_dump import pre_commit.constants as C from pre_commit.envcontext import envcontext @@ -42,13 +46,13 @@ def _add_dependencies( additional_dependencies: set[str], ) -> None: with open(cargo_toml_path, 'r+') as f: - cargo_toml = toml.load(f) + cargo_toml = toml_load(f) cargo_toml.setdefault('dependencies', {}) for dep in additional_dependencies: name, _, spec = dep.partition(':') cargo_toml['dependencies'][name] = spec or '*' f.seek(0) - toml.dump(cargo_toml, f) + toml_dump(cargo_toml, f) f.truncate() diff --git a/setup.cfg b/setup.cfg index afe56848..d5d4ce0d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,7 +23,8 @@ install_requires = identify>=1.0.0 nodeenv>=0.11.1 pyyaml>=5.1 - toml + tomli;python_version<"3.11" + tomli-w virtualenv>=20.10.0 importlib-metadata;python_version<"3.8" python_requires = >=3.7