dycw-pre-commit-hooks 0.11.0__tar.gz → 0.11.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.
Files changed (15) hide show
  1. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/PKG-INFO +3 -1
  2. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/README.md +1 -0
  3. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/pyproject.toml +15 -17
  4. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/src/pre_commit_hooks/__init__.py +1 -1
  5. dycw_pre_commit_hooks-0.11.1/src/pre_commit_hooks/replace_sequence_str/__init__.py +55 -0
  6. dycw_pre_commit_hooks-0.11.1/src/pre_commit_hooks/replace_sequence_str/__main__.py +6 -0
  7. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/.gitignore +0 -0
  8. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/src/pre_commit_hooks/common.py +0 -0
  9. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/src/pre_commit_hooks/py.typed +0 -0
  10. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/src/pre_commit_hooks/run_bump_my_version/__init__.py +0 -0
  11. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/src/pre_commit_hooks/run_bump_my_version/__main__.py +0 -0
  12. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/src/pre_commit_hooks/run_ruff_format/__init__.py +0 -0
  13. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/src/pre_commit_hooks/run_ruff_format/__main__.py +0 -0
  14. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/src/tests/__init__.py +0 -0
  15. {dycw_pre_commit_hooks-0.11.0 → dycw_pre_commit_hooks-0.11.1}/src/tests/test_main.py +0 -0
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-pre-commit-hooks
3
- Version: 0.11.0
3
+ Version: 0.11.1
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  Requires-Python: >=3.12
6
6
  Requires-Dist: click<8.3,>=8.2.1
7
7
  Requires-Dist: dycw-utilities<0.126,>=0.125.10
8
+ Requires-Dist: libcst<1.9,>=1.8.2
8
9
  Requires-Dist: loguru<0.8,>=0.7.3
9
10
  Requires-Dist: tomlkit<0.14,>=0.13.2
10
11
  Description-Content-Type: text/markdown
@@ -26,6 +27,7 @@ My [`pre-commit`](https://pre-commit.com/) hooks.
26
27
  - repo: https://github.com/dycw/pre-commit-hooks
27
28
  rev: master
28
29
  hooks:
30
+ - id: replace-sequence-str
29
31
  - id: run-bump-my-version
30
32
  - id: run-ruff-format
31
33
  ```
@@ -15,6 +15,7 @@ My [`pre-commit`](https://pre-commit.com/) hooks.
15
15
  - repo: https://github.com/dycw/pre-commit-hooks
16
16
  rev: master
17
17
  hooks:
18
+ - id: replace-sequence-str
18
19
  - id: run-bump-my-version
19
20
  - id: run-ruff-format
20
21
  ```
@@ -18,23 +18,24 @@ authors = [{name = "Derek Wan", email = "d.wan@icloud.com"}]
18
18
  dependencies = [
19
19
  "click >= 8.2.1, < 8.3",
20
20
  "dycw-utilities >= 0.125.10, < 0.126",
21
+ "libcst >= 1.8.2, < 1.9",
21
22
  "loguru >= 0.7.3, < 0.8",
22
23
  "tomlkit >= 0.13.2, < 0.14",
23
24
  ]
24
25
  name = "dycw-pre-commit-hooks"
25
26
  readme = "README.md"
26
27
  requires-python = ">= 3.12"
27
- version = "0.11.0"
28
+ version = "0.11.1"
28
29
 
29
30
  [project.scripts]
31
+ replace-sequence-str = "pre_commit_hooks.replace_sequence_str:main"
30
32
  run-bump-my-version = "pre_commit_hooks.run_bump_my_version:main"
31
- run-bump2version = "pre_commit_hooks.run_bump2version:main"
32
33
  run-ruff-format = "pre_commit_hooks.run_ruff_format:main"
33
34
 
34
35
  # bump-my-version
35
36
  [tool.bumpversion]
36
37
  allow_dirty = true
37
- current_version = "0.11.0"
38
+ current_version = "0.11.1"
38
39
 
39
40
  [[tool.bumpversion.files]]
40
41
  filename = "src/pre_commit_hooks/__init__.py"
@@ -106,7 +107,13 @@ typeCheckingMode = "strict"
106
107
  [tool.pytest]
107
108
 
108
109
  [tool.pytest.ini_options]
109
- addopts = ["-ra", "-vv", "--color=auto", "--strict-markers"]
110
+ addopts = [
111
+ "-ra",
112
+ "-vv",
113
+ "--color=auto",
114
+ "--strict-markers",
115
+ "--pdbcls=pudb.debugger:Debugger",
116
+ ]
110
117
  filterwarnings = ["error"]
111
118
  minversion = "8.0"
112
119
  testpaths = ["src/tests"]
@@ -120,8 +127,10 @@ unsafe-fixes = true
120
127
 
121
128
  [tool.ruff.format]
122
129
  preview = true
130
+ skip-magic-trailing-comma = true
123
131
 
124
132
  [tool.ruff.lint]
133
+ explicit-preview-rules = true
125
134
  fixable = ["ALL"]
126
135
  ignore = [
127
136
  "ANN401", # any-type
@@ -140,6 +149,7 @@ ignore = [
140
149
  "E501", # line-too-long
141
150
  "PD", # pandas-vet
142
151
  "PERF203", # try-except-in-loop
152
+ "PLC0415", # import-outside-top-level
143
153
  "PLR0911", # too-many-return-statements
144
154
  "PLR0912", # too-many-branches
145
155
  "PLR0913", # too-many-arguments
@@ -168,19 +178,6 @@ ignore = [
168
178
  "ISC002", # multi-line-implicit-string-concatenation
169
179
  ]
170
180
  select = ["ALL"]
171
- unfixable = [
172
- "B007", # unused-loop-control-variable
173
- "F541", # f-string-missing-placeholders
174
- "F601", # multi-value-repeated-key-literal
175
- "PIE794", # duplicate-class-field-definition
176
- "PLR5501", # collapsible-else-if
177
- "PT014", # pytest-duplicate-parametrize-test-cases
178
- "RET504", # unnecessary-assign
179
- "SIM102", # collapsible-if
180
- "SIM105", # suppressible-exception
181
- "SIM114", # if-with-same-arms
182
- "T201", # print
183
- ]
184
181
 
185
182
  [tool.ruff.lint.extend-per-file-ignores]
186
183
  "*.ipynb" = [
@@ -199,3 +196,4 @@ ban-relative-imports = "all"
199
196
 
200
197
  [tool.ruff.lint.isort]
201
198
  required-imports = ["from __future__ import annotations"]
199
+ split-on-trailing-comma = false
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.11.0"
3
+ __version__ = "0.11.1"
@@ -0,0 +1,55 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, override
4
+
5
+ from click import argument, command
6
+ from libcst import CSTTransformer, Name, Subscript, parse_module
7
+ from libcst.matchers import Index as MIndex
8
+ from libcst.matchers import Name as MName
9
+ from libcst.matchers import Subscript as MSubscript
10
+ from libcst.matchers import SubscriptElement as MSubscriptElement
11
+ from libcst.matchers import matches
12
+ from libcst.metadata import MetadataWrapper
13
+ from utilities.click import FilePath
14
+
15
+ if TYPE_CHECKING:
16
+ from pathlib import Path
17
+
18
+
19
+ @command()
20
+ @argument("paths", nargs=-1, type=FilePath)
21
+ def main(*, paths: tuple[Path, ...]) -> bool:
22
+ """CLI for the `replace_sequence_str` hook."""
23
+ results = list(map(_process, paths))
24
+ return all(results)
25
+
26
+
27
+ def _process(path: Path, /) -> bool:
28
+ existing = path.read_text()
29
+ wrapper = MetadataWrapper(parse_module(existing))
30
+ transformed = wrapper.module.visit(SequenceToListTransformer())
31
+ new = transformed.code
32
+ if existing == new:
33
+ return True
34
+ _ = path.write_text(new)
35
+ return False
36
+
37
+
38
+ class SequenceToListTransformer(CSTTransformer):
39
+ @override
40
+ def leave_Subscript(
41
+ self, original_node: Subscript, updated_node: Subscript
42
+ ) -> Subscript:
43
+ _ = original_node
44
+ if matches(
45
+ updated_node,
46
+ MSubscript(
47
+ value=MName("Sequence"),
48
+ slice=[MSubscriptElement(slice=MIndex(value=MName("str")))],
49
+ ),
50
+ ):
51
+ return updated_node.with_changes(value=Name("list"))
52
+ return updated_node
53
+
54
+
55
+ __all__ = ["main"]
@@ -0,0 +1,6 @@
1
+ from __future__ import annotations
2
+
3
+ from pre_commit_hooks.replace_sequence_str import main
4
+
5
+ if __name__ == "__main__":
6
+ raise SystemExit(int(not main()))