lapsed 3.2.0__py3-none-win32.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.
Binary file
@@ -0,0 +1,246 @@
1
+ Metadata-Version: 2.4
2
+ Name: lapsed
3
+ Version: 3.2.0
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: License :: OSI Approved :: GNU Affero General Public License v3
6
+ Classifier: Natural Language :: English
7
+ Classifier: Operating System :: Microsoft :: Windows
8
+ Classifier: Operating System :: POSIX :: Linux
9
+ Classifier: Programming Language :: Rust
10
+ License-File: LICENSE
11
+ Summary: Find and remove dead code in Python codebases (Rust implementation).
12
+ Author-email: Colin Kennedy <colinvfx@gmail.com>
13
+ License: AGPL-3.0-only
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
16
+ Project-URL: documentation, https://deadcode.readthedocs.io/
17
+ Project-URL: homepage, https://github.com/albertas/deadcode
18
+
19
+ [![Deadcode Logo](https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/deadcode-logo-readme.png)](https://deadcode.readthedocs.io/en/stable/)
20
+
21
+ <h2 align="center">Find and Fix Unused Python Code</h2>
22
+
23
+ <p align="center">
24
+ <a href="https://github.com/pre-commit/pre-commit"><img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit" alt="pre-commit" style="max-width:100%;"></a>
25
+ <a href="https://pypi.org/project/deadcode/"><img alt="PyPI" src="https://img.shields.io/pypi/v/deadcode"></a>
26
+ <a href="https://pepy.tech/project/deadcode"><img alt="Downloads" src="https://static.pepy.tech/badge/deadcode"></a>
27
+ <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>
28
+ <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>
29
+ </p>
30
+
31
+
32
+ ## Installation
33
+ ```shell
34
+ pip install deadcode
35
+ ```
36
+
37
+ ## Usage
38
+ To see unused code findings:
39
+ ```shell
40
+ deadcode .
41
+ ```
42
+
43
+ To see suggested fixes for all files:
44
+ ```shell
45
+ deadcode . --fix --dry
46
+ ```
47
+
48
+ To see suggested fixes only for `foo.py` file:
49
+ ```shell
50
+ deadcode . --fix --dry --only foo.py
51
+ ```
52
+
53
+ To fix:
54
+ ```shell
55
+ deadcode . --fix
56
+ ```
57
+
58
+ Tune out some of the false positives, e.g.:
59
+ ```
60
+ deadcode . --exclude=venv,tests --ignore-names=BaseTestCase,*Mixin --ignore-names-in-files=migrations
61
+ ```
62
+
63
+ The same options can be provided in `pyproject.toml` settings file:
64
+ ```
65
+ [tool.deadcode]
66
+ exclude = ["venv", "tests"]
67
+ ignore-names = ["BaseTestCase", "*Mixin"]
68
+ ignore-names-in-files = ["migrations"]
69
+ ```
70
+
71
+ If your project uses [Tach](https://docs.gauge.sh) to declare module boundaries, `deadcode` can read one
72
+ or more `tach.toml` files and treat names exposed through `[[interfaces]]` as intentional public API
73
+ (never reported as unused, the same way `__all__` is treated), and skip files that belong to a module
74
+ marked `unchecked = true`:
75
+ ```shell
76
+ deadcode . --tach-config tach.toml
77
+ ```
78
+
79
+ ## Pre-commit hook
80
+ 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:
81
+
82
+ ```
83
+ # See https://pre-commit.com for more information
84
+ # See https://pre-commit.com/hooks.html for more hooks
85
+ repos:
86
+ - repo: https://github.com/albertas/deadcode
87
+ rev: 2.6.0
88
+ hooks:
89
+ - id: deadcode
90
+ ```
91
+
92
+ ## Command line options
93
+
94
+ | 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 |
95
+ |-------------------------------------------|------|----------------------------------------------------------------------|
96
+ |`--fix` | - | Automatically remove detected unused code expressions from the code base. |
97
+ |`--dry` | - | Show changes which would be made in files. |
98
+ |`--only` | list | Filenames (or path expressions), that will be reflected in the output (and modified if needed). |
99
+ |`--exclude` | list | Filenames (or path expressions), which will be completely skipped without being analysed. |
100
+ |`--ignore-names` | list | Removes provided list of names from the output. Regexp expressions to match multiple names can also be provided, e.g. `*Mixin` will match all classes ending with `Mixin`. |
101
+ |`--ignore-names-in-files` | list | Ignores unused names in files, which filenames match provided path expressions. |
102
+ |`--ignore-names-if-inherits-from` | list | Ignores names of classes, which inherit from provided class names. |
103
+ |`--ignore-names-if-decorated-with` | list | Ignores names of an expression, which is decorated with one of the provided decorator names. |
104
+ |`--ignore-bodies-of` | list | Ignores body of an expression if its name matches any of the provided names. |
105
+ |`--ignore-bodies-if-decorated-with` | list | Ignores body of an expression if its decorated with one of the provided decorator names. |
106
+ |`--ignore-bodies-if-inherits-from` | list | Ignores body of a class if it inherits from any of the provided class names. |
107
+ |`--ignore-definitions` | list | Ignores definition (including name and body) if a name of an expression matches any of the provided ones. |
108
+ |`--ignore-definitions-if-inherits-from` | list | Ignores definition (including name and body) of a class if it inherits from any of the provided class names. |
109
+ |`--ignore-definitions-if-decorated-with` | list | Ignores definition (including name and body) of an expression, which is decorated with any of the provided decorator names. |
110
+ |`--ignore-non-self-attributes` | - | Does not report unused attributes assigned on objects other than `self`, e.g. `foo.bar = 1`. Such assignments may have side effects or be consumed by code outside of the analysed files, so they cannot safely be assumed dead. |
111
+ |`--ignore-class-attributes` | - | Does not report unused attributes assigned directly in a class body, e.g. `THING = "blah"` inside a `class Foo:` block. Such attributes may control behaviour of inherited/overridden methods, external frameworks, or metaclasses, so they cannot safely be assumed dead. |
112
+ |`--tach-config` | list | Paths to `tach.toml` files (see [Tach](https://docs.gauge.sh)). Names exposed via `[[interfaces]]` are treated as public API and never reported as unused; files in `unchecked = true` modules are skipped entirely. |
113
+ |`--no-color` | - | Removes colors from the output. |
114
+ |`--count` | - | Provides the count of the detected unused names instead of printing them all out. |
115
+ |`--quiet` | - | Does not output anything. Makefile still fails with exit code 1 if unused names are found. |
116
+
117
+
118
+ ##### Glossory
119
+ - `name` - variable, function or class name.
120
+ - `body` - code block which follows after `:` in function or class definition.
121
+ - `definition` - whole class or function definition expression including its name and body.
122
+
123
+
124
+ ## Rules
125
+ | Code | Name | Message |
126
+ |--------|--------------------|----------------|
127
+ | DC01 | unused-variable | Variable `{name}` is never used
128
+ | DC02 | unused-function | Function `{name}` is never used
129
+ | DC03 | unused-class | Class `{name}` is never used
130
+ | DC04 | unused-method | Method `{name}` is never used
131
+ | DC05 | unused-attribute | Attribute `{name}` is never used
132
+ | DC06 | unused-name | Name `{name}` is never used
133
+ | DC07 | unused-import | Import `{name}` is never used
134
+ | DC08 | unused-property | Property `{name}` is never used
135
+ | DC09 | unreachable-if-block | Unreachable conditional statement block
136
+ | DC11 | empty-file | Empty Python file
137
+ | DC12 | commented-out-code | Commented out code
138
+ | DC13 | unreachable-code | Code after terminal statement, e.g. `return`, `raise`, `continue`, `break`
139
+ | DC | ignore-expression | Do not show any findings for an expression, which starts on current line (this code can only be used in `# noqa: DC` comments)
140
+
141
+ ## Ignoring checks with noqa comments
142
+ Inline `# noqa` comments can be used to ignore `deadcode` checks.
143
+ E.g. unused `Foo` class wont be detected/fixed because `# noqa: DC03` comment is used:
144
+
145
+ ```python
146
+ class Foo: # noqa: DC03
147
+ pass
148
+ ```
149
+
150
+ ## Contributing
151
+ - `make check` - runs unit tests and other checks using virtual environment.
152
+
153
+ ## Rationale
154
+ [ruff](https://pypi.org/project/ruff/) and
155
+ [flake8](https://pypi.org/project/flake8/) - don't have rules for unused global
156
+ code detection, only for local ones `F823`, `F841`, `F842`. `deadcode` package
157
+ tries to add new `DCXXX` checks for detecting variables/functions/classes/files
158
+ which are not used in a whole code base.
159
+
160
+ `deadcode` - is supposed to be used inline with other static code checkers like `ruff`.
161
+
162
+ There is an alternative [vulture](https://pypi.org/project/vulture/) package.
163
+
164
+ ## Known limitations
165
+ In case there are several definitions using the same name - they all wont be
166
+ reported if at least one usage of that name is being detected.
167
+
168
+ Files with syntax errors will be ignored, because `deadcode` uses `ast` to
169
+ build abstract syntax tree for name usage detection.
170
+
171
+ It is assumed that `deadcode` will be run using the same or higher Python version as the
172
+ code base is implemented in.
173
+
174
+ ## Feature requests
175
+ - [x] Replace `.*` with only `*` in regexp matching.
176
+ - [x] Add unused class method detection DC04 check.
177
+ - [x] Add `--fix` option to automatically remove detected dead code occourencies
178
+ - [x] Add a check for empty python files.
179
+ - [x] Split error codes into DC01, DC02, DC03 for variables, functions, class.
180
+ - [x] Should have different codes for ignoring name and ignoring whole definition (reserved DCxx0 - ignore name, DCxx1 - ignore definition).
181
+ - [ ] Allow to disable each check separately using:
182
+ - [ ] inline comment.
183
+ - [ ] pyproject.toml file
184
+ - [ ] Add a check for code in comments.
185
+ - [ ] Add target python version option, if specified it will be used for code base check.
186
+ - [ ] Add a `--depth` parameter to ignore nested code.. (To only check global scope use 0).
187
+ - [ ] Add options:
188
+ - [x] --ignore-definitions
189
+ - [x] --ignore-definitions-if-inherits-from
190
+ - [ ] --ignore-definitions-if-decorated-with
191
+ - [ ] --ignore-names-if-inherits-from
192
+ - [ ] --ignore-names-if-decorated-with
193
+ - [ ] --ignore-bodies-of
194
+ - [ ] --ignore-bodies-if-decorated-with
195
+ - [ ] --ignore-bodies-if-inherits-from
196
+ - [ ] --ignore-definitions
197
+ - [ ] --ignore-definitions-if-inherits-from
198
+ - [ ] --ignore-definitions-if-decorated-with
199
+ - Question: would it be possible to ignore only certain types of checks for a body, e.g. only variable attributes of TypedDict and still check usage of methods and properties?
200
+ - What expression would allow this type of precission?
201
+ - [ ] Distinguish between definitions with same name, but different files.
202
+ - [ ] Repeated application of `deadcode` till the output stops changing.
203
+ - [ ] Unreachable code detection and fixing: this should only be scoped for if statements and only limited to primitive variables.
204
+ - [ ] Benchmarking performance with larger projects (time, CPU and memory consumption) in order to optimize.
205
+ - [ ] `--fix` could accept a list of filenames as well (only those files would be changed, but the summary could would be full).
206
+ (This might be confusing, because filenames, which have to be considered are provided without any flag, --fix is expected to not accept arguments)
207
+ - [ ] pre-commit-hook.
208
+ - [ ] language server.
209
+ - [ ] DC10: remove code after terminal statements like `raise`, `return`, `break`, `continue` and comes in the same scope.
210
+ - [ ] Add `ignore` and `per-file-ignores` command line and pyproject.toml options, which allows to skip some rules.
211
+ - [ ] Make sure that all rules are being skipped by `noqa` comment and all rules react to `noqa: rule_id` comments.
212
+ - [ ] Include package names into code item scope (dot-separated path), e.g. "package1.package2.module.class.method.variable".
213
+ - [ ] All options should be able to accept dot-separated path or a generic name, e.g. "marshmallow.Schema" vs "Schema",
214
+ documentation should cleary demonstrate the behaviour/example that "Schema" means "*.Schema".
215
+ - [ ] Redefinition of an existing name makes previous name unreachable, unless it is assigned somehow.
216
+ - [ ] Check if file is still valid/parsable after automatic fixing, if not: halt the change and report error.
217
+ - [ ] Investigate ways of extracting and backporting Python3.10+ `ast` implementation to lower Python versions.
218
+
219
+ ## Release notes
220
+ - v2.6.0:
221
+ - Add `--ignore-class-attributes` option to not report unused attributes assigned directly
222
+ in a class body (e.g. `THING = "blah"` inside `class Foo:`), since such attributes may
223
+ control behaviour of inherited/overridden methods, external frameworks, or metaclasses.
224
+ - v2.5.0:
225
+ - Add `--ignore-non-self-attributes` option to not report unused attributes assigned on
226
+ objects other than `self` (e.g. `foo.bar = 1`), since such assignments may have side
227
+ effects or be consumed by code outside of the analysed files.
228
+ - v2.4.2:
229
+ - Add `--tach-config` option to read `tach.toml` file(s) and treat names exposed via `[[interfaces]]`
230
+ as public API, and skip `unchecked = true` modules entirely.
231
+ - v2.4.1:
232
+ - Add `--version` option to show `deadcode` version.
233
+ - Use stdout for `deadcode` output.
234
+ - v2.4.0:
235
+ - Add `--only` option that accepts filenames only which will be reflected in the output and modified.
236
+ This option can be used with `--fix` and `--fix --dry` options as well as for simple unused code detection without fixing.
237
+ - v2.3.2:
238
+ - Add `pre-commit` hook support.
239
+ - Drop support for Python 3.8 and 3.9 versions, since their `ast` implementation is lacking features.
240
+ - v2.3.1:
241
+ - Started analysing files in bytes instead of trying to convert them into UTF-8 encoded strings.
242
+ - Improved automatic removal of unused imports.
243
+ - v2.3.0:
244
+ - Add `--dry` option.
245
+ - Update error codes to use DCXX format instead of DCXXX.
246
+
@@ -0,0 +1,6 @@
1
+ lapsed-3.2.0.data/scripts/deadcode.exe,sha256=_rO2qdV1CgmH_8jaG-NGradFNGI01Px8p-2rkt3KZnA,3493376
2
+ lapsed-3.2.0.dist-info/METADATA,sha256=ee0wdsBAgXIhOEXqsiziO--c6GSFw2YerX15rwZlR5I,14494
3
+ lapsed-3.2.0.dist-info/WHEEL,sha256=bdMjkx77UosG9StsdhmkZ5NINL9k1Yz_ErcKcnkk7WA,90
4
+ lapsed-3.2.0.dist-info/licenses/LICENSE,sha256=bx5iLIKjgAdYQ7sISn7DsfHRKkoCUm1154sJJKhgqnU,35184
5
+ lapsed-3.2.0.dist-info/sboms/lapsed.cyclonedx.json,sha256=4qn4yCeklSMY01oMruQKggCFGjWwIlySZrbyF88cxhQ,118486
6
+ lapsed-3.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.15.0)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win32