sync-pre-commit-deps 0.0.1__tar.gz → 0.0.3__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.
@@ -1,8 +1,8 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
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
3
+ Version: 0.0.3
4
+ Summary: Sync pre-commit hook dependencies based on other installed hooks
5
+ Home-page: https://github.com/pre-commit/sync-pre-commit-deps
6
6
  Author: Max R
7
7
  Author-email: maxr@outlook.com
8
8
  License: MIT
@@ -11,9 +11,10 @@ Classifier: Programming Language :: Python :: 3
11
11
  Classifier: Programming Language :: Python :: 3 :: Only
12
12
  Classifier: Programming Language :: Python :: Implementation :: CPython
13
13
  Classifier: Programming Language :: Python :: Implementation :: PyPy
14
- Requires-Python: >=3.8
14
+ Requires-Python: >=3.9
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
+ Requires-Dist: ruamel.yaml>=0.17
17
18
 
18
19
  sync-pre-commit-deps
19
20
  ====================
@@ -33,8 +34,8 @@ See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
33
34
  Sample `.pre-commit-config.yaml`:
34
35
 
35
36
  ```yaml
36
- - repo: https://github.com/mxr/sync-pre-commit-deps
37
- rev: v0.0.1
37
+ - repo: https://github.com/pre-commit/sync-pre-commit-deps
38
+ rev: v0.0.3
38
39
  hooks:
39
40
  - id: sync-pre-commit-deps
40
41
  ```
@@ -47,7 +48,7 @@ $ sync-pre-commit-deps path/to/.pre-commit-config.yaml
47
48
 
48
49
  ## what it does
49
50
 
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
+ Ensures tools which declare `flake8`, `black`, or `mypy` as additional dependencies will have those versions synced with the `flake8`, `black`, or `mypy` versions in the rest of the config. For example, `flake8` under `yesqa` is updated from `5.0.0` to `6.0.0`.
51
52
 
52
53
  ```diff
53
54
  repos:
@@ -16,8 +16,8 @@ See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
16
16
  Sample `.pre-commit-config.yaml`:
17
17
 
18
18
  ```yaml
19
- - repo: https://github.com/mxr/sync-pre-commit-deps
20
- rev: v0.0.1
19
+ - repo: https://github.com/pre-commit/sync-pre-commit-deps
20
+ rev: v0.0.3
21
21
  hooks:
22
22
  - id: sync-pre-commit-deps
23
23
  ```
@@ -30,7 +30,7 @@ $ sync-pre-commit-deps path/to/.pre-commit-config.yaml
30
30
 
31
31
  ## what it does
32
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`.
33
+ Ensures tools which declare `flake8`, `black`, or `mypy` as additional dependencies will have those versions synced with the `flake8`, `black`, or `mypy` versions in the rest of the config. For example, `flake8` under `yesqa` is updated from `5.0.0` to `6.0.0`.
34
34
 
35
35
  ```diff
36
36
  repos:
@@ -1,10 +1,10 @@
1
1
  [metadata]
2
2
  name = sync_pre_commit_deps
3
- version = 0.0.1
4
- description = apply a consistent format to `setup.cfg` files
3
+ version = 0.0.3
4
+ description = Sync pre-commit hook dependencies based on other installed hooks
5
5
  long_description = file: README.md
6
6
  long_description_content_type = text/markdown
7
- url = https://github.com/mxr/sync-pre-commit-deps
7
+ url = https://github.com/pre-commit/sync-pre-commit-deps
8
8
  author = Max R
9
9
  author_email = maxr@outlook.com
10
10
  license = MIT
@@ -20,7 +20,7 @@ classifiers =
20
20
  py_modules = sync_pre_commit_deps
21
21
  install_requires =
22
22
  ruamel.yaml>=0.17
23
- python_requires = >=3.8
23
+ python_requires = >=3.9
24
24
 
25
25
  [options.entry_points]
26
26
  console_scripts =
@@ -32,11 +32,6 @@ universal = True
32
32
  [coverage:run]
33
33
  plugins = covdefaults
34
34
 
35
- [flake8]
36
- max-line-length = 88
37
- extend-ignore = E203
38
- min_python_version = 3.8
39
-
40
35
  [mypy]
41
36
  check_untyped_defs = true
42
37
  disallow_any_generics = true
@@ -1,8 +1,8 @@
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
1
+ Metadata-Version: 2.2
2
+ Name: sync_pre_commit_deps
3
+ Version: 0.0.3
4
+ Summary: Sync pre-commit hook dependencies based on other installed hooks
5
+ Home-page: https://github.com/pre-commit/sync-pre-commit-deps
6
6
  Author: Max R
7
7
  Author-email: maxr@outlook.com
8
8
  License: MIT
@@ -11,9 +11,10 @@ Classifier: Programming Language :: Python :: 3
11
11
  Classifier: Programming Language :: Python :: 3 :: Only
12
12
  Classifier: Programming Language :: Python :: Implementation :: CPython
13
13
  Classifier: Programming Language :: Python :: Implementation :: PyPy
14
- Requires-Python: >=3.8
14
+ Requires-Python: >=3.9
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
+ Requires-Dist: ruamel.yaml>=0.17
17
18
 
18
19
  sync-pre-commit-deps
19
20
  ====================
@@ -33,8 +34,8 @@ See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
33
34
  Sample `.pre-commit-config.yaml`:
34
35
 
35
36
  ```yaml
36
- - repo: https://github.com/mxr/sync-pre-commit-deps
37
- rev: v0.0.1
37
+ - repo: https://github.com/pre-commit/sync-pre-commit-deps
38
+ rev: v0.0.3
38
39
  hooks:
39
40
  - id: sync-pre-commit-deps
40
41
  ```
@@ -47,7 +48,7 @@ $ sync-pre-commit-deps path/to/.pre-commit-config.yaml
47
48
 
48
49
  ## what it does
49
50
 
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
+ Ensures tools which declare `flake8`, `black`, or `mypy` as additional dependencies will have those versions synced with the `flake8`, `black`, or `mypy` versions in the rest of the config. For example, `flake8` under `yesqa` is updated from `5.0.0` to `6.0.0`.
51
52
 
52
53
  ```diff
53
54
  repos:
@@ -0,0 +1,88 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ from collections.abc import Sequence
5
+
6
+ import ruamel.yaml
7
+
8
+ SUPPORTED = frozenset(('black', 'flake8', 'mypy'))
9
+
10
+
11
+ _ARGUMENT_HELP_TEMPLATE = (
12
+ 'The `{}` argument to the YAML dumper. '
13
+ 'See https://yaml.readthedocs.io/en/latest/detail/'
14
+ '#indentation-of-block-sequences'
15
+ )
16
+
17
+
18
+ def main(argv: Sequence[str] | None = None) -> int:
19
+ parser = argparse.ArgumentParser()
20
+ parser.add_argument(
21
+ 'filename', default='.pre-commit-config.yaml',
22
+ help='The pre-commit config file to sync to.',
23
+ )
24
+
25
+ # defaults below match pre-commit config as documented
26
+ # TODO - support round-tripping
27
+ parser.add_argument(
28
+ '--yaml-mapping', type=int, default=4,
29
+ help=_ARGUMENT_HELP_TEMPLATE.format('mapping'),
30
+ )
31
+ parser.add_argument(
32
+ '--yaml-sequence', type=int, default=4,
33
+ help=_ARGUMENT_HELP_TEMPLATE.format('sequence'),
34
+ )
35
+ parser.add_argument(
36
+ '--yaml-offset', type=int, default=0,
37
+ help=_ARGUMENT_HELP_TEMPLATE.format('offset'),
38
+ )
39
+
40
+ args = parser.parse_args(argv)
41
+ filename: str = args.filename
42
+ yaml_mapping: int = args.yaml_mapping
43
+ yaml_sequence: int = args.yaml_sequence
44
+ yaml_offset: int = args.yaml_offset
45
+
46
+ yaml = ruamel.yaml.YAML()
47
+ yaml.preserve_quotes = True
48
+ yaml.indent(yaml_mapping, yaml_sequence, yaml_offset)
49
+
50
+ with open(filename) as f:
51
+ loaded = yaml.load(f)
52
+
53
+ # TODO - validate schema?
54
+ versions = {}
55
+ for repo in loaded['repos']:
56
+ if repo['repo'] not in ('local', 'meta'):
57
+ for hook in repo['hooks']:
58
+ if (hid := hook['id']) in SUPPORTED:
59
+ # `mirrors-mypy` uses versions with a 'v' prefix, so we
60
+ # have to strip it out to get the mypy version.
61
+ cleaned_rev = repo['rev'].removeprefix('v')
62
+ versions[hid] = cleaned_rev
63
+
64
+ updated = []
65
+ for repo in loaded['repos']:
66
+ for hook in repo['hooks']:
67
+ for i, dep in enumerate(hook.get('additional_dependencies', ())):
68
+ name, _, cur_version = dep.partition('==')
69
+ target_version = versions.get(name, cur_version)
70
+ if target_version != cur_version:
71
+ name_and_version = f'{name}=={target_version}'
72
+ hook['additional_dependencies'][i] = name_and_version
73
+ updated.append((hook['id'], name))
74
+
75
+ if updated:
76
+ print(f'Writing updates to {filename}:')
77
+ for hid, name in updated:
78
+ print(f'\tSetting {hid!r} dependency {name!r} to {versions[name]}')
79
+
80
+ with open(filename, 'w+') as f:
81
+ yaml.dump(loaded, f)
82
+ return 1
83
+
84
+ return 0
85
+
86
+
87
+ if __name__ == '__main__':
88
+ raise SystemExit(main())
@@ -1,62 +0,0 @@
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())