deadcode 2.4.0__py3-none-any.whl → 2.5.0__py3-none-any.whl

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.
deadcode/__init__.py CHANGED
@@ -1,6 +1,8 @@
1
1
  try:
2
2
  import importlib.metadata
3
+
3
4
  __version__ = importlib.metadata.version(__package__ or __name__)
4
5
  except ImportError:
5
6
  import importlib_metadata
7
+
6
8
  __version__ = importlib_metadata.version(__package__ or __name__)
@@ -194,6 +194,12 @@ def parse_arguments(args: Optional[List[str]]) -> Args:
194
194
  action='store_true',
195
195
  default=False,
196
196
  )
197
+ parser.add_argument(
198
+ '--version',
199
+ help='Shows deadcode version',
200
+ action='store_true',
201
+ default=False,
202
+ )
197
203
 
198
204
  parsed_args = parser.parse_args(args).__dict__
199
205
 
deadcode/cli.py CHANGED
@@ -1,5 +1,7 @@
1
1
  from typing import List, Optional
2
+ import sys
2
3
 
4
+ from deadcode import __version__
3
5
  from deadcode.actions.find_python_filenames import find_python_filenames
4
6
  from deadcode.actions.find_unused_names import find_unused_names
5
7
  from deadcode.actions.fix_or_show_unused_code import fix_or_show_unused_code
@@ -12,6 +14,9 @@ from deadcode.actions.get_unused_names_error_message import (
12
14
  def main(
13
15
  command_line_args: Optional[List[str]] = None,
14
16
  ) -> Optional[str]:
17
+ if command_line_args and '--version' in command_line_args or '--version' in sys.argv:
18
+ return __version__
19
+
15
20
  args = parse_arguments(command_line_args)
16
21
 
17
22
  filenames = find_python_filenames(args=args)
@@ -31,5 +36,10 @@ def main(
31
36
  return None
32
37
 
33
38
 
39
+ def print_main() -> None:
40
+ if result := main():
41
+ print(result)
42
+
43
+
34
44
  if __name__ == '__main__':
35
- main()
45
+ print_main()
deadcode/data_types.py CHANGED
@@ -14,6 +14,7 @@ Pathname = str # Can contain wildewards
14
14
  class Args:
15
15
  fix: bool = False
16
16
  verbose: bool = False
17
+ version: bool = False
17
18
  dry: bool = False
18
19
  only: Iterable[Pathname] = ()
19
20
  paths: Iterable[Pathname] = ()
deadcode/visitor/utils.py CHANGED
@@ -58,7 +58,7 @@ def get_decorator_name(decorator: Union[ast.Call, ast.Attribute]) -> str:
58
58
  while isinstance(decorator, ast.Attribute):
59
59
  parts.append(decorator.attr)
60
60
  decorator = decorator.value # type: ignore
61
- parts.append(decorator.id) # type: ignore
61
+ parts.append(str(id(decorator)))
62
62
  return '@' + '.'.join(reversed(parts))
63
63
 
64
64
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.5
2
2
  Name: deadcode
3
- Version: 2.4.0
3
+ Version: 2.5.0
4
4
  Summary: Find and remove dead code.
5
5
  Project-URL: homepage, https://github.com/albertas/deadcode
6
6
  Project-URL: documentation, https://deadcode.readthedocs.io/
@@ -18,11 +18,12 @@ Requires-Python: >=3.10
18
18
  Requires-Dist: tomli>=2.0.1
19
19
  Provides-Extra: test
20
20
  Requires-Dist: hatch; extra == 'test'
21
- Requires-Dist: mypy; extra == 'test'
21
+ Requires-Dist: mypy==1.10.1; extra == 'test'
22
22
  Requires-Dist: pip-audit; extra == 'test'
23
- Requires-Dist: pytest; extra == 'test'
24
- Requires-Dist: pytest-cov; extra == 'test'
25
- Requires-Dist: ruff; extra == 'test'
23
+ Requires-Dist: pre-commit; extra == 'test'
24
+ Requires-Dist: pytest-cov==5.0.0; extra == 'test'
25
+ Requires-Dist: pytest==9.0.3; extra == 'test'
26
+ Requires-Dist: ruff==0.5.1; extra == 'test'
26
27
  Description-Content-Type: text/markdown
27
28
 
28
29
  [![Deadcode Logo](https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/deadcode-logo-readme.png)](https://deadcode.readthedocs.io/en/stable/)
@@ -34,6 +35,7 @@ Description-Content-Type: text/markdown
34
35
  <a href="https://pypi.org/project/deadcode/"><img alt="PyPI" src="https://img.shields.io/pypi/v/deadcode"></a>
35
36
  <a href="https://pepy.tech/project/deadcode"><img alt="Downloads" src="https://static.pepy.tech/badge/deadcode"></a>
36
37
  <a href="https://github.com/albertas/deadcode/blob/main/LICENSE"><img alt="License: AGPLv3" src="https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/AGPLv3-license.svg"></a>
38
+ <br/><a href='https://ko-fi.com/V7V21681GD' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi3.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
37
39
  </p>
38
40
 
39
41
 
@@ -76,6 +78,28 @@ ignore-names = ["BaseTestCase", "*Mixin"]
76
78
  ignore-names-in-files = ["migrations"]
77
79
  ```
78
80
 
81
+ ## Pre-commit hook
82
+ Create a `.pre-commit-config.yaml` file in the root of your project directory, if it doesn't exist, and add the following to the file:
83
+
84
+ ```
85
+ # See https://pre-commit.com for more information
86
+ # See https://pre-commit.com/hooks.html for more hooks
87
+ repos:
88
+ - repo: https://github.com/albertas/deadcode
89
+ rev: 2.5.0
90
+ hooks:
91
+ - id: deadcode
92
+ ```
93
+
94
+ The `rev` is the release tag, so it matches the version published on PyPI. To
95
+ run the same hook while developing deadcode itself, use `make pre-commit`.
96
+
97
+ ## Contributing
98
+
99
+ Create a feature branch from `main`, open a pull request targeting `main`, and
100
+ wait for review. Do not commit feature changes directly to `main`; release
101
+ commits are made by the maintainer on `main`.
102
+
79
103
  ## Command line options
80
104
 
81
105
  | Option&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Type | Meaning |
@@ -201,6 +225,11 @@ code base is implemented in.
201
225
  - [ ] Investigate ways of extracting and backporting Python3.10+ `ast` implementation to lower Python versions.
202
226
 
203
227
  ## Release notes
228
+ - v2.5.0:
229
+ - Fix a crash when a decorator has no `id` attribute.
230
+ - v2.4.1:
231
+ - Add `--version` option to show `deadcode` version.
232
+ - Use stdout for `deadcode` output.
204
233
  - v2.4.0:
205
234
  - Add `--only` option that accepts filenames only which will be reflected in the output and modified.
206
235
  This option can be used with `--fix` and `--fix --dry` options as well as for simple unused code detection without fixing.
@@ -1,7 +1,7 @@
1
- deadcode/__init__.py,sha256=FVV1tdqGE_2-b70g8FPwZhmFrQ9hCXwuWb7cn9f0w3M,225
2
- deadcode/cli.py,sha256=F9YO08LvhTAs_UIGklTvILR1Fw3ghDD0gafRy1-7xe8,1175
1
+ deadcode/__init__.py,sha256=-nvSi7hjcp572lXD-ercQdCJg2qJKYeBC7rLYPanSUs,227
2
+ deadcode/cli.py,sha256=hwzIUEzaaKQ8HWZ8TfuQQbxmAOmnBU9g7ym448Ld6UI,1418
3
3
  deadcode/constants.py,sha256=ya_JsIQGtWAgrEZWc2NpKtuhwkn_05tlGBQpAm3f3Hc,838
4
- deadcode/data_types.py,sha256=Qh7J-7-a-1eVbNLJl8XpOe6G9vIXCZa24BCmA5Jrygo,1337
4
+ deadcode/data_types.py,sha256=3BzU0LxTi00XtbIM8fh4RkdAoAeZsrbCyvyaSuNe5UA,1363
5
5
  deadcode/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  deadcode/actions/find_python_filenames.py,sha256=uUKvCcisGc4zb6CjUDOhGYPjwW4S2Ysfr2MRhkMD7m0,1546
7
7
  deadcode/actions/find_unused_names.py,sha256=TagYxuxNrBarwmJ23tuxuCGNinj8mQo26RGZTh90a-8,494
@@ -9,7 +9,7 @@ deadcode/actions/fix_or_show_unused_code.py,sha256=7txuOL_4wYiBecSMhGJ15YotNtlTW
9
9
  deadcode/actions/get_unused_names_error_message.py,sha256=OMQyCXYTs5FAEFzrcFHZAJ_UrrphbAfn9ahtQG7Nt1I,1285
10
10
  deadcode/actions/merge_overlaping_file_parts.py,sha256=ukErzpXCuUOWk5CCpPxD43edqoE087sGJGvYZnwUGXs,3165
11
11
  deadcode/actions/parse_abstract_syntax_tree.py,sha256=iL0ukt-FQKA9DuFUk7-sSJZ9nfBzDlJBY-ijItYR6PU,547
12
- deadcode/actions/parse_arguments.py,sha256=xYozzUjDNogVsYAh-0k0zVTauTr8GFWY0bOjTH2skDU,6970
12
+ deadcode/actions/parse_arguments.py,sha256=gYbdHz_8bzWUXArLzeV0Mu1a4vnhSBKuGWsuluDJcSs,7113
13
13
  deadcode/actions/remove_file_parts_from_content.py,sha256=vz9fjniO6Tx3y-rUb4pmAWwU3BYbCBE4-ZY7aDNNnMI,6475
14
14
  deadcode/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  deadcode/utils/add_colors_to_diff.py,sha256=JSEtaHbyojIpCOBa2UNCaKDJr0a9hxkeDlRB4h-YpBI,423
@@ -24,9 +24,9 @@ deadcode/visitor/dead_code_visitor.py,sha256=JndoN9fpQcJ6g4IDoZq5xlrV2jJI195R6jU
24
24
  deadcode/visitor/ignore.py,sha256=m8qB8uKYB65D-53JOB5LKz32TF9c1y623EyZ1uFFc9A,3191
25
25
  deadcode/visitor/lines.py,sha256=0NCrWAqYua7k93VYy7yLby7olhT2Pe4VU_Z5ImNKkjE,3241
26
26
  deadcode/visitor/noqa.py,sha256=0zRA9q0MzEzKe-N285JafP1DSJ3QqGL4GTb9m0QwCiY,2088
27
- deadcode/visitor/utils.py,sha256=55WcdKJPRrQiFrc0tIkcGO7dUkTnfvZ3qSzsLsTR4MI,2765
28
- deadcode-2.4.0.dist-info/METADATA,sha256=NT---6Vv93M9jHBL5_nRpx-K2K1mlvlt1sAa1EU03MI,11892
29
- deadcode-2.4.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
30
- deadcode-2.4.0.dist-info/entry_points.txt,sha256=B0nEkycvQHBUJVGS4KmWCBtcWoEM87Gae6zHbrXCU2Q,47
31
- deadcode-2.4.0.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
32
- deadcode-2.4.0.dist-info/RECORD,,
27
+ deadcode/visitor/utils.py,sha256=0DELSP23ora0AjZdEpjiAEE9VlXkOhq6W63ZmgmtwGA,2759
28
+ deadcode-2.5.0.dist-info/METADATA,sha256=8fWn41I1ILdlA-6CdQ0OwohkaOoGeMZSrbpnGBHwV00,13093
29
+ deadcode-2.5.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
30
+ deadcode-2.5.0.dist-info/entry_points.txt,sha256=efJLd6DwsjycmpPFhvnql1ziW6xGx6VtAvZXNlREQxg,53
31
+ deadcode-2.5.0.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
32
+ deadcode-2.5.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.25.0
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ deadcode = deadcode.cli:print_main
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- deadcode = deadcode.cli:main