canibuild 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.
- canibuild/__init__.py +3 -0
- canibuild/__main__.py +5 -0
- canibuild/check.py +391 -0
- canibuild/cli.py +163 -0
- canibuild/fixes.py +163 -0
- canibuild/lockfiles.py +576 -0
- canibuild/model.py +102 -0
- canibuild/py.typed +0 -0
- canibuild/pypi.py +196 -0
- canibuild/report.py +145 -0
- canibuild/rules.py +858 -0
- canibuild/sdist.py +199 -0
- canibuild/target.py +282 -0
- canibuild-0.1.0.dist-info/METADATA +207 -0
- canibuild-0.1.0.dist-info/RECORD +18 -0
- canibuild-0.1.0.dist-info/WHEEL +4 -0
- canibuild-0.1.0.dist-info/entry_points.txt +2 -0
- canibuild-0.1.0.dist-info/licenses/LICENSE +21 -0
canibuild/fixes.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"""Concrete commands that make a finding go away, for each packaging tool."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Sequence
|
|
6
|
+
|
|
7
|
+
from packaging.requirements import InvalidRequirement, Requirement
|
|
8
|
+
|
|
9
|
+
from .model import Finding, Fix
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _split(constraint: str) -> tuple[str, str]:
|
|
13
|
+
try:
|
|
14
|
+
requirement = Requirement(constraint)
|
|
15
|
+
except InvalidRequirement:
|
|
16
|
+
return constraint, ""
|
|
17
|
+
return requirement.name, str(requirement.specifier)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _upgrade_fix(package: str, version: str, tools: Sequence[str], reason: str) -> Fix:
|
|
21
|
+
lines: list[str] = []
|
|
22
|
+
for tool in tools:
|
|
23
|
+
if tool == "uv":
|
|
24
|
+
line = f"uv lock --upgrade-package '{package}>={version}'"
|
|
25
|
+
elif tool in {"uv pip", "pip"}:
|
|
26
|
+
line = f"{package}>={version} # in requirements"
|
|
27
|
+
elif tool == "poetry":
|
|
28
|
+
line = f"poetry add '{package}>={version}'"
|
|
29
|
+
else:
|
|
30
|
+
continue
|
|
31
|
+
if line not in lines:
|
|
32
|
+
lines.append(line)
|
|
33
|
+
return Fix(
|
|
34
|
+
tool="any",
|
|
35
|
+
summary=(
|
|
36
|
+
f"Upgrade {package} to {version}, the first newer release with a wheel for this target"
|
|
37
|
+
if reason == "wheel"
|
|
38
|
+
else f"Upgrade {package} to {version}, the first newer release whose sdist "
|
|
39
|
+
"has none of these problems"
|
|
40
|
+
),
|
|
41
|
+
snippet="\n".join(lines),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _build_constraint_fixes(
|
|
46
|
+
finding: Finding, constraint: str, tools: Sequence[str], lockfile: str
|
|
47
|
+
) -> list[Fix]:
|
|
48
|
+
package = finding.package
|
|
49
|
+
name, operator = _split(constraint)
|
|
50
|
+
requested = set(tools)
|
|
51
|
+
fixes: list[Fix] = []
|
|
52
|
+
if "uv" in requested:
|
|
53
|
+
fixes.append(
|
|
54
|
+
Fix(
|
|
55
|
+
tool="uv",
|
|
56
|
+
summary=f"Constrain {name} in {package}'s build (pyproject.toml)",
|
|
57
|
+
snippet=(f'[tool.uv.extra-build-dependencies]\n{package} = ["{constraint}"]'),
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
fixes.append(
|
|
61
|
+
Fix(
|
|
62
|
+
tool="uv",
|
|
63
|
+
summary="Or constrain it for every build (pyproject.toml)",
|
|
64
|
+
snippet=(f'[tool.uv]\nbuild-constraint-dependencies = ["{constraint}"]'),
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
if "uv pip" in requested:
|
|
68
|
+
fixes.append(
|
|
69
|
+
Fix(
|
|
70
|
+
tool="uv pip",
|
|
71
|
+
summary="Pass a build constraints file",
|
|
72
|
+
snippet=(
|
|
73
|
+
f"echo '{constraint}' > build-constraints.txt\n"
|
|
74
|
+
f"uv pip install -b build-constraints.txt -r {lockfile}"
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
if "pip" in requested:
|
|
79
|
+
fixes.append(
|
|
80
|
+
Fix(
|
|
81
|
+
tool="pip",
|
|
82
|
+
summary="Pass a build constraints file (pip 25.3+)",
|
|
83
|
+
snippet=(
|
|
84
|
+
f"echo '{constraint}' > build-constraints.txt\n"
|
|
85
|
+
"pip install --build-constraint build-constraints.txt "
|
|
86
|
+
f"-r {lockfile}"
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
fixes.append(
|
|
91
|
+
Fix(
|
|
92
|
+
tool="pip",
|
|
93
|
+
summary=(
|
|
94
|
+
"pip older than 25.3: use PIP_CONSTRAINT (ignored for builds since pip 26.2)"
|
|
95
|
+
),
|
|
96
|
+
snippet=(
|
|
97
|
+
f"echo '{constraint}' > build-constraints.txt\n"
|
|
98
|
+
f"PIP_CONSTRAINT=build-constraints.txt pip install -r {lockfile}"
|
|
99
|
+
),
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
if "poetry" in requested:
|
|
103
|
+
fixes.append(
|
|
104
|
+
Fix(
|
|
105
|
+
tool="poetry",
|
|
106
|
+
summary=(
|
|
107
|
+
f"Constrain {name} in {package}'s build "
|
|
108
|
+
"(Poetry 2.3+, pyproject.toml), then poetry lock"
|
|
109
|
+
),
|
|
110
|
+
snippet=(
|
|
111
|
+
f'[tool.poetry.build-constraints]\n{package} = {{ {name} = "{operator}" }}'
|
|
112
|
+
),
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
return fixes
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _missing_requirement_fixes(finding: Finding, missing: str, tools: Sequence[str]) -> list[Fix]:
|
|
119
|
+
package = finding.package
|
|
120
|
+
version = finding.version or ""
|
|
121
|
+
requested = set(tools)
|
|
122
|
+
fixes: list[Fix] = []
|
|
123
|
+
if "uv" in requested:
|
|
124
|
+
fixes.append(
|
|
125
|
+
Fix(
|
|
126
|
+
tool="uv",
|
|
127
|
+
summary=f"Add {missing} to {package}'s build (pyproject.toml)",
|
|
128
|
+
snippet=(f'[tool.uv.extra-build-dependencies]\n{package} = ["{missing}"]'),
|
|
129
|
+
)
|
|
130
|
+
)
|
|
131
|
+
for tool, command in (("pip", "pip install"), ("uv pip", "uv pip install")):
|
|
132
|
+
if tool in requested:
|
|
133
|
+
fixes.append(
|
|
134
|
+
Fix(
|
|
135
|
+
tool=tool,
|
|
136
|
+
summary=f"Install {missing} first and build without isolation",
|
|
137
|
+
snippet=(
|
|
138
|
+
f"{command} {missing} && "
|
|
139
|
+
f"{command} --no-build-isolation {package}=={version}"
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
return fixes
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def fixes_for(
|
|
147
|
+
finding: Finding,
|
|
148
|
+
*,
|
|
149
|
+
upgrade_to: str | None,
|
|
150
|
+
tools: Sequence[str],
|
|
151
|
+
lockfile: str = "requirements.txt",
|
|
152
|
+
upgrade_reason: str = "wheel",
|
|
153
|
+
) -> tuple[Fix, ...]:
|
|
154
|
+
"""Return the fixes to show for one finding, upgrade first when relevant."""
|
|
155
|
+
|
|
156
|
+
fixes: list[Fix] = []
|
|
157
|
+
if upgrade_to is not None:
|
|
158
|
+
fixes.append(_upgrade_fix(finding.package, upgrade_to, tools, upgrade_reason))
|
|
159
|
+
if finding.build_constraint is not None:
|
|
160
|
+
fixes.extend(_build_constraint_fixes(finding, finding.build_constraint, tools, lockfile))
|
|
161
|
+
if finding.missing_requirement is not None:
|
|
162
|
+
fixes.extend(_missing_requirement_fixes(finding, finding.missing_requirement, tools))
|
|
163
|
+
return tuple(fixes)
|