pymolt 0.1.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.
- pymolt/__init__.py +1 -0
- pymolt/adapters/__init__.py +1 -0
- pymolt/adapters/github_forks.py +235 -0
- pymolt/adapters/pypi_metadata.py +38 -0
- pymolt/adapters/subprocess_runner.py +25 -0
- pymolt/assess/__init__.py +29 -0
- pymolt/assess/service.py +614 -0
- pymolt/codemods/__init__.py +15 -0
- pymolt/codemods/apply.py +1014 -0
- pymolt/codemods/client.py +258 -0
- pymolt/codemods/models.py +164 -0
- pymolt/codemods/rules.py +745 -0
- pymolt/codemods/service.py +453 -0
- pymolt/config.py +221 -0
- pymolt/core/__init__.py +19 -0
- pymolt/core/enums.py +78 -0
- pymolt/core/generated.py +27 -0
- pymolt/core/graph.py +38 -0
- pymolt/core/layers.py +15 -0
- pymolt/core/legacy_stdlib.py +81 -0
- pymolt/core/serialize.py +26 -0
- pymolt/discovery/__init__.py +8 -0
- pymolt/discovery/discover.py +255 -0
- pymolt/discovery/dockerfile.py +244 -0
- pymolt/discovery/models.py +138 -0
- pymolt/discovery/tox_nox.py +142 -0
- pymolt/doctor.py +193 -0
- pymolt/ingestion/__init__.py +1 -0
- pymolt/ingestion/conda_ingest.py +466 -0
- pymolt/ingestion/config.py +107 -0
- pymolt/ingestion/data/conda_pypi_map.json +29 -0
- pymolt/ingestion/detect.py +630 -0
- pymolt/ingestion/fallback_compiler.py +454 -0
- pymolt/ingestion/lock_parsers.py +262 -0
- pymolt/ingestion/name_mapping.py +172 -0
- pymolt/ingestion/orchestrator.py +154 -0
- pymolt/ingestion/resolve_cache.py +84 -0
- pymolt/ingestion/uv_runner.py +282 -0
- pymolt/interfaces/__init__.py +1 -0
- pymolt/interfaces/cli/__init__.py +1 -0
- pymolt/interfaces/cli/__main__.py +9 -0
- pymolt/interfaces/cli/commands.py +2867 -0
- pymolt/interfaces/cli/output.py +135 -0
- pymolt/interfaces/cli/verify_cmd.py +657 -0
- pymolt/interfaces/mcp_server.py +1263 -0
- pymolt/inventory/__init__.py +1 -0
- pymolt/inventory/code_scan.py +10 -0
- pymolt/inventory/edges.py +319 -0
- pymolt/inventory/intersect.py +10 -0
- pymolt/migration_plan.py +733 -0
- pymolt/migration_state.py +83 -0
- pymolt/py.typed +0 -0
- pymolt/risk/__init__.py +6 -0
- pymolt/risk/assess.py +214 -0
- pymolt/risk/cache.py +44 -0
- pymolt/risk/models.py +39 -0
- pymolt/risk/osv.py +59 -0
- pymolt/scan/__init__.py +11 -0
- pymolt/scan/report.py +33 -0
- pymolt/setup/__init__.py +31 -0
- pymolt/setup/baseline_hint.py +83 -0
- pymolt/setup/pythons.py +118 -0
- pymolt/setup/service.py +380 -0
- pymolt/setup/target_hint.py +196 -0
- pymolt/status.py +426 -0
- pymolt/strategic/__init__.py +5 -0
- pymolt/strategic/forknet/__init__.py +1 -0
- pymolt/strategic/forknet/cache.py +45 -0
- pymolt/strategic/forknet/models.py +111 -0
- pymolt/strategic/forknet/service.py +143 -0
- pymolt/strategic/succession/__init__.py +3 -0
- pymolt/strategic/succession/client.py +72 -0
- pymolt/strategic/succession/detect.py +23 -0
- pymolt/strategic/succession/models.py +61 -0
- pymolt/strategic/succession/service.py +59 -0
- pymolt/strategic/succession/transplant.py +91 -0
- pymolt/verify/__init__.py +63 -0
- pymolt/verify/_backend.py +408 -0
- pymolt/verify/_install_hook.py +68 -0
- pymolt/verify/_normalize.py +106 -0
- pymolt/verify/_sinks.py +273 -0
- pymolt/verify/_wrap.py +417 -0
- pymolt/verify/boundary_tracer.py +219 -0
- pymolt/verify/cascade.py +173 -0
- pymolt/verify/comparators.py +88 -0
- pymolt/verify/contact_map.py +421 -0
- pymolt/verify/contract.py +150 -0
- pymolt/verify/coverage.py +119 -0
- pymolt/verify/diff.py +102 -0
- pymolt/verify/export_watcher.py +73 -0
- pymolt/verify/gaps.py +232 -0
- pymolt/verify/golden_master.py +57 -0
- pymolt/verify/models.py +285 -0
- pymolt/verify/policy.py +328 -0
- pymolt/verify/probe.py +156 -0
- pymolt/verify/reinvoke.py +133 -0
- pymolt/verify/report.py +417 -0
- pymolt/verify/sandbox.py +142 -0
- pymolt/verify/service.py +1516 -0
- pymolt/verify/shadow.py +259 -0
- pymolt/verify/sitecustomize.py +27 -0
- pymolt/verify/unified.py +180 -0
- pymolt-0.1.0.dist-info/METADATA +273 -0
- pymolt-0.1.0.dist-info/RECORD +107 -0
- pymolt-0.1.0.dist-info/WHEEL +4 -0
- pymolt-0.1.0.dist-info/entry_points.txt +2 -0
- pymolt-0.1.0.dist-info/licenses/LICENSE +176 -0
pymolt/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Adapters module stubs
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"""GitHub fork-network adapter — thin, network-only.
|
|
2
|
+
|
|
3
|
+
Feeds pymolt's strategic fork triage (:mod:`pymolt.strategic.forknet`). These are
|
|
4
|
+
pure fetchers over the GitHub API: no domain models, no scoring, no caching (the
|
|
5
|
+
forknet service wraps them with an on-disk cache, mirroring the risk layer). Every
|
|
6
|
+
function degrades to ``None`` / an empty list on any failure and never raises for a
|
|
7
|
+
network/HTTP problem — offline-first posture. Uses ``httpx`` like the PyPI adapter.
|
|
8
|
+
|
|
9
|
+
Auth: a token from ``GITHUB_TOKEN`` / ``GH_TOKEN`` raises the rate limit to 5000/hr;
|
|
10
|
+
anonymous is 60/hr. Degrade (fewer forks compared), don't fail, when anonymous.
|
|
11
|
+
|
|
12
|
+
Endpoints this adapter speaks:
|
|
13
|
+
- GraphQL POST https://api.github.com/graphql
|
|
14
|
+
query Repository.forks(first: 100, after: $cursor,
|
|
15
|
+
orderBy: {field: PUSHED_AT, direction: DESC})
|
|
16
|
+
per node: nameWithOwner, url, pushedAt, stargazerCount, defaultBranchRef.name
|
|
17
|
+
Because forks come back newest-push-first, the caller stops paging as soon as
|
|
18
|
+
a page's oldest pushedAt is below the recency cutoff (cheap: a few requests
|
|
19
|
+
even for a 15k-fork repo).
|
|
20
|
+
- REST GET /repos/{base}/compare/{base_branch}...{owner}:{fork_branch}
|
|
21
|
+
-> {"ahead_by": int, "behind_by": int, ...} (the only way to get divergence;
|
|
22
|
+
one call PER fork, so the service runs it on the top-N survivors only)
|
|
23
|
+
- Raw GET https://raw.githubusercontent.com/{owner}/{name}/{branch}/{path}
|
|
24
|
+
for requirements.txt / setup.py / pyproject.toml -> declared-dependency lines
|
|
25
|
+
(the "already ported?" enrichment signal)
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
import logging
|
|
31
|
+
import os
|
|
32
|
+
from dataclasses import dataclass
|
|
33
|
+
|
|
34
|
+
import httpx
|
|
35
|
+
|
|
36
|
+
logger = logging.getLogger(__name__)
|
|
37
|
+
|
|
38
|
+
GITHUB_GRAPHQL_URL = "https://api.github.com/graphql"
|
|
39
|
+
GITHUB_API_URL = "https://api.github.com"
|
|
40
|
+
GITHUB_RAW_URL = "https://raw.githubusercontent.com"
|
|
41
|
+
# Manifests we probe (first hit wins) for the ported-signal enrichment.
|
|
42
|
+
MANIFEST_PATHS = ("requirements.txt", "setup.py", "pyproject.toml")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class RawFork:
|
|
47
|
+
"""A fork as the GraphQL API returns it (pre-domain, ISO strings preserved)."""
|
|
48
|
+
|
|
49
|
+
name_with_owner: str # "owner/name"
|
|
50
|
+
url: str
|
|
51
|
+
pushed_at: str # ISO8601, e.g. "2025-04-01T12:00:00Z"
|
|
52
|
+
stars: int
|
|
53
|
+
default_branch: str
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def resolve_token() -> str | None:
|
|
57
|
+
"""Return a GitHub token from GITHUB_TOKEN / GH_TOKEN, or None (anonymous)."""
|
|
58
|
+
return os.environ.get("GITHUB_TOKEN") or os.environ.get("GH_TOKEN") or None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def auth_mode(token: str | None) -> str:
|
|
62
|
+
"""'token' when authenticated, else 'anonymous' (for the report honesty marker)."""
|
|
63
|
+
return "token" if token else "anonymous"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _auth_headers(token: str | None) -> dict[str, str]:
|
|
67
|
+
"""Common headers for GitHub API/raw requests; Bearer auth when a token exists."""
|
|
68
|
+
headers = {"Accept": "application/vnd.github+json"}
|
|
69
|
+
if token:
|
|
70
|
+
headers["Authorization"] = f"Bearer {token}"
|
|
71
|
+
return headers
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
_FORKS_QUERY = """
|
|
75
|
+
query($owner: String!, $name: String!, $cursor: String) {
|
|
76
|
+
repository(owner: $owner, name: $name) {
|
|
77
|
+
forks(first: 100, after: $cursor, orderBy: {field: PUSHED_AT, direction: DESC}) {
|
|
78
|
+
pageInfo { hasNextPage endCursor }
|
|
79
|
+
nodes {
|
|
80
|
+
nameWithOwner
|
|
81
|
+
url
|
|
82
|
+
pushedAt
|
|
83
|
+
stargazerCount
|
|
84
|
+
defaultBranchRef { name }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def fetch_recent_forks(
|
|
93
|
+
base_repo: str,
|
|
94
|
+
*,
|
|
95
|
+
cutoff_iso: str,
|
|
96
|
+
token: str | None,
|
|
97
|
+
max_pages: int = 50,
|
|
98
|
+
) -> list[RawFork]:
|
|
99
|
+
"""All forks of ``base_repo`` ("owner/name") pushed at/after ``cutoff_iso``.
|
|
100
|
+
|
|
101
|
+
Pages the GraphQL forks connection newest-push-first, stopping once a page's
|
|
102
|
+
entries fall below ``cutoff_iso`` (or ``max_pages`` is hit — surfaced by the
|
|
103
|
+
caller as a truncation caveat). Returns [] on failure.
|
|
104
|
+
"""
|
|
105
|
+
owner, _, name = base_repo.partition("/")
|
|
106
|
+
headers = _auth_headers(token)
|
|
107
|
+
forks: list[RawFork] = []
|
|
108
|
+
cursor: str | None = None
|
|
109
|
+
|
|
110
|
+
for _page in range(max_pages):
|
|
111
|
+
variables = {"owner": owner, "name": name, "cursor": cursor}
|
|
112
|
+
try:
|
|
113
|
+
resp = httpx.post(
|
|
114
|
+
GITHUB_GRAPHQL_URL,
|
|
115
|
+
json={"query": _FORKS_QUERY, "variables": variables},
|
|
116
|
+
headers=headers,
|
|
117
|
+
timeout=30.0,
|
|
118
|
+
)
|
|
119
|
+
except httpx.HTTPError as e:
|
|
120
|
+
logger.info("GitHub GraphQL request failed (%s): %s", base_repo, e)
|
|
121
|
+
break
|
|
122
|
+
if resp.status_code != 200:
|
|
123
|
+
break
|
|
124
|
+
try:
|
|
125
|
+
data = resp.json()
|
|
126
|
+
except ValueError:
|
|
127
|
+
break
|
|
128
|
+
if data.get("errors"):
|
|
129
|
+
logger.info("GitHub GraphQL errors for %s: %s", base_repo, data["errors"])
|
|
130
|
+
break
|
|
131
|
+
|
|
132
|
+
repository = data.get("data", {}).get("repository")
|
|
133
|
+
if not repository:
|
|
134
|
+
break
|
|
135
|
+
forks_conn = repository.get("forks", {})
|
|
136
|
+
nodes = forks_conn.get("nodes") or []
|
|
137
|
+
|
|
138
|
+
hit_cutoff = False
|
|
139
|
+
for node in nodes:
|
|
140
|
+
pushed_at = node.get("pushedAt", "")
|
|
141
|
+
if pushed_at < cutoff_iso:
|
|
142
|
+
hit_cutoff = True
|
|
143
|
+
break
|
|
144
|
+
default_branch_ref = node.get("defaultBranchRef") or {}
|
|
145
|
+
forks.append(
|
|
146
|
+
RawFork(
|
|
147
|
+
name_with_owner=node.get("nameWithOwner", ""),
|
|
148
|
+
url=node.get("url", ""),
|
|
149
|
+
pushed_at=pushed_at,
|
|
150
|
+
stars=node.get("stargazerCount", 0),
|
|
151
|
+
default_branch=default_branch_ref.get("name") or "master",
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
if hit_cutoff:
|
|
155
|
+
break
|
|
156
|
+
|
|
157
|
+
page_info = forks_conn.get("pageInfo", {})
|
|
158
|
+
if not page_info.get("hasNextPage"):
|
|
159
|
+
break
|
|
160
|
+
cursor = page_info.get("endCursor")
|
|
161
|
+
|
|
162
|
+
return forks
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def fetch_default_branch(base_repo: str, *, token: str | None) -> str | None:
|
|
166
|
+
"""The base repo's default branch (the correct left side of a fork compare), or None.
|
|
167
|
+
|
|
168
|
+
A fork may have renamed its default branch (``master`` -> ``main``); comparing
|
|
169
|
+
against the fork's own branch name would 404 and silently lose the divergence
|
|
170
|
+
signal, so the service resolves the base branch here once.
|
|
171
|
+
"""
|
|
172
|
+
url = f"{GITHUB_API_URL}/repos/{base_repo}"
|
|
173
|
+
try:
|
|
174
|
+
resp = httpx.get(url, headers=_auth_headers(token), timeout=30.0)
|
|
175
|
+
except httpx.HTTPError as e:
|
|
176
|
+
logger.info("GitHub repo request failed (%s): %s", url, e)
|
|
177
|
+
return None
|
|
178
|
+
if resp.status_code != 200:
|
|
179
|
+
return None
|
|
180
|
+
try:
|
|
181
|
+
return resp.json().get("default_branch")
|
|
182
|
+
except ValueError:
|
|
183
|
+
return None
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def compare_fork(
|
|
187
|
+
base_repo: str,
|
|
188
|
+
base_branch: str,
|
|
189
|
+
fork_name_with_owner: str,
|
|
190
|
+
fork_branch: str,
|
|
191
|
+
*,
|
|
192
|
+
token: str | None,
|
|
193
|
+
) -> dict | None:
|
|
194
|
+
"""{'ahead_by': int, 'behind_by': int} for a fork vs base, or None on failure."""
|
|
195
|
+
fork_owner, _, _fork_name = fork_name_with_owner.partition("/")
|
|
196
|
+
url = f"{GITHUB_API_URL}/repos/{base_repo}/compare/{base_branch}...{fork_owner}:{fork_branch}"
|
|
197
|
+
try:
|
|
198
|
+
resp = httpx.get(url, headers=_auth_headers(token), timeout=30.0)
|
|
199
|
+
except httpx.HTTPError as e:
|
|
200
|
+
logger.info("GitHub compare request failed (%s): %s", url, e)
|
|
201
|
+
return None
|
|
202
|
+
if resp.status_code != 200:
|
|
203
|
+
return None
|
|
204
|
+
try:
|
|
205
|
+
data = resp.json()
|
|
206
|
+
except ValueError:
|
|
207
|
+
return None
|
|
208
|
+
return {"ahead_by": data.get("ahead_by"), "behind_by": data.get("behind_by")}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def fetch_manifest_deps(
|
|
212
|
+
fork_name_with_owner: str,
|
|
213
|
+
branch: str,
|
|
214
|
+
*,
|
|
215
|
+
token: str | None,
|
|
216
|
+
) -> list[str] | None:
|
|
217
|
+
"""Declared-dependency lines from the fork's first present manifest, or None.
|
|
218
|
+
|
|
219
|
+
Tries :data:`MANIFEST_PATHS` in order via the raw endpoint; returns the file's
|
|
220
|
+
non-empty lines (the forknet models classify the ported-signal from them). None
|
|
221
|
+
means no manifest was reachable (→ UNKNOWN signal, not a failure).
|
|
222
|
+
"""
|
|
223
|
+
owner, _, name = fork_name_with_owner.partition("/")
|
|
224
|
+
headers = _auth_headers(token)
|
|
225
|
+
for path in MANIFEST_PATHS:
|
|
226
|
+
url = f"{GITHUB_RAW_URL}/{owner}/{name}/{branch}/{path}"
|
|
227
|
+
try:
|
|
228
|
+
resp = httpx.get(url, headers=headers, timeout=30.0)
|
|
229
|
+
except httpx.HTTPError as e:
|
|
230
|
+
logger.info("GitHub raw request failed (%s): %s", url, e)
|
|
231
|
+
continue
|
|
232
|
+
if resp.status_code != 200:
|
|
233
|
+
continue
|
|
234
|
+
return [line.strip() for line in resp.text.splitlines() if line.strip()]
|
|
235
|
+
return None
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""PyPI JSON API adapter — wheel/compilation and release-recency signals.
|
|
2
|
+
|
|
3
|
+
Pure HTTP fetchers (no caching here; the risk layer wraps these with its
|
|
4
|
+
on-disk cache). Each returns the parsed JSON dict or ``None`` on any failure.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
PYPI_PACKAGE_URL = "https://pypi.org/pypi/{name}/json"
|
|
14
|
+
PYPI_RELEASE_URL = "https://pypi.org/pypi/{name}/{version}/json"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _get_json(url: str, client: httpx.Client) -> dict | None:
|
|
18
|
+
try:
|
|
19
|
+
resp = client.get(url)
|
|
20
|
+
except httpx.HTTPError as e:
|
|
21
|
+
logger.info("PyPI request failed (%s): %s", url, e)
|
|
22
|
+
return None
|
|
23
|
+
if resp.status_code != 200:
|
|
24
|
+
return None
|
|
25
|
+
try:
|
|
26
|
+
return resp.json()
|
|
27
|
+
except ValueError:
|
|
28
|
+
return None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def fetch_release_json(name: str, version: str, client: httpx.Client) -> dict | None:
|
|
32
|
+
"""Return the PyPI JSON for a specific release (has the per-file ``urls``)."""
|
|
33
|
+
return _get_json(PYPI_RELEASE_URL.format(name=name, version=version), client)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def fetch_package_json(name: str, client: httpx.Client) -> dict | None:
|
|
37
|
+
"""Return the package-level PyPI JSON (all releases + upload times)."""
|
|
38
|
+
return _get_json(PYPI_PACKAGE_URL.format(name=name), client)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def run_command(
|
|
5
|
+
args: list[str],
|
|
6
|
+
check: bool = True,
|
|
7
|
+
cwd: str | None = None,
|
|
8
|
+
env: dict[str, str] | None = None,
|
|
9
|
+
timeout: int | None = None,
|
|
10
|
+
) -> subprocess.CompletedProcess:
|
|
11
|
+
"""Run a subprocess command in one isolated system-touching location.
|
|
12
|
+
|
|
13
|
+
``env`` and ``timeout`` are additive (existing callers are unaffected). ``env`` lets
|
|
14
|
+
verify/ inject ``PYMOLT_TRACE_*`` when launching a suite or test client under the
|
|
15
|
+
Mode-B watcher; ``timeout`` guards a hung traced run.
|
|
16
|
+
"""
|
|
17
|
+
return subprocess.run(
|
|
18
|
+
args,
|
|
19
|
+
capture_output=True,
|
|
20
|
+
text=True,
|
|
21
|
+
check=check,
|
|
22
|
+
cwd=cwd,
|
|
23
|
+
env=env,
|
|
24
|
+
timeout=timeout,
|
|
25
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Phase 3 — assess: resolve lock-first, compare baseline vs target, rank risk.
|
|
2
|
+
|
|
3
|
+
The compute core is UI-agnostic: :func:`run_assess` resolves both graphs, builds
|
|
4
|
+
the comparison rows and (optionally) the risk report, returning an
|
|
5
|
+
:class:`AssessResult`. No prompts, no printing — callers drive
|
|
6
|
+
this same core and own their own I/O. The CLI additionally reuses the pure
|
|
7
|
+
helpers (``resolve_target_graph``/``build_comparison_rows``) for its interactive
|
|
8
|
+
override loop.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from pymolt.assess.service import (
|
|
12
|
+
AssessResult,
|
|
13
|
+
build_comparison_rows,
|
|
14
|
+
extract_constraint,
|
|
15
|
+
resolve_chosen_source,
|
|
16
|
+
resolve_target_graph,
|
|
17
|
+
run_assess,
|
|
18
|
+
write_constraints_file,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"AssessResult",
|
|
23
|
+
"build_comparison_rows",
|
|
24
|
+
"extract_constraint",
|
|
25
|
+
"resolve_chosen_source",
|
|
26
|
+
"resolve_target_graph",
|
|
27
|
+
"run_assess",
|
|
28
|
+
"write_constraints_file",
|
|
29
|
+
]
|