sync-pre-commit-deps 0.0.3__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.
@@ -1,20 +1,20 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: sync_pre_commit_deps
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: Sync pre-commit hook dependencies based on other installed hooks
5
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
9
- Classifier: License :: OSI Approved :: MIT License
10
9
  Classifier: Programming Language :: Python :: 3
11
10
  Classifier: Programming Language :: Python :: 3 :: Only
12
11
  Classifier: Programming Language :: Python :: Implementation :: CPython
13
12
  Classifier: Programming Language :: Python :: Implementation :: PyPy
14
- Requires-Python: >=3.9
13
+ Requires-Python: >=3.10
15
14
  Description-Content-Type: text/markdown
16
15
  License-File: LICENSE
17
16
  Requires-Dist: ruamel.yaml>=0.17
17
+ Dynamic: license-file
18
18
 
19
19
  sync-pre-commit-deps
20
20
  ====================
@@ -35,7 +35,7 @@ Sample `.pre-commit-config.yaml`:
35
35
 
36
36
  ```yaml
37
37
  - repo: https://github.com/pre-commit/sync-pre-commit-deps
38
- rev: v0.0.3
38
+ rev: v0.0.4
39
39
  hooks:
40
40
  - id: sync-pre-commit-deps
41
41
  ```
@@ -48,7 +48,9 @@ $ sync-pre-commit-deps path/to/.pre-commit-config.yaml
48
48
 
49
49
  ## what it does
50
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`.
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`:
52
54
 
53
55
  ```diff
54
56
  repos:
@@ -64,3 +66,24 @@ Ensures tools which declare `flake8`, `black`, or `mypy` as additional dependenc
64
66
  - - flake8==5.0.0
65
67
  + - flake8==6.0.0
66
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,6 +1,6 @@
1
1
  [metadata]
2
2
  name = sync_pre_commit_deps
3
- version = 0.0.3
3
+ version = 0.0.4
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
@@ -10,7 +10,6 @@ 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 =
@@ -1,20 +1,20 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: sync_pre_commit_deps
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: Sync pre-commit hook dependencies based on other installed hooks
5
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
9
- Classifier: License :: OSI Approved :: MIT License
10
9
  Classifier: Programming Language :: Python :: 3
11
10
  Classifier: Programming Language :: Python :: 3 :: Only
12
11
  Classifier: Programming Language :: Python :: Implementation :: CPython
13
12
  Classifier: Programming Language :: Python :: Implementation :: PyPy
14
- Requires-Python: >=3.9
13
+ Requires-Python: >=3.10
15
14
  Description-Content-Type: text/markdown
16
15
  License-File: LICENSE
17
16
  Requires-Dist: ruamel.yaml>=0.17
17
+ Dynamic: license-file
18
18
 
19
19
  sync-pre-commit-deps
20
20
  ====================
@@ -35,7 +35,7 @@ Sample `.pre-commit-config.yaml`:
35
35
 
36
36
  ```yaml
37
37
  - repo: https://github.com/pre-commit/sync-pre-commit-deps
38
- rev: v0.0.3
38
+ rev: v0.0.4
39
39
  hooks:
40
40
  - id: sync-pre-commit-deps
41
41
  ```
@@ -48,7 +48,9 @@ $ sync-pre-commit-deps path/to/.pre-commit-config.yaml
48
48
 
49
49
  ## what it does
50
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`.
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`:
52
54
 
53
55
  ```diff
54
56
  repos:
@@ -64,3 +66,24 @@ Ensures tools which declare `flake8`, `black`, or `mypy` as additional dependenc
64
66
  - - flake8==5.0.0
65
67
  + - flake8==6.0.0
66
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,7 +60,7 @@ 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?
@@ -55,22 +68,24 @@ def main(argv: Sequence[str] | None = None) -> int:
55
68
  for repo in loaded['repos']:
56
69
  if repo['repo'] not in ('local', 'meta'):
57
70
  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.
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.
61
75
  cleaned_rev = repo['rev'].removeprefix('v')
62
- versions[hid] = cleaned_rev
76
+ versions[dep] = cleaned_rev
63
77
 
64
78
  updated = []
65
79
  for repo in loaded['repos']:
66
80
  for hook in repo['hooks']:
67
81
  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))
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))
74
89
 
75
90
  if updated:
76
91
  print(f'Writing updates to {filename}:')
@@ -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/pre-commit/sync-pre-commit-deps
20
- rev: v0.0.3
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
- ```