code-metadata 0.1.0__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.
- code_metadata-0.1.0/.claude/settings.local.json +5 -0
- code_metadata-0.1.0/.gitignore +8 -0
- code_metadata-0.1.0/.serena/.gitignore +2 -0
- code_metadata-0.1.0/.serena/project.local.yml +5 -0
- code_metadata-0.1.0/.serena/project.yml +169 -0
- code_metadata-0.1.0/CLAUDE.md +70 -0
- code_metadata-0.1.0/PKG-INFO +16 -0
- code_metadata-0.1.0/README.md +122 -0
- code_metadata-0.1.0/graphify-out/.graphify_ast.json +6676 -0
- code_metadata-0.1.0/graphify-out/.graphify_chunk_01.json +1 -0
- code_metadata-0.1.0/graphify-out/.graphify_chunk_02.json +1 -0
- code_metadata-0.1.0/graphify-out/.graphify_communities.json +322 -0
- code_metadata-0.1.0/graphify-out/.graphify_community_labels.json +22 -0
- code_metadata-0.1.0/graphify-out/.graphify_detect.json +1 -0
- code_metadata-0.1.0/graphify-out/.graphify_merged.json +8040 -0
- code_metadata-0.1.0/graphify-out/.graphify_nx.pkl +0 -0
- code_metadata-0.1.0/graphify-out/.graphify_python +1 -0
- code_metadata-0.1.0/graphify-out/.graphify_uncached.txt +21 -0
- code_metadata-0.1.0/graphify-out/GRAPH_REPORT.md +88 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/0909e99546b86054b78ed066b38d4b19f141d1b0c3fbe4866b12032e999ebdbc.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/0fce32351afd2b9cb2bef506486476cc534f0d9865c736aa84cb49fab1ae708b.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/0fe5000f7bebec662b475a288d774f09d905ac100f92066da2a9e2cbc84164be.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/127a71906d335db61f892da869cca780d24e0d5a546a192ee372cea348ee4c70.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/1bbc804667f902547034cecb9d5f640326cf8ffb500ba17c14eadcde6338cb5c.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/69790238a4225262ec003a2776ffe74113b8e53fbf40e26d954af2318fc30249.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/8c1dd68a9037c6149183c7e76d8587498ea020287ff83a31e88f5c80522743c1.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/8fcc7ce568c98f754697396fad551865064f1e9b4093f81438c49a5518713132.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/902512070e4e7c674f9b3b8cc72adb649e4d1f1e14365efaeb19f9335a1d9da6.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/9766508e5a013c3d3cbb2602719391199e90af5720c9782a77ca71565aa346b1.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/a718c242324477d37bf1ecc9e195e2f65bd408487a86d9865c496cade209020c.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/a8fac968336f4b21373031388fb59558c60e1904298e9138d127b0035ac7b4bc.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/be5cf9527c1c6899103153446c27c60a6fd12c9ef062529c4f4b888438494140.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/c321a753cad3211bb238c033793f5a9a60695569cc30bd3d8edca014769141e0.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/d210f4364c89007af948d2ff9fe4dde1c24a4e75ca113663875dad86934714a9.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/e334ce55ffe09e1ccbce2c3cb2ac915774acc5b1c050d53ec1149c8f8a21b4e4.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/e5aeb0b9f54810748c8a83843e5c2b77c26ace866d98eedc917bfc8de3e51d5f.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/ef94ac612fb9ebc8d58877ad8990cda0b5a4013067e63bbd00ee3943f290123e.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/ast/v0.9.36/f9e7ee001f572ff9cf2b491bcf51e305cc7552738bdda0ee62c7ccc887c01c71.json +1 -0
- code_metadata-0.1.0/graphify-out/cache/stat-index.json +1 -0
- code_metadata-0.1.0/graphify-out/graph.html +320 -0
- code_metadata-0.1.0/graphify-out/graph.json +8768 -0
- code_metadata-0.1.0/pyproject.toml +46 -0
- code_metadata-0.1.0/src/code_metadata/__init__.py +0 -0
- code_metadata-0.1.0/src/code_metadata/analyzer.py +168 -0
- code_metadata-0.1.0/src/code_metadata/cli.py +178 -0
- code_metadata-0.1.0/src/code_metadata/docstring_scorer.py +116 -0
- code_metadata-0.1.0/src/code_metadata/exporters.py +82 -0
- code_metadata-0.1.0/src/code_metadata/git_utils.py +134 -0
- code_metadata-0.1.0/src/code_metadata/parser.py +146 -0
- code_metadata-0.1.0/src/code_metadata/schema.py +88 -0
- code_metadata-0.1.0/src/code_metadata/summarizer.py +50 -0
- code_metadata-0.1.0/tests/__init__.py +0 -0
- code_metadata-0.1.0/tests/fixtures/__init__.py +0 -0
- code_metadata-0.1.0/tests/fixtures/sample_module.py +91 -0
- code_metadata-0.1.0/tests/fixtures/test_sample_module.py +11 -0
- code_metadata-0.1.0/tests/test_analyzer.py +215 -0
- code_metadata-0.1.0/tests/test_docstring_scorer.py +192 -0
- code_metadata-0.1.0/tests/test_exporters.py +97 -0
- code_metadata-0.1.0/tests/test_git_utils.py +154 -0
- code_metadata-0.1.0/tests/test_integration.py +157 -0
- code_metadata-0.1.0/tests/test_parser.py +133 -0
- code_metadata-0.1.0/tests/test_summarizer.py +77 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# This file allows you to locally override settings in project.yml for development purposes.
|
|
2
|
+
#
|
|
3
|
+
# Use the same keys as in project.yml here. Any setting you specify will override the corresponding
|
|
4
|
+
# setting in project.yml, allowing you to customise the configuration for your local development environment
|
|
5
|
+
# without affecting the project configuration in project.yml (which is intended to be versioned).
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# the name by which the project can be referenced within Serena/when chatting with the LLM.
|
|
2
|
+
project_name: "code-metadata-extractor"
|
|
3
|
+
|
|
4
|
+
# list of language servers to start when using the LSP backend; choose from:
|
|
5
|
+
# ada al angular ansible bash
|
|
6
|
+
# bsl clojure cpp cpp_ccls crystal
|
|
7
|
+
# csharp csharp_omnisharp cue dart deno
|
|
8
|
+
# elixir elm erlang fortran fsharp
|
|
9
|
+
# gdscript gleam go groovy haskell
|
|
10
|
+
# haxe hlsl html java json
|
|
11
|
+
# julia julia_fatou kotlin latex lean4
|
|
12
|
+
# lua luau markdown matlab msl
|
|
13
|
+
# nextflow nix ocaml pascal perl
|
|
14
|
+
# php php_phpactor php_phpantom powershell python
|
|
15
|
+
# python_basedpyright python_jedi python_pyrefly python_ty qml
|
|
16
|
+
# r rego ruby ruby_solargraph rust
|
|
17
|
+
# scala scss solidity svelte swift
|
|
18
|
+
# systemverilog terraform toml typescript typescript_vts
|
|
19
|
+
# vue wolfram yaml zig
|
|
20
|
+
# (This list may be outdated; generated with scripts/print_language_list.py;
|
|
21
|
+
# For the current list, see values of the LanguageServerId enum here:
|
|
22
|
+
# https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py)
|
|
23
|
+
# For some languages, there are several alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
|
|
24
|
+
# Note:
|
|
25
|
+
# - For C, use cpp
|
|
26
|
+
# - For JavaScript, use typescript
|
|
27
|
+
# - For Angular projects, use angular (subsumes typescript+html; requires `npm install` in the project root)
|
|
28
|
+
# - For Svelte projects, use svelte (subsumes typescript/javascript for .svelte projects; requires npm)
|
|
29
|
+
# - For Deno projects, use deno (serves the same .ts/.js files as typescript; requires the deno CLI on PATH)
|
|
30
|
+
# - For SCSS / Sass / plain CSS, use scss (some-sass-language-server handles all three)
|
|
31
|
+
# - For Free Pascal/Lazarus, use pascal
|
|
32
|
+
# Special requirements:
|
|
33
|
+
# Some language servers require additional setup/installations.
|
|
34
|
+
# See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers
|
|
35
|
+
# When using multiple language servers, the first language server that supports a given file will be used for that file.
|
|
36
|
+
# The first language server is the default language and the respective language server will be used as a fallback.
|
|
37
|
+
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
|
|
38
|
+
language_servers:
|
|
39
|
+
- python
|
|
40
|
+
|
|
41
|
+
# the encoding used by text files in the project
|
|
42
|
+
# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
|
|
43
|
+
encoding: "utf-8"
|
|
44
|
+
|
|
45
|
+
# optional shell command to run before the language backend (LSP or JetBrains) is initialised.
|
|
46
|
+
# the command runs in the project root directory and is only executed if the project is trusted
|
|
47
|
+
# (see trusted_project_path_patterns in the global configuration).
|
|
48
|
+
# serena waits for the command to exit: a non-zero exit code is logged as an error but does not
|
|
49
|
+
# abort activation. a per-project timeout (activation_command_timeout, default 180s) is the safety
|
|
50
|
+
# backstop for non-terminating commands; on expiry the process is killed and activation continues.
|
|
51
|
+
# example: activation_command: "npx nx run-many -t build"
|
|
52
|
+
activation_command:
|
|
53
|
+
|
|
54
|
+
# maximum time in seconds to wait for activation_command to complete before killing it (default 180s).
|
|
55
|
+
# must be a positive number.
|
|
56
|
+
activation_command_timeout: 180.0
|
|
57
|
+
|
|
58
|
+
# line ending convention to use when writing source files.
|
|
59
|
+
# Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)
|
|
60
|
+
# This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.
|
|
61
|
+
line_ending:
|
|
62
|
+
|
|
63
|
+
# The language backend to use for this project.
|
|
64
|
+
# If not set, the global setting from serena_config.yml is used.
|
|
65
|
+
# Valid values: LSP, JetBrains
|
|
66
|
+
# Note: the backend is fixed at startup. If a project with a different backend
|
|
67
|
+
# is activated post-init, an error will be returned.
|
|
68
|
+
language_backend:
|
|
69
|
+
|
|
70
|
+
# whether to use project's .gitignore files to ignore files
|
|
71
|
+
ignore_all_files_in_gitignore: true
|
|
72
|
+
|
|
73
|
+
# advanced configuration option allowing to configure language server-specific options.
|
|
74
|
+
# Maps the language key to the options.
|
|
75
|
+
# The settings are considered only if the project is trusted (see global configuration to define trusted projects).
|
|
76
|
+
# See https://oraios.github.io/serena/02-usage/050_configuration.html#language-server-specific-settings
|
|
77
|
+
ls_specific_settings: {}
|
|
78
|
+
|
|
79
|
+
# list of workspace folder paths (LSP backend only).
|
|
80
|
+
# These folders will be used to build up Serena's symbol index.
|
|
81
|
+
# Paths must be within the project root and should thus be relative to the project root.
|
|
82
|
+
# Furthermore, the paths should not be filtered by ignore settings.
|
|
83
|
+
# Default setting: The entire project root folder (".") is considered.
|
|
84
|
+
# In (large) monorepos, this can be used to index only subfolders of the project root, e.g.
|
|
85
|
+
# ls_workspace_folders:
|
|
86
|
+
# - "./subproject1"
|
|
87
|
+
# - "./subproject2"
|
|
88
|
+
ls_workspace_folders:
|
|
89
|
+
- "."
|
|
90
|
+
|
|
91
|
+
# list of additional workspace folder paths for cross-package reference support.
|
|
92
|
+
# Paths can be absolute or relative to the project root.
|
|
93
|
+
# Each folder is registered as an LSP workspace folder, enabling language servers to discover
|
|
94
|
+
# symbols and references across package boundaries, but these folders are not indexed by Serena,
|
|
95
|
+
# i.e. the respective symbols will not be found using Serena's symbol search tools.
|
|
96
|
+
# Example:
|
|
97
|
+
# additional_workspace_folders:
|
|
98
|
+
# - ../sibling-package
|
|
99
|
+
# - ../shared-lib
|
|
100
|
+
ls_additional_workspace_folders: []
|
|
101
|
+
|
|
102
|
+
# list of additional paths to ignore in this project.
|
|
103
|
+
# Same syntax as gitignore, so you can use * and **.
|
|
104
|
+
# Important: quote patterns that start with `*`, otherwise YAML treats them as aliases.
|
|
105
|
+
# Example:
|
|
106
|
+
# ignored_paths:
|
|
107
|
+
# - "examples/**"
|
|
108
|
+
# - ".worktrees/**"
|
|
109
|
+
# - "**/bin/**"
|
|
110
|
+
# - "**/obj/**"
|
|
111
|
+
# Note: global ignored_paths from serena_config.yml are also applied additively.
|
|
112
|
+
ignored_paths: []
|
|
113
|
+
|
|
114
|
+
# whether the project is in read-only mode
|
|
115
|
+
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
|
|
116
|
+
# Added on 2025-04-18
|
|
117
|
+
read_only: false
|
|
118
|
+
|
|
119
|
+
# list of tool names to exclude.
|
|
120
|
+
# This extends the existing exclusions (e.g. from the global configuration)
|
|
121
|
+
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
|
|
122
|
+
excluded_tools: []
|
|
123
|
+
|
|
124
|
+
# list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default).
|
|
125
|
+
# This extends the existing inclusions (e.g. from the global configuration).
|
|
126
|
+
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
|
|
127
|
+
included_optional_tools: []
|
|
128
|
+
|
|
129
|
+
# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.
|
|
130
|
+
# This cannot be combined with non-empty excluded_tools or included_optional_tools.
|
|
131
|
+
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
|
|
132
|
+
fixed_tools: []
|
|
133
|
+
|
|
134
|
+
# list of mode names that are to be activated by default, overriding the setting in the global configuration.
|
|
135
|
+
# The full set of modes to be activated is base_modes (from global config) + default_modes + added_modes.
|
|
136
|
+
# If the setting is undefined/empty, the default_modes from the global configuration (serena_config.yml) apply.
|
|
137
|
+
# Otherwise, this overrides the setting from the global configuration (serena_config.yml).
|
|
138
|
+
# Therefore, you can set this to [] if you do not want the default modes defined in the global config to apply
|
|
139
|
+
# for this project.
|
|
140
|
+
# This setting can, in turn, be overridden by CLI parameters (--mode).
|
|
141
|
+
# See https://oraios.github.io/serena/02-usage/050_configuration.html#modes
|
|
142
|
+
default_modes:
|
|
143
|
+
|
|
144
|
+
# list of mode names to be activated additionally for this project, e.g. ["query-projects"]
|
|
145
|
+
# The full set of modes to be activated is base_modes (from global config) + default_modes + added_modes.
|
|
146
|
+
# See https://oraios.github.io/serena/02-usage/050_configuration.html#modes
|
|
147
|
+
added_modes:
|
|
148
|
+
|
|
149
|
+
# initial prompt for the project. It will always be given to the LLM upon activating the project
|
|
150
|
+
# (contrary to the memories, which are loaded on demand).
|
|
151
|
+
initial_prompt: ""
|
|
152
|
+
|
|
153
|
+
# time budget (seconds) per tool call for the retrieval of additional symbol information
|
|
154
|
+
# such as docstrings or parameter information.
|
|
155
|
+
# This overrides the corresponding setting in the global configuration; see the documentation there.
|
|
156
|
+
# If null or missing, use the setting from the global configuration.
|
|
157
|
+
symbol_info_budget:
|
|
158
|
+
|
|
159
|
+
# list of regex patterns which, when matched, mark a memory entry as read‑only.
|
|
160
|
+
# Extends the list from the global configuration, merging the two lists.
|
|
161
|
+
read_only_memory_patterns: []
|
|
162
|
+
|
|
163
|
+
# list of regex patterns for memories to completely ignore.
|
|
164
|
+
# Matching memories will not appear in list_memories or activate_project output
|
|
165
|
+
# and cannot be accessed via read_memory or write_memory.
|
|
166
|
+
# To access ignored memory files, use the read_file tool on the raw file path.
|
|
167
|
+
# Extends the list from the global configuration, merging the two lists.
|
|
168
|
+
# Example: ["_archive/.*", "_episodes/.*"]
|
|
169
|
+
ignored_memory_patterns: []
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
# code-metadata-extractor
|
|
6
|
+
|
|
7
|
+
Python-only repository metadata extraction tool. AST-based, no LLM in MVP.
|
|
8
|
+
|
|
9
|
+
## Stack
|
|
10
|
+
|
|
11
|
+
- Python 3.11+
|
|
12
|
+
- `radon` — cyclomatic complexity + LOC
|
|
13
|
+
- `gitpython` — git blame (author, date, commit count)
|
|
14
|
+
- `pydantic` v2 — schema / validation
|
|
15
|
+
- `typer` + `rich` — CLI
|
|
16
|
+
- `ruff` — lint/format
|
|
17
|
+
- `pytest` + `pytest-cov` — tests (target: 80%+, currently 95 tests / 94.6%)
|
|
18
|
+
|
|
19
|
+
## Commands
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Setup
|
|
23
|
+
pip install -e ".[dev]"
|
|
24
|
+
|
|
25
|
+
# Run all tests (coverage enforced via pyproject addopts, fails under 80%)
|
|
26
|
+
pytest
|
|
27
|
+
|
|
28
|
+
# Run a single test file / test
|
|
29
|
+
pytest tests/test_parser.py
|
|
30
|
+
pytest tests/test_parser.py::test_parses_function_params -v
|
|
31
|
+
|
|
32
|
+
# Lint / format
|
|
33
|
+
ruff check src/
|
|
34
|
+
ruff format src/ tests/
|
|
35
|
+
|
|
36
|
+
# Run the CLI locally
|
|
37
|
+
code-metadata extract /path/to/repo --format json
|
|
38
|
+
code-metadata extract /path/to/repo --format csv --output out.csv
|
|
39
|
+
code-metadata extract /path/to/repo --no-git # skip git blame, works on non-git dirs
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Architecture
|
|
43
|
+
|
|
44
|
+
The extractor is a linear enrichment pipeline, orchestrated by `extract_repo()` in `cli.py`. Each `.py` file under the target repo flows through the same sequence of mutation passes before being validated into the final Pydantic schema:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
parser.parse_file(path) → raw dict: functions/classes/imports/total_lines (per file, AST-only)
|
|
48
|
+
→ analyzer.enrich_file(parsed, source, test_index) → adds complexity (radon), LOC, has_test/test_files
|
|
49
|
+
→ docstring_scorer.enrich_docstrings(parsed) → adds docstring style + quality_score (0-1)
|
|
50
|
+
→ git_utils.enrich_git(parsed) → adds git_metadata (or None if --no-git / non-git repo)
|
|
51
|
+
→ cli._to_file_metadata(parsed) → validates into schema.FileMetadata (Pydantic)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Key points for working in this codebase:
|
|
55
|
+
|
|
56
|
+
- **Dicts until the end.** `parser.py`, `analyzer.py`, `docstring_scorer.py`, and `git_utils.py` all mutate plain `dict` structures in place (functions/classes as nested dicts with a `methods` list). Pydantic validation (`schema.py` models) only happens once, at the very end, in `cli._to_file_metadata` / `_to_class_metadata` / `_to_function_metadata`. Don't introduce schema objects earlier in the pipeline — the enrichment stages are intentionally schema-agnostic.
|
|
57
|
+
- **`build_test_index(root)` runs once per repo** (in `analyzer.py`), before the per-file loop, and is passed into every `enrich_file` call — it scans all `test_*.py`/`*_test.py` files up front so each function lookup for `has_test` is a dict lookup, not a re-scan.
|
|
58
|
+
- **Git blame is cached per file**, not per function/method — `git_utils.py` calls `git blame` once per file and slices results per line range, keeping cost linear in files rather than functions.
|
|
59
|
+
- **Errors are contained per-file.** A file that fails Pydantic validation in `extract_repo` is caught and skipped with a console warning (`cli.py`), not aborted — the run always produces output for whatever parsed successfully. A file with a Python `SyntaxError` is not skipped outright; `parser.parse_file` returns it with empty functions/classes and a `parse_error` field instead of raising.
|
|
60
|
+
- **Docstring scoring is heuristic, not semantic** (`docstring_scorer.py`): style detection (numpy/google/sphinx/unstructured/none) plus presence of args/returns/example sections, no LLM. This is called out in design decisions below because it's the most likely thing a future contributor will assume is "just a stub" — it's the intended MVP behavior.
|
|
61
|
+
- **Test coverage is inferred, not measured**: `analyzer.py` looks for a `test_<funcname>` symbol in `test_*.py`/`*_test.py` files, it does not run the target repo's test suite or read coverage data.
|
|
62
|
+
- **Exporters (`exporters.py`) consume the fully-validated `RepositoryMetadata`** — CSV flattening logic (methods promoted to top-level rows with `parent_class` set) lives only there, not upstream.
|
|
63
|
+
|
|
64
|
+
## Design decisions
|
|
65
|
+
|
|
66
|
+
- Git integration is optional: non-git repos produce `git_metadata: null`, no crash.
|
|
67
|
+
- Blame is cached per file (one call per file, not per function line).
|
|
68
|
+
- Docstring style detection: numpy / google / sphinx / unstructured / none — heuristic, no LLM.
|
|
69
|
+
- Test coverage is *inferred*: presence of `test_<funcname>` in `test_*.py` or `*_test.py`.
|
|
70
|
+
- No domain-agnostic abstraction in MVP — code domain only, generalize after shipping.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: code-metadata
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python repository metadata extractor — AST-based, no LLM
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: gitpython>=3.1
|
|
7
|
+
Requires-Dist: pydantic>=2.0
|
|
8
|
+
Requires-Dist: radon>=6.0
|
|
9
|
+
Requires-Dist: rich>=13.0
|
|
10
|
+
Requires-Dist: typer>=0.12
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
13
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
14
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
15
|
+
Provides-Extra: llm
|
|
16
|
+
Requires-Dist: anthropic>=0.34; extra == 'llm'
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# code-metadata-extractor
|
|
2
|
+
|
|
3
|
+
Extract rich metadata from Python repositories — no LLM, no API keys, fully deterministic.
|
|
4
|
+
|
|
5
|
+
Walks every `.py` file via AST and produces structured data on functions, methods, and classes: complexity, docstring quality, git history, and inferred test coverage.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
| Metadata | Source |
|
|
10
|
+
|---|---|
|
|
11
|
+
| Cyclomatic complexity | `radon` |
|
|
12
|
+
| Lines of code | `radon` |
|
|
13
|
+
| Docstring quality score (0–1) | Heuristic: style detection + section presence |
|
|
14
|
+
| Docstring style | numpy / google / sphinx / unstructured / none |
|
|
15
|
+
| Git blame (author, date, commit count) | `gitpython` — cached per file |
|
|
16
|
+
| Test coverage (inferred) | Detect `test_<funcname>` in `test_*.py` / `*_test.py` |
|
|
17
|
+
| Type hints, decorators, async flag | `ast` |
|
|
18
|
+
| Import-level dependencies per function | `ast` call-site analysis |
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install -e ".[dev]"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Requires Python 3.11+.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# JSON to stdout
|
|
32
|
+
code-metadata extract /path/to/repo
|
|
33
|
+
|
|
34
|
+
# CSV to file
|
|
35
|
+
code-metadata extract /path/to/repo --format csv --output metadata.csv
|
|
36
|
+
|
|
37
|
+
# Skip git blame (faster, works on non-git directories)
|
|
38
|
+
code-metadata extract /path/to/repo --no-git
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Output shape (JSON)
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"repository_path": "/path/to/repo",
|
|
46
|
+
"analyzed_at": "2026-09-10T12:00:00Z",
|
|
47
|
+
"total_files": 12,
|
|
48
|
+
"total_functions": 84,
|
|
49
|
+
"total_classes": 9,
|
|
50
|
+
"files": [
|
|
51
|
+
{
|
|
52
|
+
"file_path": "/path/to/repo/module.py",
|
|
53
|
+
"total_lines": 120,
|
|
54
|
+
"import_count": 5,
|
|
55
|
+
"functions": [
|
|
56
|
+
{
|
|
57
|
+
"name": "parse_record",
|
|
58
|
+
"line_number": 14,
|
|
59
|
+
"end_line_number": 38,
|
|
60
|
+
"is_async": false,
|
|
61
|
+
"is_method": false,
|
|
62
|
+
"return_type": "dict",
|
|
63
|
+
"params": [{"name": "raw", "type_hint": "str"}],
|
|
64
|
+
"complexity": {
|
|
65
|
+
"cyclomatic_complexity": 4,
|
|
66
|
+
"lines_of_code": 25,
|
|
67
|
+
"has_test": true,
|
|
68
|
+
"test_files": ["tests/test_module.py"],
|
|
69
|
+
"dependencies": ["json.loads", "re.match"]
|
|
70
|
+
},
|
|
71
|
+
"docstring_quality": {
|
|
72
|
+
"presence": true,
|
|
73
|
+
"style": "google",
|
|
74
|
+
"has_args_section": true,
|
|
75
|
+
"has_return_section": true,
|
|
76
|
+
"has_example": false,
|
|
77
|
+
"quality_score": 0.7
|
|
78
|
+
},
|
|
79
|
+
"git_metadata": {
|
|
80
|
+
"author": "Alice",
|
|
81
|
+
"author_email": "alice@example.com",
|
|
82
|
+
"last_modified": "2026-08-01T09:30:00Z",
|
|
83
|
+
"commit_count": 7
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
"classes": []
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## CSV columns
|
|
94
|
+
|
|
95
|
+
`file_path`, `name`, `line_number`, `end_line_number`, `is_method`, `is_async`, `parent_class`, `decorators`, `return_type`, `cyclomatic_complexity`, `lines_of_code`, `docstring_lines`, `has_test`, `has_docstring`, `docstring_score`, `docstring_style`, `git_author`, `git_last_modified`, `git_commit_count`
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Run tests with coverage
|
|
101
|
+
pytest
|
|
102
|
+
|
|
103
|
+
# Lint
|
|
104
|
+
ruff check src/
|
|
105
|
+
|
|
106
|
+
# Format
|
|
107
|
+
ruff format src/ tests/
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
95 tests, 94.6% coverage.
|
|
111
|
+
|
|
112
|
+
## Design notes
|
|
113
|
+
|
|
114
|
+
- **No LLM in MVP** — all extraction is deterministic and free. LLM-based semantic docstring scoring is a planned post-MVP addition.
|
|
115
|
+
- **Git is optional** — non-git directories produce `git_metadata: null`, no crash.
|
|
116
|
+
- **Blame is cached per file** — one `git blame` call per file, not per function line.
|
|
117
|
+
- **Test coverage is inferred** — presence of `test_<funcname>` in test files, not actual execution coverage.
|
|
118
|
+
- **Single domain first** — code only; generalise to other domains after shipping value.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT
|