codeclone 1.1.0__py3-none-any.whl → 1.2.1__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.
- codeclone/__init__.py +1 -1
- codeclone/baseline.py +44 -14
- codeclone/blockhash.py +1 -1
- codeclone/blocks.py +4 -3
- codeclone/cache.py +154 -17
- codeclone/cfg.py +128 -38
- codeclone/cfg_model.py +47 -0
- codeclone/cli.py +524 -100
- codeclone/errors.py +27 -0
- codeclone/extractor.py +101 -24
- codeclone/html_report.py +230 -691
- codeclone/normalize.py +43 -13
- codeclone/py.typed +0 -0
- codeclone/report.py +23 -12
- codeclone/scanner.py +66 -3
- codeclone/templates.py +1262 -0
- {codeclone-1.1.0.dist-info → codeclone-1.2.1.dist-info}/METADATA +62 -34
- codeclone-1.2.1.dist-info/RECORD +23 -0
- {codeclone-1.1.0.dist-info → codeclone-1.2.1.dist-info}/WHEEL +1 -1
- codeclone-1.1.0.dist-info/RECORD +0 -19
- {codeclone-1.1.0.dist-info → codeclone-1.2.1.dist-info}/entry_points.txt +0 -0
- {codeclone-1.1.0.dist-info → codeclone-1.2.1.dist-info}/licenses/LICENSE +0 -0
- {codeclone-1.1.0.dist-info → codeclone-1.2.1.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codeclone
|
|
3
|
-
Version: 1.1
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: AST and CFG-based code clone detector for Python focused on architectural duplication
|
|
5
5
|
Author-email: Den Rozhnovskiy <pytelemonbot@mail.ru>
|
|
6
6
|
Maintainer-email: Den Rozhnovskiy <pytelemonbot@mail.ru>
|
|
@@ -10,11 +10,10 @@ Project-URL: Repository, https://github.com/orenlab/codeclone
|
|
|
10
10
|
Project-URL: Issues, https://github.com/orenlab/codeclone/issues
|
|
11
11
|
Project-URL: Changelog, https://github.com/orenlab/codeclone/releases
|
|
12
12
|
Project-URL: Documentation, https://github.com/orenlab/codeclone/tree/main/docs
|
|
13
|
-
Keywords: python,ast,code-clone,duplication,static-analysis,ci
|
|
13
|
+
Keywords: python,ast,cfg,code-clone,duplication,static-analysis,architecture,control-flow,ci
|
|
14
14
|
Classifier: Development Status :: 5 - Production/Stable
|
|
15
15
|
Classifier: Intended Audience :: Developers
|
|
16
16
|
Classifier: Topic :: Software Development :: Quality Assurance
|
|
17
|
-
Classifier: Topic :: Software Development :: Code Generators
|
|
18
17
|
Classifier: Topic :: Software Development :: Testing
|
|
19
18
|
Classifier: Typing :: Typed
|
|
20
19
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -23,26 +22,31 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
23
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
24
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
25
24
|
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
26
26
|
Classifier: Operating System :: OS Independent
|
|
27
27
|
Requires-Python: >=3.10
|
|
28
28
|
Description-Content-Type: text/markdown
|
|
29
29
|
License-File: LICENSE
|
|
30
30
|
Requires-Dist: pygments>=2.19.2
|
|
31
|
+
Requires-Dist: rich>=14.3.2
|
|
31
32
|
Provides-Extra: dev
|
|
32
33
|
Requires-Dist: pytest>=9.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-cov>=6.1.0; extra == "dev"
|
|
33
35
|
Requires-Dist: build>=1.2.0; extra == "dev"
|
|
34
36
|
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
35
37
|
Requires-Dist: mypy>=1.19.1; extra == "dev"
|
|
38
|
+
Requires-Dist: ruff>=0.12.0; extra == "dev"
|
|
36
39
|
Dynamic: license-file
|
|
37
40
|
|
|
38
41
|
# CodeClone
|
|
39
42
|
|
|
40
43
|
[](https://pypi.org/project/codeclone/)
|
|
41
44
|
[](https://pypi.org/project/codeclone/)
|
|
45
|
+
[](https://github.com/orenlab/codeclone/actions/workflows/tests.yml)
|
|
42
46
|
[](https://pypi.org/project/codeclone/)
|
|
43
47
|
[](LICENSE)
|
|
44
48
|
|
|
45
|
-
**CodeClone** is a Python code clone detector based on **normalized AST and
|
|
49
|
+
**CodeClone** is a Python code clone detector based on **normalized Python AST and Control Flow Graphs (CFG)**.
|
|
46
50
|
It helps teams discover architectural duplication and prevent new copy-paste from entering the codebase via CI.
|
|
47
51
|
|
|
48
52
|
CodeClone is designed to help teams:
|
|
@@ -51,15 +55,16 @@ CodeClone is designed to help teams:
|
|
|
51
55
|
- identify architectural hotspots,
|
|
52
56
|
- prevent *new* duplication via CI and pre-commit hooks.
|
|
53
57
|
|
|
54
|
-
Unlike token- or text-based tools, CodeClone operates on **normalized Python AST and CFG**, making it robust against
|
|
55
|
-
formatting, and minor refactoring.
|
|
58
|
+
Unlike token- or text-based tools, CodeClone operates on **normalized Python AST and CFG**, making it robust against
|
|
59
|
+
renaming, formatting, and minor refactoring.
|
|
56
60
|
|
|
57
61
|
---
|
|
58
62
|
|
|
59
63
|
## Why CodeClone?
|
|
60
64
|
|
|
61
65
|
Most existing tools detect *textual* duplication.
|
|
62
|
-
CodeClone detects **structural and block-level duplication**, which usually signals missing abstractions or
|
|
66
|
+
CodeClone detects **structural and block-level duplication**, which usually signals missing abstractions or
|
|
67
|
+
architectural drift.
|
|
63
68
|
|
|
64
69
|
Typical use cases:
|
|
65
70
|
|
|
@@ -77,11 +82,11 @@ Typical use cases:
|
|
|
77
82
|
- Detects functions and methods with identical **control-flow structure**.
|
|
78
83
|
- Based on **Control Flow Graph (CFG)** fingerprinting.
|
|
79
84
|
- Robust to:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
- variable renaming,
|
|
86
|
+
- constant changes,
|
|
87
|
+
- attribute renaming,
|
|
88
|
+
- formatting differences,
|
|
89
|
+
- docstrings and type annotations.
|
|
85
90
|
- Ideal for spotting architectural duplication across layers.
|
|
86
91
|
|
|
87
92
|
### Block-level clone detection (Type-3-lite)
|
|
@@ -89,24 +94,29 @@ Typical use cases:
|
|
|
89
94
|
- Detects repeated **statement blocks** inside larger functions.
|
|
90
95
|
- Uses sliding windows over CFG-normalized statement sequences.
|
|
91
96
|
- Targets:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
- validation blocks,
|
|
98
|
+
- guard clauses,
|
|
99
|
+
- repeated orchestration logic.
|
|
95
100
|
- Carefully filtered to reduce noise:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
- no overlapping windows,
|
|
102
|
+
- no clones inside the same function,
|
|
103
|
+
- no `__init__` noise,
|
|
104
|
+
- size and statement-count thresholds.
|
|
100
105
|
|
|
101
106
|
### Control-Flow Awareness (CFG v1)
|
|
102
107
|
|
|
103
108
|
- Each function is converted into a **Control Flow Graph**.
|
|
104
109
|
- CFG nodes contain normalized AST statements.
|
|
105
|
-
- CFG edges represent structural control flow
|
|
110
|
+
- CFG edges represent structural control flow:
|
|
111
|
+
- `if` / `else`
|
|
112
|
+
- `for` / `async for` / `while`
|
|
113
|
+
- `try` / `except` / `finally`
|
|
114
|
+
- `with` / `async with`
|
|
115
|
+
- `match` / `case` (Python 3.10+)
|
|
106
116
|
- Current CFG semantics (v1):
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
- `break` and `continue` are treated as statements (no jump targets),
|
|
118
|
+
- after-blocks are explicit and always present,
|
|
119
|
+
- focus is on **structural similarity**, not precise runtime semantics.
|
|
110
120
|
|
|
111
121
|
This design keeps clone detection **stable, deterministic, and low-noise**.
|
|
112
122
|
|
|
@@ -115,6 +125,7 @@ This design keeps clone detection **stable, deterministic, and low-noise**.
|
|
|
115
125
|
- AST + CFG normalization instead of token matching.
|
|
116
126
|
- Conservative defaults tuned for real-world Python projects.
|
|
117
127
|
- Explicit thresholds for size and statement count.
|
|
128
|
+
- No probabilistic scoring or heuristic similarity thresholds.
|
|
118
129
|
- Focus on *architectural duplication*, not micro-similarities.
|
|
119
130
|
|
|
120
131
|
### CI-friendly baseline mode
|
|
@@ -154,14 +165,14 @@ Generate reports:
|
|
|
154
165
|
|
|
155
166
|
```bash
|
|
156
167
|
codeclone . \
|
|
157
|
-
--json
|
|
158
|
-
--text
|
|
168
|
+
--json .cache/codeclone/report.json \
|
|
169
|
+
--text .cache/codeclone/report.txt
|
|
159
170
|
```
|
|
160
171
|
|
|
161
172
|
Generate an HTML report:
|
|
162
173
|
|
|
163
174
|
```bash
|
|
164
|
-
codeclone . --html
|
|
175
|
+
codeclone . --html .cache/codeclone/report.html
|
|
165
176
|
```
|
|
166
177
|
|
|
167
178
|
---
|
|
@@ -181,14 +192,26 @@ Commit the generated baseline file to the repository.
|
|
|
181
192
|
### 2. Use in CI
|
|
182
193
|
|
|
183
194
|
```bash
|
|
184
|
-
codeclone . --fail-on-new
|
|
195
|
+
codeclone . --fail-on-new --no-progress
|
|
185
196
|
```
|
|
186
197
|
|
|
187
198
|
Behavior:
|
|
188
199
|
|
|
189
|
-
-
|
|
190
|
-
-
|
|
191
|
-
-
|
|
200
|
+
- existing clones are allowed,
|
|
201
|
+
- the build fails if *new* clones appear,
|
|
202
|
+
- refactoring that removes duplication is always allowed.
|
|
203
|
+
|
|
204
|
+
`--fail-on-new` exits with a non-zero code when new clones are detected.
|
|
205
|
+
|
|
206
|
+
### Python Version Consistency for Baseline Checks
|
|
207
|
+
|
|
208
|
+
Due to inherent differences in Python’s AST between interpreter versions, baseline
|
|
209
|
+
generation and verification must be performed using the same Python version.
|
|
210
|
+
|
|
211
|
+
This ensures deterministic and reproducible clone detection results.
|
|
212
|
+
|
|
213
|
+
CI checks therefore pin baseline verification to a single Python version, while the
|
|
214
|
+
test matrix continues to validate compatibility across Python 3.10–3.14.
|
|
192
215
|
|
|
193
216
|
---
|
|
194
217
|
|
|
@@ -196,14 +219,14 @@ Behavior:
|
|
|
196
219
|
|
|
197
220
|
```yaml
|
|
198
221
|
repos:
|
|
199
|
-
-
|
|
222
|
+
- repo: local
|
|
200
223
|
hooks:
|
|
201
|
-
|
|
224
|
+
- id: codeclone
|
|
202
225
|
name: CodeClone
|
|
203
226
|
entry: codeclone
|
|
204
227
|
language: python
|
|
205
|
-
args: [".", "--fail-on-new"]
|
|
206
|
-
types: [python]
|
|
228
|
+
args: [ ".", "--fail-on-new" ]
|
|
229
|
+
types: [ python ]
|
|
207
230
|
```
|
|
208
231
|
|
|
209
232
|
---
|
|
@@ -235,6 +258,10 @@ repos:
|
|
|
235
258
|
5. Detect function-level and block-level clones.
|
|
236
259
|
6. Apply conservative filters to suppress noise.
|
|
237
260
|
|
|
261
|
+
See the architectural overview:
|
|
262
|
+
|
|
263
|
+
- [docs/architecture.md](docs/architecture.md)
|
|
264
|
+
|
|
238
265
|
---
|
|
239
266
|
|
|
240
267
|
## Control Flow Graph (CFG)
|
|
@@ -245,6 +272,7 @@ to improve structural clone detection robustness.
|
|
|
245
272
|
The CFG is a **structural abstraction**, not a runtime execution model.
|
|
246
273
|
|
|
247
274
|
See full design and semantics:
|
|
275
|
+
|
|
248
276
|
- [docs/cfg.md](docs/cfg.md)
|
|
249
277
|
|
|
250
278
|
---
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
codeclone/__init__.py,sha256=M4X23w41G4ph6fx29JG3qrkkyWaTSwvCe5O6jeJvFd0,364
|
|
2
|
+
codeclone/baseline.py,sha256=Y367RgcTlBwQxkQmm4gGwWft7yhp7u3BMeeWQsZgV6I,2533
|
|
3
|
+
codeclone/blockhash.py,sha256=0vavcw3nkg7IIIqqYRObVmzHSJSC3tbzmiVqqr21miA,594
|
|
4
|
+
codeclone/blocks.py,sha256=BAWb9iPvSWYggQr9SlWIpb-7lyvVvrW0dxjTEnKdm0o,1796
|
|
5
|
+
codeclone/cache.py,sha256=3Ky4ubZZsDvHTwqSRPQ9nPl4t4eCsUtiXCWeNBOZfIo,5493
|
|
6
|
+
codeclone/cfg.py,sha256=XJWb2fcKxa3f6ffRMrQroX6QzkPcByZPNwjhsebbx2g,8236
|
|
7
|
+
codeclone/cfg_model.py,sha256=D2KK4OZrVV-OCwFECw-Ej_u32uekNgj6pdTqCvZa5H0,1170
|
|
8
|
+
codeclone/cli.py,sha256=SjoTSBDNyrjlNhTMze_-Y1GvuZ1nB4wVa027y9XiOgc,20550
|
|
9
|
+
codeclone/errors.py,sha256=3QRu2IR8I-VgJLkT3B9DZ0fW4Sxi-EnBYVUeX3rfWhw,556
|
|
10
|
+
codeclone/extractor.py,sha256=LixKDPJpP2V1UIwW0vsFJm6BKr1NijD8BCGJB3I9lds,6946
|
|
11
|
+
codeclone/fingerprint.py,sha256=H0YY209sfGf02VeLlxHNDp7n6es0vLiMmq3TBWDm3SE,545
|
|
12
|
+
codeclone/html_report.py,sha256=OwVRt4o3DZ17RMDgzI5578bqbyHLqC0mnedmDlYWwag,16369
|
|
13
|
+
codeclone/normalize.py,sha256=BOTgJS5NmJxgBwHFxkqWqRNL1uk9rJtjdeQtSgFscS8,4461
|
|
14
|
+
codeclone/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
codeclone/report.py,sha256=g8EiUksjrQXjJch8-KfJT-IsMkONNnuaj1rNOIfPDbE,2153
|
|
16
|
+
codeclone/scanner.py,sha256=44YbL9fiDauNgwrMbnLijoH3CMWInro4vBsIlBLQu-M,2669
|
|
17
|
+
codeclone/templates.py,sha256=UDEzE_X7n5eWU1CyXChxNhVPM6j3OvVBYDlWcyQaY7I,29375
|
|
18
|
+
codeclone-1.2.1.dist-info/licenses/LICENSE,sha256=ndXAbunvN-jCQjgCaoBOF5AN4FcRlAa0R7hK1lWDuBU,1073
|
|
19
|
+
codeclone-1.2.1.dist-info/METADATA,sha256=Xxe9hqv01xYFZpjmS0gmzAGzobMV5Cyb_MvvkzjL1Vs,8110
|
|
20
|
+
codeclone-1.2.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
21
|
+
codeclone-1.2.1.dist-info/entry_points.txt,sha256=_MI9DVTLOmv3OlxpyogdOmMAduiLVIdHeOlZ_KBsrIY,49
|
|
22
|
+
codeclone-1.2.1.dist-info/top_level.txt,sha256=4tQa_d-4Zle-qV9KmNDkWq0WHYgZsW9vdaeF30rNntg,10
|
|
23
|
+
codeclone-1.2.1.dist-info/RECORD,,
|
codeclone-1.1.0.dist-info/RECORD
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
codeclone/__init__.py,sha256=_MZuqgioYGn49qw6_OluedgcRvuu8IhAwVgHkM4Kj7s,364
|
|
2
|
-
codeclone/baseline.py,sha256=VdIh5AeWeAod6MZ1EV2UWMlvlhwHwlbyUJM_RXbhf24,1545
|
|
3
|
-
codeclone/blockhash.py,sha256=jOswW9jqe9ww3y4r-gLTUZjMmn0CHXpU5qTtFndKQ10,594
|
|
4
|
-
codeclone/blocks.py,sha256=Y75BSpzf-zyyeD9-vKnQfJ3QwIjYxMwiN9DbEqnbONg,1735
|
|
5
|
-
codeclone/cache.py,sha256=PZ9XgHc3A-JSGXHYQHJK_Ldu24EIaGL7Spi2cTpbEUo,1334
|
|
6
|
-
codeclone/cfg.py,sha256=e4zCfHeqWRvxIN1E4D-t_717ZftQY7XlwgYBfFaa9oU,4794
|
|
7
|
-
codeclone/cli.py,sha256=Zp6e7PC-9WJIBkqX88V-4L7wryi1c2qPB87Pbpo4BfE,5177
|
|
8
|
-
codeclone/extractor.py,sha256=crCxgkK1n2fl5FUz6HtbaEZUH5CO8S0zqM0Xj0RSE6E,4558
|
|
9
|
-
codeclone/fingerprint.py,sha256=H0YY209sfGf02VeLlxHNDp7n6es0vLiMmq3TBWDm3SE,545
|
|
10
|
-
codeclone/html_report.py,sha256=Es4lYOMm24O2UTsaF59qjvCxLA2nwojwLX-zOpvluro,24337
|
|
11
|
-
codeclone/normalize.py,sha256=AzKE-1kOrOV3LVK8x4gGytulxXVYBkB0W_3oIqiRWS8,3236
|
|
12
|
-
codeclone/report.py,sha256=2Yu9267M2GLYKqsMAD4mrTUWhTbHP6_fIOGqhtDkxL0,1912
|
|
13
|
-
codeclone/scanner.py,sha256=BdJFyaLv1xvimVkJyvvTN0FcG2RQZzRlTlHWi2fRQnU,1050
|
|
14
|
-
codeclone-1.1.0.dist-info/licenses/LICENSE,sha256=ndXAbunvN-jCQjgCaoBOF5AN4FcRlAa0R7hK1lWDuBU,1073
|
|
15
|
-
codeclone-1.1.0.dist-info/METADATA,sha256=J2l_qX6VxJ_WRCK87KJPuzdVlFI5hcFR9lWjMzuQ55w,6984
|
|
16
|
-
codeclone-1.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
-
codeclone-1.1.0.dist-info/entry_points.txt,sha256=_MI9DVTLOmv3OlxpyogdOmMAduiLVIdHeOlZ_KBsrIY,49
|
|
18
|
-
codeclone-1.1.0.dist-info/top_level.txt,sha256=4tQa_d-4Zle-qV9KmNDkWq0WHYgZsW9vdaeF30rNntg,10
|
|
19
|
-
codeclone-1.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|