sync-pre-commit-deps 0.0.1__tar.gz

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,65 @@
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
+
18
+ sync-pre-commit-deps
19
+ ====================
20
+
21
+ Sync pre-commit hook dependencies based on other installed hooks
22
+
23
+ ## install (standalone)
24
+
25
+ ```bash
26
+ pip install sync-pre-commit-deps
27
+ ```
28
+
29
+ ## install as a pre-commit hook (recommended)
30
+
31
+ See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
32
+
33
+ Sample `.pre-commit-config.yaml`:
34
+
35
+ ```yaml
36
+ - repo: https://github.com/mxr/sync-pre-commit-deps
37
+ rev: v0.0.1
38
+ hooks:
39
+ - id: sync-pre-commit-deps
40
+ ```
41
+
42
+ ## cli
43
+
44
+ ```console
45
+ $ sync-pre-commit-deps path/to/.pre-commit-config.yaml
46
+ ```
47
+
48
+ ## what it does
49
+
50
+ 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`.
51
+
52
+ ```diff
53
+ repos:
54
+ - repo: https://github.com/PyCQA/flake8
55
+ rev: 6.0.0
56
+ hooks:
57
+ - id: flake8
58
+ - repo: https://github.com/asottile/yesqa
59
+ rev: v1.5.0
60
+ hooks:
61
+ - id: yesqa
62
+ additional_dependencies:
63
+ - - flake8==5.0.0
64
+ + - flake8==6.0.0
65
+ ```
@@ -0,0 +1,48 @@
1
+ sync-pre-commit-deps
2
+ ====================
3
+
4
+ Sync pre-commit hook dependencies based on other installed hooks
5
+
6
+ ## install (standalone)
7
+
8
+ ```bash
9
+ pip install sync-pre-commit-deps
10
+ ```
11
+
12
+ ## install as a pre-commit hook (recommended)
13
+
14
+ See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
15
+
16
+ Sample `.pre-commit-config.yaml`:
17
+
18
+ ```yaml
19
+ - repo: https://github.com/mxr/sync-pre-commit-deps
20
+ rev: v0.0.1
21
+ hooks:
22
+ - id: sync-pre-commit-deps
23
+ ```
24
+
25
+ ## cli
26
+
27
+ ```console
28
+ $ sync-pre-commit-deps path/to/.pre-commit-config.yaml
29
+ ```
30
+
31
+ ## what it does
32
+
33
+ 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`.
34
+
35
+ ```diff
36
+ repos:
37
+ - repo: https://github.com/PyCQA/flake8
38
+ rev: 6.0.0
39
+ hooks:
40
+ - id: flake8
41
+ - repo: https://github.com/asottile/yesqa
42
+ rev: v1.5.0
43
+ hooks:
44
+ - id: yesqa
45
+ additional_dependencies:
46
+ - - flake8==5.0.0
47
+ + - flake8==6.0.0
48
+ ```
@@ -0,0 +1,57 @@
1
+ [metadata]
2
+ name = sync_pre_commit_deps
3
+ version = 0.0.1
4
+ description = apply a consistent format to `setup.cfg` files
5
+ long_description = file: README.md
6
+ long_description_content_type = text/markdown
7
+ url = https://github.com/mxr/sync-pre-commit-deps
8
+ author = Max R
9
+ author_email = maxr@outlook.com
10
+ license = MIT
11
+ license_files = LICENSE
12
+ classifiers =
13
+ License :: OSI Approved :: MIT License
14
+ Programming Language :: Python :: 3
15
+ Programming Language :: Python :: 3 :: Only
16
+ Programming Language :: Python :: Implementation :: CPython
17
+ Programming Language :: Python :: Implementation :: PyPy
18
+
19
+ [options]
20
+ py_modules = sync_pre_commit_deps
21
+ install_requires =
22
+ ruamel.yaml>=0.17
23
+ python_requires = >=3.8
24
+
25
+ [options.entry_points]
26
+ console_scripts =
27
+ sync-pre-commit-deps=sync_pre_commit_deps:main
28
+
29
+ [bdist_wheel]
30
+ universal = True
31
+
32
+ [coverage:run]
33
+ plugins = covdefaults
34
+
35
+ [flake8]
36
+ max-line-length = 88
37
+ extend-ignore = E203
38
+ min_python_version = 3.8
39
+
40
+ [mypy]
41
+ check_untyped_defs = true
42
+ disallow_any_generics = true
43
+ disallow_incomplete_defs = true
44
+ disallow_untyped_defs = true
45
+ warn_redundant_casts = true
46
+ warn_unused_ignores = true
47
+
48
+ [mypy-testing.*]
49
+ disallow_untyped_defs = false
50
+
51
+ [mypy-tests.*]
52
+ disallow_untyped_defs = false
53
+
54
+ [egg_info]
55
+ tag_build =
56
+ tag_date = 0
57
+
@@ -0,0 +1,5 @@
1
+ from __future__ import annotations
2
+
3
+ from setuptools import setup
4
+
5
+ setup()
@@ -0,0 +1,65 @@
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
+
18
+ sync-pre-commit-deps
19
+ ====================
20
+
21
+ Sync pre-commit hook dependencies based on other installed hooks
22
+
23
+ ## install (standalone)
24
+
25
+ ```bash
26
+ pip install sync-pre-commit-deps
27
+ ```
28
+
29
+ ## install as a pre-commit hook (recommended)
30
+
31
+ See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
32
+
33
+ Sample `.pre-commit-config.yaml`:
34
+
35
+ ```yaml
36
+ - repo: https://github.com/mxr/sync-pre-commit-deps
37
+ rev: v0.0.1
38
+ hooks:
39
+ - id: sync-pre-commit-deps
40
+ ```
41
+
42
+ ## cli
43
+
44
+ ```console
45
+ $ sync-pre-commit-deps path/to/.pre-commit-config.yaml
46
+ ```
47
+
48
+ ## what it does
49
+
50
+ 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`.
51
+
52
+ ```diff
53
+ repos:
54
+ - repo: https://github.com/PyCQA/flake8
55
+ rev: 6.0.0
56
+ hooks:
57
+ - id: flake8
58
+ - repo: https://github.com/asottile/yesqa
59
+ rev: v1.5.0
60
+ hooks:
61
+ - id: yesqa
62
+ additional_dependencies:
63
+ - - flake8==5.0.0
64
+ + - flake8==6.0.0
65
+ ```
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ setup.cfg
4
+ setup.py
5
+ sync_pre_commit_deps.py
6
+ sync_pre_commit_deps.egg-info/PKG-INFO
7
+ sync_pre_commit_deps.egg-info/SOURCES.txt
8
+ sync_pre_commit_deps.egg-info/dependency_links.txt
9
+ sync_pre_commit_deps.egg-info/entry_points.txt
10
+ sync_pre_commit_deps.egg-info/requires.txt
11
+ sync_pre_commit_deps.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ sync-pre-commit-deps = sync_pre_commit_deps:main
@@ -0,0 +1 @@
1
+ ruamel.yaml>=0.17
@@ -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())