summaryrefslogtreecommitdiff
path: root/dev-vcs/pre-commit/files/pre-commit-2.20.0-no_toml.patch
blob: f7f335c29e14792b86e5f448a4b35ff4a12b9a51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Backported upstream commit e703982de45ac64492897b25fa4edbdb8da10e62.

--- a/pre_commit/languages/rust.py
+++ b/pre_commit/languages/rust.py
@@ -5,8 +5,6 @@
 from typing import Generator
 from typing import Sequence
 
-import toml
-
 import pre_commit.constants as C
 from pre_commit.envcontext import envcontext
 from pre_commit.envcontext import PatchesT
@@ -38,18 +36,16 @@
 
 
 def _add_dependencies(
-        cargo_toml_path: str,
+        prefix: Prefix,
         additional_dependencies: set[str],
 ) -> None:
-    with open(cargo_toml_path, 'r+') as 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)
-        f.truncate()
+    crates = []
+    for dep in additional_dependencies:
+        name, _, spec = dep.partition(':')
+        crate = f'{name}@{spec or "*"}'
+        crates.append(crate)
+
+    helpers.run_setup_cmd(prefix, ('cargo', 'add', *crates))
 
 
 def install_environment(
@@ -77,9 +73,6 @@
     }
     lib_deps = set(additional_dependencies) - cli_deps
 
-    if len(lib_deps) > 0:
-        _add_dependencies(prefix.path('Cargo.toml'), lib_deps)
-
     with clean_path_on_failure(directory):
         packages_to_install: set[tuple[str, ...]] = {('--path', '.')}
         for cli_dep in cli_deps:
@@ -90,6 +83,9 @@
             else:
                 packages_to_install.add((package,))
 
+        if len(lib_deps) > 0:
+            _add_dependencies(prefix, lib_deps)
+
         for args in packages_to_install:
             cmd_output_b(
                 'cargo', 'install', '--bins', '--root', directory, *args,
--- a/setup.cfg
+++ b/setup.cfg
@@ -27,7 +27,6 @@
     identify>=1.0.0
     nodeenv>=0.11.1
     pyyaml>=5.1
-    toml
     virtualenv>=20.0.8
     importlib-metadata;python_version<"3.8"
 python_requires = >=3.7
--- a/tests/repository_test.py
+++ b/tests/repository_test.py
@@ -485,7 +485,7 @@
     path = make_repo(tempdir_factory, 'rust_hooks_repo')
     config = make_config_from_repo(path)
     # A small rust package with no dependencies.
-    deps = ['shellharden:3.1.0']
+    deps = ['shellharden:3.1.0', 'git-version']
     config['hooks'][0]['additional_dependencies'] = deps
     hook = _get_hook(config, store, 'rust-hook')
     binaries = os.listdir(