sync-pre-commit-deps 0.0.2__tar.gz → 0.0.4__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,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: sync_pre_commit_deps
3
+ Version: 0.0.4
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
+ Author: Max R
7
+ Author-email: maxr@outlook.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: Implementation :: CPython
12
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: ruamel.yaml>=0.17
17
+ Dynamic: license-file
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/pre-commit/sync-pre-commit-deps
38
+ rev: v0.0.4
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
+ Hooks like `black`, `yesqa`, and `eslint` reference additional dependencies which are also `pre-commit` hooks. This tool syncs the version in `additional_dependencies` with the version in `rev`.
52
+
53
+ For example, `flake8` under `yesqa` is updated from `5.0.0` to `6.0.0` because the `flake8` hook uses `6.0.0`:
54
+
55
+ ```diff
56
+ repos:
57
+ - repo: https://github.com/PyCQA/flake8
58
+ rev: 6.0.0
59
+ hooks:
60
+ - id: flake8
61
+ - repo: https://github.com/asottile/yesqa
62
+ rev: v1.5.0
63
+ hooks:
64
+ - id: yesqa
65
+ additional_dependencies:
66
+ - - flake8==5.0.0
67
+ + - flake8==6.0.0
68
+ ```
69
+
70
+ Another example, the `eslint` version in `additional_dependencies` is updated to match the version in `rev`:
71
+
72
+ ```diff
73
+ - repo: https://github.com/pre-commit/mirrors-eslint
74
+ rev: v4.15.0
75
+ hooks:
76
+ - id: eslint
77
+ additional_dependencies:
78
+ - - eslint@4.14.0
79
+ + - eslint@4.15.0
80
+ - eslint-config-google@0.7.1
81
+ - eslint-loader@1.6.1
82
+ - eslint-plugin-react@6.10.3
83
+ - babel-eslint@6.1.2
84
+ ```
85
+
86
+ ## what it doesn't do
87
+
88
+ - Does not add new additional dependencies. Only updates versions for dependencies that are already specified.
89
+ - Does not sync versions from `package.json`, `requirements.txt`, `pyproject.toml`, etc.
@@ -0,0 +1,71 @@
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/pre-commit/sync-pre-commit-deps
20
+ rev: v0.0.4
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
+ Hooks like `black`, `yesqa`, and `eslint` reference additional dependencies which are also `pre-commit` hooks. This tool syncs the version in `additional_dependencies` with the version in `rev`.
34
+
35
+ For example, `flake8` under `yesqa` is updated from `5.0.0` to `6.0.0` because the `flake8` hook uses `6.0.0`:
36
+
37
+ ```diff
38
+ repos:
39
+ - repo: https://github.com/PyCQA/flake8
40
+ rev: 6.0.0
41
+ hooks:
42
+ - id: flake8
43
+ - repo: https://github.com/asottile/yesqa
44
+ rev: v1.5.0
45
+ hooks:
46
+ - id: yesqa
47
+ additional_dependencies:
48
+ - - flake8==5.0.0
49
+ + - flake8==6.0.0
50
+ ```
51
+
52
+ Another example, the `eslint` version in `additional_dependencies` is updated to match the version in `rev`:
53
+
54
+ ```diff
55
+ - repo: https://github.com/pre-commit/mirrors-eslint
56
+ rev: v4.15.0
57
+ hooks:
58
+ - id: eslint
59
+ additional_dependencies:
60
+ - - eslint@4.14.0
61
+ + - eslint@4.15.0
62
+ - eslint-config-google@0.7.1
63
+ - eslint-loader@1.6.1
64
+ - eslint-plugin-react@6.10.3
65
+ - babel-eslint@6.1.2
66
+ ```
67
+
68
+ ## what it doesn't do
69
+
70
+ - Does not add new additional dependencies. Only updates versions for dependencies that are already specified.
71
+ - Does not sync versions from `package.json`, `requirements.txt`, `pyproject.toml`, etc.
@@ -1,16 +1,15 @@
1
1
  [metadata]
2
2
  name = sync_pre_commit_deps
3
- version = 0.0.2
4
- description = apply a consistent format to `setup.cfg` files
3
+ version = 0.0.4
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
11
11
  license_files = LICENSE
12
12
  classifiers =
13
- License :: OSI Approved :: MIT License
14
13
  Programming Language :: Python :: 3
15
14
  Programming Language :: Python :: 3 :: Only
16
15
  Programming Language :: Python :: Implementation :: CPython
@@ -20,7 +19,7 @@ classifiers =
20
19
  py_modules = sync_pre_commit_deps
21
20
  install_requires =
22
21
  ruamel.yaml>=0.17
23
- python_requires = >=3.9
22
+ python_requires = >=3.10
24
23
 
25
24
  [options.entry_points]
26
25
  console_scripts =
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: sync_pre_commit_deps
3
+ Version: 0.0.4
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
+ Author: Max R
7
+ Author-email: maxr@outlook.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: Implementation :: CPython
12
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: ruamel.yaml>=0.17
17
+ Dynamic: license-file
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/pre-commit/sync-pre-commit-deps
38
+ rev: v0.0.4
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
+ Hooks like `black`, `yesqa`, and `eslint` reference additional dependencies which are also `pre-commit` hooks. This tool syncs the version in `additional_dependencies` with the version in `rev`.
52
+
53
+ For example, `flake8` under `yesqa` is updated from `5.0.0` to `6.0.0` because the `flake8` hook uses `6.0.0`:
54
+
55
+ ```diff
56
+ repos:
57
+ - repo: https://github.com/PyCQA/flake8
58
+ rev: 6.0.0
59
+ hooks:
60
+ - id: flake8
61
+ - repo: https://github.com/asottile/yesqa
62
+ rev: v1.5.0
63
+ hooks:
64
+ - id: yesqa
65
+ additional_dependencies:
66
+ - - flake8==5.0.0
67
+ + - flake8==6.0.0
68
+ ```
69
+
70
+ Another example, the `eslint` version in `additional_dependencies` is updated to match the version in `rev`:
71
+
72
+ ```diff
73
+ - repo: https://github.com/pre-commit/mirrors-eslint
74
+ rev: v4.15.0
75
+ hooks:
76
+ - id: eslint
77
+ additional_dependencies:
78
+ - - eslint@4.14.0
79
+ + - eslint@4.15.0
80
+ - eslint-config-google@0.7.1
81
+ - eslint-loader@1.6.1
82
+ - eslint-plugin-react@6.10.3
83
+ - babel-eslint@6.1.2
84
+ ```
85
+
86
+ ## what it doesn't do
87
+
88
+ - Does not add new additional dependencies. Only updates versions for dependencies that are already specified.
89
+ - Does not sync versions from `package.json`, `requirements.txt`, `pyproject.toml`, etc.
@@ -1,12 +1,25 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import argparse
4
+ import re
4
5
  from collections.abc import Sequence
5
6
 
6
7
  import ruamel.yaml
7
8
 
8
- SUPPORTED = frozenset(('black', 'flake8', 'mypy'))
9
-
9
+ SUPPORTED = {
10
+ 'black': 'black',
11
+ 'flake8': 'flake8',
12
+ 'mypy': 'mypy',
13
+ 'eslint': 'eslint',
14
+ 'csslint': 'csslint',
15
+ 'fixmyjs': 'fixmyjs',
16
+ 'jshint': 'jshint',
17
+ 'prettier': 'prettier',
18
+ 'biome-check': '@biomejs/biome',
19
+ }
20
+
21
+ _SEPS = ('==', '@')
22
+ _RE_SEP = re.compile(rf'^(.+)({"|".join(_SEPS)})(.+)$')
10
23
 
11
24
  _ARGUMENT_HELP_TEMPLATE = (
12
25
  'The `{}` argument to the YAML dumper. '
@@ -47,29 +60,32 @@ def main(argv: Sequence[str] | None = None) -> int:
47
60
  yaml.preserve_quotes = True
48
61
  yaml.indent(yaml_mapping, yaml_sequence, yaml_offset)
49
62
 
50
- with open(filename) as f:
63
+ with open(filename, encoding='utf-8') as f:
51
64
  loaded = yaml.load(f)
52
65
 
53
66
  # TODO - validate schema?
54
67
  versions = {}
55
68
  for repo in loaded['repos']:
56
- for hook in repo['hooks']:
57
- if (hid := hook['id']) in SUPPORTED:
58
- # `mirrors-mypy` uses versions with a 'v' prefix, so we have to
59
- # strip it out to get the mypy version.
60
- cleaned_rev = repo['rev'].removeprefix('v')
61
- versions[hid] = cleaned_rev
69
+ if repo['repo'] not in ('local', 'meta'):
70
+ for hook in repo['hooks']:
71
+ if (dep := SUPPORTED.get(hook['id'])) is not None:
72
+ # `mirrors-mypy` and various node revs have a 'v' prefix,
73
+ # so we have to strip that out to get the
74
+ # additional_dependency version.
75
+ cleaned_rev = repo['rev'].removeprefix('v')
76
+ versions[dep] = cleaned_rev
62
77
 
63
78
  updated = []
64
79
  for repo in loaded['repos']:
65
80
  for hook in repo['hooks']:
66
81
  for i, dep in enumerate(hook.get('additional_dependencies', ())):
67
- name, _, cur_version = dep.partition('==')
68
- target_version = versions.get(name, cur_version)
69
- if target_version != cur_version:
70
- name_and_version = f'{name}=={target_version}'
71
- hook['additional_dependencies'][i] = name_and_version
72
- updated.append((hook['id'], name))
82
+ if match := _RE_SEP.match(dep):
83
+ name, sep, cur_version = match.groups()
84
+ target_version = versions.get(name, cur_version)
85
+ if target_version != cur_version:
86
+ updated_dep = f'{name}{sep}{target_version}'
87
+ hook['additional_dependencies'][i] = updated_dep
88
+ updated.append((hook['id'], name))
73
89
 
74
90
  if updated:
75
91
  print(f'Writing updates to {filename}:')
@@ -1,66 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: sync_pre_commit_deps
3
- Version: 0.0.2
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.9
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.2
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`, `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`.
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
- ```
@@ -1,48 +0,0 @@
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.2
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`, `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
-
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
- ```
@@ -1,66 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: sync_pre_commit_deps
3
- Version: 0.0.2
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.9
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.2
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`, `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`.
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
- ```