codevariability 0.2.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.
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: codevariability
3
+ Version: 0.2.0
4
+ Summary: Source-code similarity matrices, representative rankings, and independent group comparison.
5
+ Author: Otávio Gomes
6
+ Maintainer: Otávio Gomes
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://github.com/otaviouss/codevariability-py
9
+ Project-URL: Documentation, https://github.com/otaviouss/codevariability-py/tree/main/docs
10
+ Project-URL: Source, https://github.com/otaviouss/codevariability-py
11
+ Project-URL: Issues, https://github.com/otaviouss/codevariability-py/issues
12
+ Keywords: code similarity,source code analysis,ast,software metrics
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: numpy>=1.23
24
+ Requires-Dist: pandas>=2.0
25
+ Requires-Dist: scikit-learn>=1.5.0
26
+ Requires-Dist: rapidfuzz>=3.0
27
+ Requires-Dist: Pygments<3,>=2.20.0
28
+ Requires-Dist: openpyxl>=3.1
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=9.0.3; extra == "dev"
31
+ Requires-Dist: hypothesis>=6.168.3; extra == "dev"
32
+ Requires-Dist: mypy>=2.4; extra == "dev"
33
+ Requires-Dist: ruff>=0.14; extra == "dev"
34
+ Requires-Dist: build>=1.2; extra == "dev"
35
+ Requires-Dist: twine>=6; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # CodeVariability for Python
39
+
40
+ CodeVariability compares UTF-8 source-code files and returns similarity
41
+ matrices, descriptive statistics, representative rankings, and comparisons
42
+ between independent groups. It helps you identify common structures and
43
+ unusual variants in a collection without executing the submitted code.
44
+
45
+ Version **0.2.0** is the first release of this independent repository. The API is alpha. The distribution name is `codevariability`;
46
+ the import name and command are `codevariability`.
47
+
48
+ ## Installation
49
+
50
+ Python 3.10 or later is required. Install from PyPI:
51
+
52
+ ```bash
53
+ python -m pip install codevariability==0.2.0
54
+ ```
55
+
56
+ For development, install a checkout with `python -m pip install .`.
57
+ The historical 0.1.2 code is the implementation baseline; 0.2.0 is the first
58
+ public PyPI release. Use a new virtual environment when migrating from a
59
+ local historical installation.
60
+
61
+ ## Quick start
62
+
63
+ This example creates its own inputs and works with an installed package:
64
+
65
+ ```python
66
+ from pathlib import Path
67
+ from tempfile import TemporaryDirectory
68
+ from codevariability import analyze
69
+
70
+ with TemporaryDirectory() as directory:
71
+ folder = Path(directory)
72
+ (folder / "a.py").write_text("def total(a, b):\n return a + b\n", encoding="utf-8")
73
+ (folder / "b.py").write_text("def sum_values(x, y):\n return x + y\n", encoding="utf-8")
74
+ result = analyze(folder, metrics="all")
75
+ print(result.statistics)
76
+ print(result.ranking)
77
+ print(result.most_representative)
78
+ ```
79
+
80
+ The runnable [example](https://github.com/otaviouss/codevariability-py/blob/main/examples/basic.py) also exports JSON, CSV, and Excel.
81
+ For the bundled input files, the CLI is:
82
+
83
+ ```bash
84
+ codevariability analyze examples/inputs --metrics all --output analysis-output
85
+ codevariability analyze examples/inputs --metrics cosine jaccard --output analysis-output/report.xlsx
86
+ ```
87
+
88
+ ## Inputs and metrics
89
+
90
+ Pass a directory or a list of file paths to `analyze()`. Directory scans are
91
+ not recursive. File basenames must be unique. Files are decoded as UTF-8,
92
+ including an optional BOM. Use `extensions="py"` or a list of extensions to
93
+ filter a directory.
94
+
95
+ | Metric | What it compares |
96
+ | --- | --- |
97
+ | `cosine` | Word frequencies in the full document. |
98
+ | `jaccard` | Sets of words in the full document. |
99
+ | `lcs` | The longest common subsequence of code tokens. |
100
+ | `levenshtein` | Token sequences using unit edit costs. |
101
+ | `ast_tree_edit_similarity` | Ordered, normalized Python syntax trees. |
102
+
103
+ `metrics="all"` includes all applicable metrics. Python AST analysis requires
104
+ Python inputs; explicit selection on incompatible inputs raises `AnalysisError`.
105
+ Source files are read in full. For Markdown, token and AST metrics use the
106
+ identified fenced code blocks; textual metrics include the full document.
107
+
108
+ ## Results and export
109
+
110
+ `AnalysisResult` exposes `matrices`, `statistics`, `representativeness`,
111
+ `ranking`, `rankings_by_metric`, `most_representative`, and `most_distinct`.
112
+ Similarities range from 0 to 1. Statistics use each unique pair once. Rankings
113
+ average within each available dimension and then give dimensions equal weight.
114
+
115
+ Use `result.export(directory, formats=("json", "csv"))` for machine-readable
116
+ results and tables, or `result.to_excel(path)` for a workbook. Outputs include
117
+ metric identifiers, normalization and runtime versions, and input hashes.
118
+ Spreadsheet exports escape formula-like labels; JSON retains the original
119
+ labels. See [input/output details](https://github.com/otaviouss/codevariability-py/blob/main/docs/FORMATS.md).
120
+
121
+ `compare_groups()` supports two groups or a mapping of two or more groups,
122
+ file-label permutation tests, and Holm-adjusted p-values. Each group needs at
123
+ least two files and groups must not share physical files. A complete example
124
+ is in [examples/groups.py](https://github.com/otaviouss/codevariability-py/blob/main/examples/groups.py).
125
+
126
+ ## Optional JavaScript integration
127
+
128
+ The Python library works without Node.js. To request structural JavaScript or
129
+ TypeScript analysis through `compare_groups(..., include_ast=True)`, install
130
+ the independent [codevariability-js](https://github.com/otaviouss/codevariability-js)
131
+ package and make its command available on `PATH`. Alternatively, import a
132
+ single-metric JSON with `load_matrix_json()` and attach it with `with_metric()`.
133
+ The Python build and normal test suite require no JavaScript checkout.
134
+
135
+ ## Limits and errors
136
+
137
+ Scores describe text, tokens, or syntax; they do not establish functional
138
+ equivalence, correctness, authorship, or copied-code percentages. AST
139
+ normalization removes concrete names and literal values. Different sources
140
+ can therefore have structural similarity 1.
141
+
142
+ Exact tree comparison can be expensive. The default `max_ted_cells=2_000_000`
143
+ limits tables for each non-identical AST pair; exceeding it raises an error,
144
+ without approximation. `None` removes the limit. It does not limit source
145
+ file size, the full pairwise matrix, or total CPU time. Use trusted output
146
+ directories and apply application-level resource limits for untrusted inputs.
147
+
148
+ Expected input and serialization errors raise `AnalysisError`. JavaScript
149
+ integration also supports `ast_timeout=120` seconds. See the
150
+ [API](https://github.com/otaviouss/codevariability-py/blob/main/docs/API.md) and [metric definitions](https://github.com/otaviouss/codevariability-py/blob/main/docs/METRICS.md) for details.
151
+
152
+ ## Contributing and license
153
+
154
+ See [CONTRIBUTING.md](https://github.com/otaviouss/codevariability-py/blob/main/CONTRIBUTING.md) for development and
155
+ [PUBLICATION_CHECKLIST.md](https://github.com/otaviouss/codevariability-py/blob/main/PUBLICATION_CHECKLIST.md) for release preparation.
156
+ The project uses the [MIT license](https://github.com/otaviouss/codevariability-py/blob/main/LICENSE), copyright 2026 Otávio Gomes.
157
+
158
+ ## Compatibility
159
+
160
+ Arbitrary distinct nonempty group names are
161
+ accepted; use `result.within_group_columns` to locate collision-safe within-group
162
+ means. Keep files unchanged while an analysis runs; optional JavaScript results
163
+ with different input hashes raise `AnalysisError`.
164
+
165
+ Runtime minimums are scikit-learn 1.5.0 and Pygments 2.20.0; build minimum is
166
+ setuptools 83.0.0 and development tests require pytest 9.0.3. These scopes are
167
+ separate. See [API](docs/API.md) and [metric limits](docs/METRICS.md).
168
+
169
+ Python AST normalization now uses v3 to identify corrected empty-program
170
+ behavior. The TED formula ID remains v2; use compatible normalization IDs when
171
+ comparing results across versions.
@@ -0,0 +1,18 @@
1
+ codevariability/__init__.py,sha256=srjZaAHtnsEnfjVG6uXYDVMMhaoUvYhP4DCTk_O-X8c,544
2
+ codevariability/analysis.py,sha256=R1RNb_t5X-PKgMHFKlZmag9_6GiJ65OTH1bPzNxqbcM,27622
3
+ codevariability/ast_tree_edit.py,sha256=qIwP0VTxuvdScYV4CMdHa4F4Bdx8W1LsLK09dGj6T7s,12877
4
+ codevariability/cli.py,sha256=zfNG1BlHOrRqh9P1BRThEyMvCHCQA5kSSMyvaapQoJA,2522
5
+ codevariability/exceptions.py,sha256=8OBSVF2x0HAtm_bJBHYVvMCEh5fdyel0H03g8xM9VmA,85
6
+ codevariability/group_comparison.py,sha256=jc6Glkp_rVy03pzMfiot1VNq03HBMecZ30d-vC-0Wkw,42228
7
+ codevariability/interop.py,sha256=-HzPwR_5GxCXyH7gXopvF4WiIOmiyqj_VN8mnfm3LPw,3797
8
+ codevariability/metrics.py,sha256=u9f1Aa-9b37eTsK16waZop6XFiMPbLwJlWw8Bq5zaxc,3140
9
+ codevariability/normalization.py,sha256=eCO4ddYvDFt2njNrmgLx68NVQ7idG-a990768l9i7P0,7933
10
+ codevariability/output.py,sha256=HbLTEJBGlPB-La0rm44UdqtBaxG_VRa4zvXjIcaH4cE,2418
11
+ codevariability/spreadsheet.py,sha256=0GLcHkZGP6zX8RDlcD7nQsT42lgCIVcKDml73rRgVq8,2198
12
+ codevariability/validation.py,sha256=-QmIbMqV_judKKhDmFXLFxrhasnUEM9qLxiqesVmPlk,4449
13
+ codevariability-0.2.0.dist-info/licenses/LICENSE,sha256=D9r56CkUbcYQxajHJN_WbUo_mKmFeupRfGhvLtJm1oA,1070
14
+ codevariability-0.2.0.dist-info/METADATA,sha256=HRUpVjIkBwrgbda9ZFgW4vDKBK0JS1XrwRypPA74N2c,7993
15
+ codevariability-0.2.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
16
+ codevariability-0.2.0.dist-info/entry_points.txt,sha256=_x7ZYg8c9H38jQ-WGTuPH-Y8h8pt81RaXk8rd-MH_z0,61
17
+ codevariability-0.2.0.dist-info/top_level.txt,sha256=e2BzckcZ3lCvCIcOE-xDidVw58QHJ7n5avhVM1nuPG4,16
18
+ codevariability-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ codevariability = codevariability.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Otávio Gomes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ codevariability