sync-pre-commit-deps 0.0.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Max R
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.1
2
+ Name: sync-pre-commit-deps
3
+ Version: 0.0.1
4
+ Summary: apply a consistent format to `setup.cfg` files
5
+ Home-page: https://github.com/mxr/sync-pre-commit-deps
6
+ Author: Max R
7
+ Author-email: maxr@outlook.com
8
+ License: MIT
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: Implementation :: CPython
13
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: ruamel.yaml (>=0.17)
18
+
19
+ sync-pre-commit-deps
20
+ ====================
21
+
22
+ Sync pre-commit hook dependencies based on other installed hooks
23
+
24
+ ## install (standalone)
25
+
26
+ ```bash
27
+ pip install sync-pre-commit-deps
28
+ ```
29
+
30
+ ## install as a pre-commit hook (recommended)
31
+
32
+ See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
33
+
34
+ Sample `.pre-commit-config.yaml`:
35
+
36
+ ```yaml
37
+ - repo: https://github.com/mxr/sync-pre-commit-deps
38
+ rev: v0.0.1
39
+ hooks:
40
+ - id: sync-pre-commit-deps
41
+ ```
42
+
43
+ ## cli
44
+
45
+ ```console
46
+ $ sync-pre-commit-deps path/to/.pre-commit-config.yaml
47
+ ```
48
+
49
+ ## what it does
50
+
51
+ Ensures tools which declare `flake8` and `black` as additional dependencies will have those versions synced with the `flake8` and `black` versions in the rest of the config. For example, `flake8` under `yesqa` is updated from `5.0.0` to `6.0.0`.
52
+
53
+ ```diff
54
+ repos:
55
+ - repo: https://github.com/PyCQA/flake8
56
+ rev: 6.0.0
57
+ hooks:
58
+ - id: flake8
59
+ - repo: https://github.com/asottile/yesqa
60
+ rev: v1.5.0
61
+ hooks:
62
+ - id: yesqa
63
+ additional_dependencies:
64
+ - - flake8==5.0.0
65
+ + - flake8==6.0.0
66
+ ```
@@ -0,0 +1,7 @@
1
+ sync_pre_commit_deps.py,sha256=d9jE4m8tbRsBydNNMDeDz4FlK0PgfbVTMon3jTQGJwU,1690
2
+ sync_pre_commit_deps-0.0.1.dist-info/LICENSE,sha256=Uw07TX_qcYMYkCNciCEJdj9GDE2XGlpDpCafmlLpI18,1062
3
+ sync_pre_commit_deps-0.0.1.dist-info/METADATA,sha256=FIUL1_F_X5qQffM9VxSiVlOp6OeuQArlPsPpdojbH2g,1752
4
+ sync_pre_commit_deps-0.0.1.dist-info/WHEEL,sha256=a-zpFRIJzOq5QfuhBzbhiA1eHTzNCJn8OdRvhdNX0Rk,110
5
+ sync_pre_commit_deps-0.0.1.dist-info/entry_points.txt,sha256=vgxjDd6toUrbNiQWzlF3iXwZk4sm72lSHASqMqhIR6c,67
6
+ sync_pre_commit_deps-0.0.1.dist-info/top_level.txt,sha256=Z3C0kUg8cWsx_bsF7MdD-RWHUgnAP4VZr0nowAUi1TA,21
7
+ sync_pre_commit_deps-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.40.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
6
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ sync-pre-commit-deps = sync_pre_commit_deps:main
@@ -0,0 +1 @@
1
+ sync_pre_commit_deps
@@ -0,0 +1,62 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ from collections.abc import Sequence
5
+
6
+ import ruamel.yaml
7
+
8
+ SUPPORTED = frozenset(
9
+ (
10
+ "black",
11
+ "flake8",
12
+ )
13
+ )
14
+
15
+
16
+ def main(argv: Sequence[str] | None = None) -> int:
17
+ parser = argparse.ArgumentParser()
18
+ parser.add_argument("filename", default=".pre-commit-config.yaml")
19
+
20
+ args = parser.parse_args(argv)
21
+ filename: str = args.filename
22
+
23
+ # match pre-commit config as documented
24
+ # TODO - support round-tripping
25
+ yaml = ruamel.yaml.YAML()
26
+ yaml.preserve_quotes = True
27
+ yaml.indent(mapping=4, sequence=4)
28
+
29
+ with open(filename) as f:
30
+ loaded = yaml.load(f)
31
+
32
+ # TODO - validate schema?
33
+ versions = {}
34
+ for repo in loaded["repos"]:
35
+ for hook in repo["hooks"]:
36
+ if (hid := hook["id"]) in SUPPORTED:
37
+ versions[hid] = repo["rev"]
38
+
39
+ updated = []
40
+ for repo in loaded["repos"]:
41
+ for hook in repo["hooks"]:
42
+ for i, dep in enumerate(hook.get("additional_dependencies", ())):
43
+ name, _, cur_version = dep.partition("==")
44
+ target_version = versions.get(name, cur_version)
45
+ if target_version != cur_version:
46
+ hook["additional_dependencies"][i] = f"{name}=={target_version}"
47
+ updated.append((hook["id"], name))
48
+
49
+ if updated:
50
+ print(f"Writing updates to {filename}:")
51
+ for hid, name in updated:
52
+ print(f"\tSetting {hid!r} dependency {name!r} to {versions[name]}")
53
+
54
+ with open(filename, "w+") as f:
55
+ yaml.dump(loaded, f)
56
+ return 1
57
+
58
+ return 0
59
+
60
+
61
+ if __name__ == "__main__":
62
+ raise SystemExit(main())