mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 10:01:46 +04:00
Migrate from dependency toml because it has not yet reached v1.0
This commit is contained in:
parent
3fe38dff05
commit
a12065d16c
2 changed files with 9 additions and 4 deletions
|
|
@ -5,7 +5,11 @@ import os.path
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
from typing import Sequence
|
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
|
import pre_commit.constants as C
|
||||||
from pre_commit.envcontext import envcontext
|
from pre_commit.envcontext import envcontext
|
||||||
|
|
@ -42,13 +46,13 @@ def _add_dependencies(
|
||||||
additional_dependencies: set[str],
|
additional_dependencies: set[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
with open(cargo_toml_path, 'r+') as f:
|
with open(cargo_toml_path, 'r+') as f:
|
||||||
cargo_toml = toml.load(f)
|
cargo_toml = toml_load(f)
|
||||||
cargo_toml.setdefault('dependencies', {})
|
cargo_toml.setdefault('dependencies', {})
|
||||||
for dep in additional_dependencies:
|
for dep in additional_dependencies:
|
||||||
name, _, spec = dep.partition(':')
|
name, _, spec = dep.partition(':')
|
||||||
cargo_toml['dependencies'][name] = spec or '*'
|
cargo_toml['dependencies'][name] = spec or '*'
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
toml.dump(cargo_toml, f)
|
toml_dump(cargo_toml, f)
|
||||||
f.truncate()
|
f.truncate()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ install_requires =
|
||||||
identify>=1.0.0
|
identify>=1.0.0
|
||||||
nodeenv>=0.11.1
|
nodeenv>=0.11.1
|
||||||
pyyaml>=5.1
|
pyyaml>=5.1
|
||||||
toml
|
tomli;python_version<"3.11"
|
||||||
|
tomli-w
|
||||||
virtualenv>=20.10.0
|
virtualenv>=20.10.0
|
||||||
importlib-metadata;python_version<"3.8"
|
importlib-metadata;python_version<"3.8"
|
||||||
python_requires = >=3.7
|
python_requires = >=3.7
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue