codefactory-cli 0.20.1__py3-none-any.whl → 0.20.2__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.
codefactory/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """codefactory: see a codebase as a factory floor and find dead code, duplicates, import loops and bottlenecks."""
2
2
 
3
- __version__ = "0.20.1"
3
+ __version__ = "0.20.2"
codefactory/cli.py CHANGED
@@ -692,7 +692,7 @@ Run `codefactory <command> --help` for a command's options.""",
692
692
  if name == "skill":
693
693
  s.add_argument("--hook", action="store_true", help="also add a session-start hook that keeps codefactory current")
694
694
  if name == "update":
695
- s.add_argument("--source", default=SKILL_SOURCE, help="where to install from (default: the GitHub repository)")
695
+ s.add_argument("--source", default=SKILL_SOURCE, help="where to install from (default: codefactory-cli on PyPI)")
696
696
  if name == "sbom":
697
697
  s.add_argument("-o", "--output", help="output file (default: print it)")
698
698
  if name not in ("skill", "update", "sbom"):
codefactory/skill.py CHANGED
@@ -19,7 +19,8 @@ from pathlib import Path
19
19
 
20
20
  from . import __version__
21
21
 
22
- SOURCE = "codefactory[languages] @ git+https://github.com/dominickkubica/codefactory"
22
+ SOURCE = "codefactory-cli[languages]" # on PyPI as codefactory-cli (`codefactory` there is an unrelated project)
23
+ GIT_URL = "github.com/dominickkubica/codefactory"
23
24
  STAMP = re.compile(r"<!-- codefactory skill (\S+) -->")
24
25
  HOOK_NAME = "codefactory.sh"
25
26
  HOOK_COMMAND = f'"$CLAUDE_PROJECT_DIR"/.claude/hooks/{HOOK_NAME}'
@@ -83,23 +84,35 @@ set -u
83
84
  cd "${CLAUDE_PROJECT_DIR:-.}" || exit 0
84
85
 
85
86
  SOURCE="__SOURCE__"
87
+ STAMP="${HOME:-/tmp}/.cache/codefactory/last-update"
88
+ mkdir -p "$(dirname "$STAMP")" 2>/dev/null
89
+ stale() { [ -z "$(find "$STAMP" -mmin -1440 2>/dev/null)" ]; }
90
+ limit() { if command -v timeout >/dev/null 2>&1; then timeout 180 "$@"; else "$@"; fi; }
91
+
92
+ if [ ! -f ../codefactory/pyproject.toml ] && command -v codefactory >/dev/null 2>&1 && codefactory --version >/dev/null 2>&1; then
93
+ # already a command (pipx, uv tool, a virtualenv): upgrade it with its own Python, never touching python3 (on a Mac
94
+ # without developer tools that's a stub that opens an install dialog; Homebrew's refuses pip installs)
95
+ if stale; then limit codefactory update >/dev/null 2>&1 && touch "$STAMP"; fi
96
+ codefactory skill . >/dev/null 2>&1
97
+ echo "codefactory $(codefactory --version 2>/dev/null | cut -d' ' -f2) is installed: see .claude/skills/codefactory/SKILL.md"
98
+ exit 0
99
+ fi
100
+
86
101
  PY=""
87
102
  for c in python3 python py; do # the first that really runs (Windows has a python3 stub that doesn't)
88
103
  if command -v "$c" >/dev/null 2>&1 && "$c" -c "" >/dev/null 2>&1; then PY="$c"; break; fi
89
104
  done
90
105
  [ -n "$PY" ] || exit 0
91
- STAMP="${HOME:-/tmp}/.cache/codefactory/last-update"
92
- mkdir -p "$(dirname "$STAMP")" 2>/dev/null
93
106
 
94
107
  install() { # $1: what to install
95
- if command -v timeout >/dev/null 2>&1; then timeout 180 "$PY" -m pip install --quiet --upgrade "$1" >/dev/null 2>&1
96
- else "$PY" -m pip install --quiet --upgrade "$1" >/dev/null 2>&1; fi
108
+ limit "$PY" -m pip install --quiet --upgrade "$@" >/dev/null 2>&1
97
109
  }
98
110
 
99
111
  if [ -f ../codefactory/pyproject.toml ]; then
100
112
  # a checkout of codefactory next to this repository (a cloud session with both attached): use it as is
101
113
  "$PY" -c "import codefactory" 2>/dev/null || install -e "../codefactory[languages]"
102
- elif ! "$PY" -c "import codefactory" 2>/dev/null || [ -z "$(find "$STAMP" -mmin -1440 2>/dev/null)" ]; then
114
+ elif ! "$PY" -c "import codefactory" 2>/dev/null || stale; then
115
+ "$PY" -c "from codefactory.skill import drop_git_install as d; d()" >/dev/null 2>&1 # an older install from GitHub
103
116
  install "$SOURCE" && touch "$STAMP"
104
117
  fi
105
118
 
@@ -131,12 +144,35 @@ def install_hook(repo: Path) -> tuple[Path, Path]:
131
144
  return hook, settings_file
132
145
 
133
146
 
147
+ def git_install() -> bool:
148
+ """codefactory installed from its GitHub repository (as the `codefactory` distribution), before it was on PyPI."""
149
+ from importlib.metadata import PackageNotFoundError, distribution
150
+
151
+ try:
152
+ url = distribution("codefactory").read_text("direct_url.json") or ""
153
+ except PackageNotFoundError:
154
+ return False
155
+ return GIT_URL in url and '"vcs_info"' in url # not an editable clone (a file:// URL), not PyPI's other project
156
+
157
+
158
+ def drop_git_install() -> bool:
159
+ """Uninstalls a GitHub install, which shares every file with codefactory-cli. codefactory-cli goes too when it's
160
+ also installed: uninstalling either deletes the shared files, and pip would then see codefactory-cli as already
161
+ installed and leave it broken. The caller installs codefactory-cli afresh."""
162
+ if not git_install():
163
+ return False
164
+ return subprocess.run([sys.executable, "-m", "pip", "uninstall", "--yes", "--quiet", "codefactory", "codefactory-cli"],
165
+ capture_output=True).returncode == 0 # fmt: skip
166
+
167
+
134
168
  def update(source: str = SOURCE) -> tuple[str, str]:
135
169
  """Upgrades codefactory with this Python's pip. Returns (old version, new version)."""
136
- proc = subprocess.run(
137
- [sys.executable, "-m", "pip", "install", "--quiet", "--upgrade", source], capture_output=True, text=True
138
- )
170
+ pip = [sys.executable, "-m", "pip", "install", "--quiet", "--upgrade"]
171
+ dropped = drop_git_install()
172
+ proc = subprocess.run([*pip, source], capture_output=True, text=True)
139
173
  if proc.returncode != 0:
174
+ if dropped: # put the GitHub install back rather than leave nothing installed
175
+ subprocess.run([*pip, f"codefactory[languages] @ git+https://{GIT_URL}"], capture_output=True)
140
176
  raise RuntimeError(f"pip couldn't upgrade codefactory:\n{proc.stderr.strip()[-1500:]}")
141
177
  new = subprocess.run(
142
178
  [sys.executable, "-c", "import codefactory; print(codefactory.__version__)"], capture_output=True, text=True
@@ -7,7 +7,7 @@ description: Map this codebase's structure (layers, who calls what) and find cop
7
7
 
8
8
  `codefactory` statically analyzes this repo into a call graph and lists issues with `file:line`. The first run takes a few seconds to ~30 s; later runs reuse `.codefactory/graph.json` until a source
9
9
  file changes. Run it from the repo root. If the command isn't found, use `python -m codefactory`; if it isn't
10
- installed at all, `pip install "codefactory[languages] @ git+https://github.com/dominickkubica/codefactory"`.
10
+ installed at all, `pip install "codefactory-cli[languages]"` (on a Mac: `pipx install "codefactory-cli[languages]"`).
11
11
  It reads Python and TypeScript/JavaScript precisely; Go, Java, Kotlin, Swift, Rust, C/C++, C#, Ruby, PHP and others
12
12
  through tree-sitter, matching calls by name, so for those languages treat call, impact and unused findings as leads
13
13
  to confirm in the code. Big repositories are fine: files are parsed in parallel and cached per file. If a command below is missing or
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codefactory-cli
3
- Version: 0.20.1
3
+ Version: 0.20.2
4
4
  Summary: See a codebase as a factory floor, find what's wrong with it (copies, N+1 loops, dead code, import loops, security and reliability problems), and turn it into ranked work.
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://github.com/dominickkubica/codefactory
@@ -56,7 +56,7 @@ the number of calls it carries. Dashed orange conveyors run backwards, from a lo
56
56
  ## Quick start
57
57
 
58
58
  ```bash
59
- pip install "codefactory[languages] @ git+https://github.com/dominickkubica/codefactory"
59
+ pip install "codefactory-cli[languages]"
60
60
  cd path/to/your/repo
61
61
 
62
62
  codefactory review -o review.md # a technical review of the repository (--online: also vulnerable dependencies)
@@ -66,7 +66,11 @@ codefactory profile # what kind of project it thinks this is (findi
66
66
  codefactory hotspots # where change happens: complex code that keeps changing
67
67
  ```
68
68
 
69
+ - **The package is `codefactory-cli`** on PyPI (`codefactory` there is an unrelated project); the command is
70
+ `codefactory`. Installed from GitHub before? `codefactory update` moves you over.
69
71
  - **Python 3.11 or newer.** On Windows, run the same commands in PowerShell; use `py -m pip` if `pip` isn't found.
72
+ On a Mac, `brew install pipx` and then `pipx install "codefactory-cli[languages]"` (Homebrew's Python refuses a
73
+ plain `pip install`, and the built-in `python3` is too old).
70
74
  - **TypeScript/JavaScript projects:** run `npm install` in the project first, because codefactory uses the project's
71
75
  own TypeScript compiler (needs [Node.js](https://nodejs.org)). Without it, those files are still analyzed, less
72
76
  precisely.
@@ -178,7 +182,7 @@ jobs:
178
182
  steps:
179
183
  - uses: actions/checkout@v4
180
184
  with: { fetch-depth: 0 }
181
- - uses: dominickkubica/codefactory@v0 # follows releases; or pin v0.20.1 or a commit SHA
185
+ - uses: dominickkubica/codefactory@v0 # follows releases; or pin v0.20.2 or a commit SHA
182
186
  with: { fail-on: high }
183
187
  ```
184
188
 
@@ -1,4 +1,4 @@
1
- codefactory/__init__.py,sha256=AnLuWdZw_sywnpEWedm2OBaMVZxneCvUM0E9J05naFQ,139
1
+ codefactory/__init__.py,sha256=R_NsbpZsamxw_vMAPHTuvY2xJHG-dQFyLNgY0pWvXto,139
2
2
  codefactory/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
3
3
  codefactory/accept.py,sha256=1oaMYf6pdSy8gfdr233Lmg14p1I88EENj9HP4tBAJPU,2701
4
4
  codefactory/apple.py,sha256=khvcB9g-61b9lBz_7exp3-fpEPtB8DXq6Pc92CVdvp0,3782
@@ -7,7 +7,7 @@ codefactory/baseline.py,sha256=zPyK9ROzu_gCklpJ-jhMBu6gn9xOo6gTh5_cx0OPjqY,1947
7
7
  codefactory/brief.py,sha256=TxxWil2Hdk5ZITdUBb_fz-iJsyb7MxSBcd5Fqp3ZTro,14804
8
8
  codefactory/cache.py,sha256=Xtfj2Y2ZktUoKajuraX3yxBBcvwHjDwKp0oa9Sh7nJE,3941
9
9
  codefactory/checks.py,sha256=rPDxQ40uLnpML-Z3ABCMzSdYHKxylM0gYdq_POW9NFU,29707
10
- codefactory/cli.py,sha256=tnPG4bPnaRBbNQQSbADRydVFr3FK6MbEhamWN33-pJ4,35215
10
+ codefactory/cli.py,sha256=k47SdI0eHUsEhpOL-CAyv9TIn_5GQpgqzf3mcU9jlnw,35217
11
11
  codefactory/config.py,sha256=y6p1PS070W4C_OzDB5ZmHpI-MeA5VTw6QlZ32YIneB0,7054
12
12
  codefactory/coverage.py,sha256=3tdDymn27aIzPW_LgvLE_1f_9OVHyBrbFZDD9-vCHQg,4009
13
13
  codefactory/deps.py,sha256=yNPuP23mcHsJX8VTApSPeIuxmh5wQ8BLamelaVgSack,7644
@@ -33,7 +33,7 @@ codefactory/sarif.py,sha256=Y0MKd6wjgklehbijHTvZgfVWJCLIaHoydYlg4VIO95U,22135
33
33
  codefactory/sbom.py,sha256=nvYJppndEKJAhyAkK0DZ631uaBjE4m1TlHgLlT4mggA,3214
34
34
  codefactory/security.py,sha256=1aKs5SNKrwUw8U10XwxmK56aFLgbiuFjAlRmJ4pPG2E,29447
35
35
  codefactory/similar.py,sha256=6lcapB58MUTGIu1bHzFV8Y3Qk3NhjAILCkdTsETfS4Q,8129
36
- codefactory/skill.py,sha256=2z82H3X0wvMo0xwE9VfjFm-bWKwb_OhxmzyRQU_h608,6372
36
+ codefactory/skill.py,sha256=Kt8trXfqe1RagSzZ4k18F7I_zlJmsox-RTn73Vg--OA,8470
37
37
  codefactory/sqlgraph.py,sha256=TB1iSOupleTsZH_Wbzc8PNN7IswbosxDQW6rLxRulz0,4461
38
38
  codefactory/suppress.py,sha256=RuR30i92yHmI7Z9nEGkbO04g_MG03GHOWi7jr2TwmDQ,3637
39
39
  codefactory/taint.py,sha256=qMR0z8vTbImjqI1kmEHsG-CbfbSiR_K9hCHPSrQdHy8,22132
@@ -46,16 +46,16 @@ codefactory/analyzers/python_parse.py,sha256=RJVr4mEB-NR0q-lwRZExo4lYaJhVHZ8Vmc4
46
46
  codefactory/analyzers/treewalk.py,sha256=8vEqdlPtZBubUwf33_EZOSmypLb1VqOoiE321EPLglQ,15338
47
47
  codefactory/analyzers/ts_helper.js,sha256=PiZIjyLIRsJY3rf7SJsRsGbok3GHq0P4FHWS1mUjpMA,29216
48
48
  codefactory/analyzers/typescript.py,sha256=ZIOpBSUqwSjfYDdRFN1aga-XzoFfVSIqC4BwONg_uCA,4581
49
- codefactory/skill_template/SKILL.md,sha256=W7mXH0wVBEp8qjfu_dgFHq2Awd729BFDlkm1NPCG898,6776
49
+ codefactory/skill_template/SKILL.md,sha256=9u4SA184M_qtNAdPQQD-L1lkJ_KvhdQtGS1KLVlWLqU,6784
50
50
  codefactory/skill_template/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
51
  codefactory/viewer/__init__.py,sha256=FMCjxP02UeDUm7BEjOmM3NtU2vgR0Vv8fXljFBQqPGY,877
52
52
  codefactory/viewer/dashboard.html,sha256=y-x6kezx1gI5BA7to-sYxRcL2TkTO0evAR03lZPuQks,1856
53
53
  codefactory/viewer/factory.css,sha256=AW6wOZP1e1AUh9fsXi-yDsrBUzCEgt4YZxf6IEeIQ7M,4891
54
54
  codefactory/viewer/factory.js,sha256=awHxLwWB70iOm_W43iHnR3moiiR6WLvOdm_ys73wazg,40490
55
55
  codefactory/viewer/template.html,sha256=tOfqHMq66tfngnXLhABoZBkrlwNI1M1gy4jeDHoOkyU,1865
56
- codefactory_cli-0.20.1.dist-info/licenses/LICENSE,sha256=N-Nkwflu1UJv66kK41oCEdSsB5Ne0JycSNaI1EcV_m0,1071
57
- codefactory_cli-0.20.1.dist-info/METADATA,sha256=GQD2gFt1ytNIWWi3Lmp_ZFiRX9mrBehztBpQEVfUEUE,17033
58
- codefactory_cli-0.20.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
59
- codefactory_cli-0.20.1.dist-info/entry_points.txt,sha256=xyDemr2v6zTWLHiVpgPEIU27KfG0UQeAkEEsGSw5AcI,53
60
- codefactory_cli-0.20.1.dist-info/top_level.txt,sha256=SP10Bbz4U_cQ9B54PaGMyXWWZd8qv1MF3S7M7DeEUXk,12
61
- codefactory_cli-0.20.1.dist-info/RECORD,,
56
+ codefactory_cli-0.20.2.dist-info/licenses/LICENSE,sha256=N-Nkwflu1UJv66kK41oCEdSsB5Ne0JycSNaI1EcV_m0,1071
57
+ codefactory_cli-0.20.2.dist-info/METADATA,sha256=O8iLLHEWMxXre7-e-pjuH2kXMceCXuV9y8ZO5laYH_M,17355
58
+ codefactory_cli-0.20.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
59
+ codefactory_cli-0.20.2.dist-info/entry_points.txt,sha256=xyDemr2v6zTWLHiVpgPEIU27KfG0UQeAkEEsGSw5AcI,53
60
+ codefactory_cli-0.20.2.dist-info/top_level.txt,sha256=SP10Bbz4U_cQ9B54PaGMyXWWZd8qv1MF3S7M7DeEUXk,12
61
+ codefactory_cli-0.20.2.dist-info/RECORD,,