API reference¶
Auto-generated from docstrings -- full signatures, parameter types, and defaults for the same Python API surface that page introduces narratively. Start there for how to use it; come here for the exact call signature.
Generator functions¶
pitloom.assemble.generate ¶
generate(
target: Path | str = ".",
*,
offline: bool | None = None,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
id_registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
enrich: bool | None = None,
extract_file_header: bool | None = None,
scan_model_usage: bool | None = None,
trust_model_files: bool | None = None,
content_type: bool | None = None,
content_type_method: str | None = None,
update_id_registry: bool | None = None,
use_lockfile: bool | None = None,
build_options: BuildOptions = BuildOptions(),
max_source_metadata_bytes: int | None = None,
max_model_extract_bytes: int | None = None,
pitloom_config: PitloomConfig | None = None,
project_dir: Path | str | None = None,
check_url: Callable[[str], None] | None = None,
max_download_bytes: int | None = None,
credentials: CredentialPolicy | None = None,
) -> str
Smart unified entrypoint for generating SPDX 3 SBOMs across all target types.
build_options (see :class:~pitloom.core.build_options.BuildOptions)
takes effect for a project directory target only. Env, wheel, model and
Hugging Face targets log one WARNING: per given build flag here,
before dispatching; a Git URL, a PyPI URL and an sdist archive are
settled by :func:generate_git_project_sbom, :func:generate_pypi_sbom
and :func:generate_project_sbom.
project_dir (the project directory an sdist or a wheel was built
from, for its registry keys) reaches the sdist and wheel delegates; any
other target warns that it has no effect. So does
max_model_extract_bytes on any target but a wheel, and
max_download_bytes on any target but a PyPI URL, a Git URL or a
Hugging Face model; an invalid value of either raises ValueError
whatever the target. offline, max_download_bytes and check_url
resolve for every remote target as
:func:~pitloom.core.config_cascade.resolve_fetch_policy resolves
them.
A PyPI project or release URL is read as loom wheel reads it: the
release's wheel that best matches the running environment is
downloaded, verified and read (:func:generate_pypi_sbom), then one
INFO: names :func:generate_pypi_sbom with kind="sdist" for
the sdist.
check_url is called with every URL of the release lookup and the
download before it is requested (the PyPI lookup of a dependency's
licence and originator, made unless offline is true, does not pass
through it); max_download_bytes caps the file.
A target that is the http or https URL of a Git repository (or of
one of its web pages) is fetched and read as a project, or as the model
file it names or its folder's one model file
(:func:generate_git_sbom); check_url is its address policy,
called with every redirect target before it is requested. A local
target does not use it. max_download_bytes caps the disk the checkout
takes, as it caps a PyPI download.
A Hugging Face model URL or id is read by :func:generate_model_sbom:
check_url is called with the URL of each metadata file it downloads
and each redirect target, and max_download_bytes caps each file.
A local directory with no project config is read for its one model
file; one with no model file either is refused
(project-or-model-not-found).
credentials (:class:~pitloom.core.credential_policy.CredentialPolicy)
adds to the URL credentials pitloom_config accepts, for every target.
Source code in pitloom/assemble/__init__.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
pitloom.assemble.generate_project_sbom ¶
generate_project_sbom(
project_target: Path | str,
*,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
project_metadata: ProjectMetadata | None = None,
pitloom_config: PitloomConfig | None = None,
id_registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
enrich: bool | None = None,
extract_file_header: bool | None = None,
scan_model_usage: bool | None = None,
trust_model_files: bool | None = None,
content_type: bool | None = None,
content_type_method: str | None = None,
offline: bool | None = None,
update_id_registry: bool | None = None,
use_lockfile: bool | None = None,
build_options: BuildOptions = BuildOptions(),
max_source_metadata_bytes: int | None = None,
project_dir: Path | str | None = None,
check_url: Callable[[str], None] | None = None,
max_download_bytes: int | None = None,
acquisition: Acquisition | None = None,
credentials: CredentialPolicy | None = None,
) -> str
Generate a Source SPDX 3 SBOM for a Python project or sdist archive.
project_target may be a PyPI project or release URL (a str; a
:class:~pathlib.Path is always local): the release's sdist is
downloaded and read (:func:~pitloom.assemble.generate_pypi_sbom, which
never reads the sdist's own [tool.pitloom]): check_url is called
with every URL of the release lookup and the download before it is
requested (a dependency's licence lookup does not pass through it), and
max_download_bytes caps the file; project_metadata then has no effect,
with one WARNING:. For a local target check_url is not used and
max_download_bytes has no effect (one WARNING:; an invalid value
raises all the same). acquisition records how an sdist was downloaded
(set by :func:~pitloom.assemble.generate_pypi_sbom): one provenance
record on the main package, nothing else.
build_options (see :class:~pitloom.core.build_options.BuildOptions),
unlike every other flag-shaped parameter here, deliberately has no
pitloom_config.* fallback to defer to when unset. A caller must
pass BuildOptions(allow=True) explicitly every time it wants
Pitloom to execute the target project's own PEP 517 build backend;
there is no config-cascade layer for it, since the config file lives
in the (untrusted) project being scanned and must never be able to
silently opt itself into code execution. For an sdist archive target
every given build flag is ignored with one WARNING: each.
Settings come from the arguments, then pitloom_config, then the
target's own [tool.pitloom], then the built-in defaults.
pitloom_config alone replaces the target's config (--config); the
project metadata is still read from project_target, and its lock-file
cascade follows use_lockfile, else pitloom_config's
use-lockfile.
use_lockfile only affects metadata resolved by this call: if the
caller pre-supplies BOTH project_metadata and pitloom_config
together, this parameter has no effect -- the lock-file cascade
decision was already made when that metadata was produced.
project_metadata alone is not supported: it is re-read from
project_target, with a WARNING: explaining why (see "no silent
deviations" in AGENTS.md).
For an sdist archive, extract_file_header, content_type,
enrich, scan_model_usage, use_lockfile and
trust_model_files have no effect, and for a directory
trust_model_files has none; each warns when given (see
:data:pitloom.core.inert_options.INERT). max_model_extract_bytes
is no parameter here: a caller forwarding it settles it with
:func:~pitloom.core.inert_options.forward_options and
:func:~pitloom.core.inert_options.project_target_kind.
project_dir names the project directory an sdist archive was built
from: its members are then keyed below that directory's path from the
registry's root (a registry above the project, a monorepo), as
embed-wheel --project-dir keys a wheel's. Nothing is read from it;
without a registry it has no effect, with one WARNING:, and for a
directory target it has none (that directory is the project).
credentials (:class:~pitloom.core.credential_policy.CredentialPolicy)
adds to the credentials pitloom_config accepts; it never replaces them.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
project_dir is given for an sdist and is not a directory. |
ValueError
|
project_target is a Hugging Face model URL
( |
RemoteSourceError
|
a PyPI URL's sdist
could not be fetched or verified ( |
Source code in pitloom/assemble/_generators.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
pitloom.assemble.generate_git_sbom ¶
generate_git_sbom(
url: str,
*,
sbom_kind: str = AUTO,
check_url: Callable[[str], None] | None = None,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
pitloom_config: PitloomConfig | None = None,
id_registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
enrich: bool | None = None,
extract_file_header: bool | None = None,
scan_model_usage: bool | None = None,
content_type: bool | None = None,
content_type_method: str | None = None,
offline: bool | None = None,
max_download_bytes: int | None = None,
trust_model_files: bool | None = None,
update_id_registry: bool | None = None,
use_lockfile: bool | None = None,
build_options: BuildOptions = BuildOptions(),
max_source_metadata_bytes: int | None = None,
project_metadata: ProjectMetadata | None = None,
credentials: CredentialPolicy | None = None,
) -> str
Generate an SPDX 3 SBOM for the project or the AI model file at a Git URL.
url is fetched as :func:generate_git_project_sbom describes, every
option meaning what it means there. sbom_kind says what the SBOM
describes (:func:~pitloom.extract.remote.git_target.resolve_git_target):
"auto": a model file the URL names (whatever the folder holds), else the folder's Python project, else the folder's one AI model file;"project": the folder's project only;"model": the named model file, else the folder's one model file.
A model file of a clone, and each model file in its project's build
file list, is read as a local one, except that a format whose reader a
hostile file could crash or hang (fastText, GGUF, HDF5, ONNX, PyTorch)
is listed without metadata, said in one INFO: per SBOM, unless
trust_model_files (see :func:generate_git_project_sbom). A model
file's messages name it by its path in the repository; an option a
model SBOM cannot use warns once. credentials
(:class:~pitloom.core.credential_policy.CredentialPolicy) adds to the
credentials pitloom_config accepts.
Raises:
| Type | Description |
|---|---|
InternalError
|
sbom_kind is none of
the three (a :class: |
ValueError
|
max_download_bytes (or the config's) is not an integer of at least 1. |
RemoteSourceError
|
the repository could
not be fetched, the named file is not in it
( |
CodedValueError
|
no model file to read
( |
Source code in pitloom/assemble/_generators_git.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
pitloom.assemble.generate_git_project_sbom ¶
generate_git_project_sbom(
url: str,
*,
check_url: Callable[[str], None] | None = None,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
pitloom_config: PitloomConfig | None = None,
id_registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
enrich: bool | None = None,
extract_file_header: bool | None = None,
scan_model_usage: bool | None = None,
content_type: bool | None = None,
content_type_method: str | None = None,
offline: bool | None = None,
max_download_bytes: int | None = None,
trust_model_files: bool | None = None,
update_id_registry: bool | None = None,
use_lockfile: bool | None = None,
build_options: BuildOptions = BuildOptions(),
max_source_metadata_bytes: int | None = None,
project_metadata: ProjectMetadata | None = None,
credentials: CredentialPolicy | None = None,
) -> str
Generate a Source SPDX 3 SBOM for the project at a Git URL.
url is a clone URL or the address of a repository web page, naming a
branch, tag or commit and a folder (see
:func:~pitloom.extract.remote.git.fetch_git_project, which fetches it).
The repository is shallow-cloned into a temporary directory that is
removed on return.
check_url is called with every redirect target before it is requested (the caller's address policy; Pitloom does not check the URL itself).
The repository is untrusted: its own [tool.pitloom] is ignored (a
repository must not name host paths such as fragments or an ID registry)
unless the caller passes pitloom_config, and its build backend is never
run (a build flag in build_options warns once and has no effect). With
offline (else pitloom_config's offline) true nothing is fetched
(git.offline, offline-unusable). The fetch is stopped once the
checkout takes more disk than max_download_bytes (else
pitloom_config's max-download-bytes, else 512 MiB;
git.too-large, over-cap). The three resolve as every remote
route resolves them
(:func:~pitloom.core.config_cascade.resolve_fetch_policy).
A model file of the repository in a format whose reader a hostile file
could crash or hang (fastText, GGUF, HDF5, ONNX, PyTorch) is listed
without metadata, with one INFO: (reader-unsafe/remote). With
trust_model_files the caller vouches for the repository's model files
and those readers run. Never set it from a request a third party can
make (a service that takes repository URLs): a hostile file can crash
or hang the process, and Ctrl-C cannot interrupt it. No configuration
file can set it. When the folder
holds no Python project but folders below it do, the failure names them
(git.no-project); when it holds files that may be AI models instead,
the failure says to ask for a model SBOM (:func:generate_git_sbom).
Raises:
| Type | Description |
|---|---|
RemoteSourceError
|
the repository could
not be fetched, or |
ValueError
|
url is a Hugging Face model URL
( |
Source code in pitloom/assemble/_generators_git.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
pitloom.assemble.generate_wheel_sbom ¶
generate_wheel_sbom(
wheel_path: Path | str,
*,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
id_registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
offline: bool | None = None,
content_type_method: str | None = None,
update_id_registry: bool | None = None,
max_source_metadata_bytes: int | None = None,
max_model_extract_bytes: int | None = None,
scan_model_usage: bool | None = None,
trust_model_files: bool | None = None,
pitloom_config: PitloomConfig | None = None,
project_dir: Path | str | None = None,
check_url: Callable[[str], None] | None = None,
max_download_bytes: int | None = None,
credentials: CredentialPolicy | None = None,
) -> str
Generate an Analyzed SPDX 3 SBOM for a built Python wheel.
wheel_path may be a PyPI project or release URL (a str; a
:class:~pathlib.Path is always a local file): the release's wheel that
best matches the running environment is downloaded and read
(:func:~pitloom.assemble.generate_pypi_sbom): check_url is called
with every URL of the release lookup and the download before it is
requested (a dependency's licence lookup does not pass through it), and
max_download_bytes caps the file. For a local wheel check_url is not used
and max_download_bytes has no effect (one WARNING:; an invalid
value raises all the same).
A wheel has no [tool.pitloom] of its own, and none is borrowed: not
from the current directory, not from beside the wheel -- either may
belong to an unrelated project. Settings come from the arguments, then
pitloom_config when the caller names one explicitly, then the built-in
defaults. The same holds for the registry: id_registry, else the explicit
config's id-registry; no loom-id-registry.json is searched for.
The copy of that registry a build put in the wheel is left out, with one
WARNING:, when its path below the project directory is the member's
(see :func:~pitloom.id_registry.registry_copy for the directory).
project_dir names the project directory the wheel was built from: its
members are then keyed below that directory's path from the registry's
root (a registry above the project, a monorepo), as embed-wheel
--project-dir keys them. Nothing is read from it; without a registry
it has no effect, with one WARNING:.
credentials (:class:~pitloom.core.credential_policy.CredentialPolicy)
adds to the credentials an explicit pitloom_config accepts.
An explicit pitloom_config applies in full, identity included: its creators, creation datetime and comment fill in when creation_metadata is not given.
AI models inside the wheel are found; scan_model_usage also records
which Python files in it reference them. One model file is copied out
of the wheel at a time, each up to max_model_extract_bytes
(--max-model-extract-bytes; else the config's
max-model-extract-bytes, 512 MiB by default) and four times that in
all, counting bytes copied and bytes read from archive
members; a model beyond either limit is listed without metadata. Models
in a format whose reader a hostile file can crash or hang (fastText,
GGUF, HDF5, ONNX, PyTorch .pt/.pth) are listed without metadata
too, with one INFO:, unless trust_model_files (for a wheel you
trust only; it has no config key, so a config cannot opt in).
extract_file_header/content_type/enrich have no parameter
here: reading a built wheel scans no file headers or content types, and
its AI models are not enriched (see :data:pitloom.core.inert_options.INERT).
content_type_method does apply, because it also steers whether
dependency originator enrichment fetches a remote authors file.
Raises:
| Type | Description |
|---|---|
ValueError
|
The wheel is refused as a whole
(:class: |
FileNotFoundError
|
Nothing is at wheel_path, or not a regular
file; or project_dir is given and is not a directory
( |
CodedValueError
|
wheel_path cannot be looked at
( |
OSError
|
The file itself cannot be opened (its own permissions, a transient I/O error). |
RemoteSourceError
|
a PyPI URL's
wheel could not be fetched or verified ( |
Source code in pitloom/assemble/_generators_wheel.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
pitloom.assemble.generate_wheel_sbom_with_metadata ¶
generate_wheel_sbom_with_metadata(
wheel_path: Path | str,
*,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
id_registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
offline: bool | None = None,
content_type_method: str | None = None,
update_id_registry: bool | None = None,
max_source_metadata_bytes: int | None = None,
max_model_extract_bytes: int | None = None,
scan_model_usage: bool | None = None,
trust_model_files: bool | None = None,
pitloom_config: PitloomConfig | None = None,
project_dir: Path | str | None = None,
check_url: Callable[[str], None] | None = None,
max_download_bytes: int | None = None,
acquisition: Acquisition | None = None,
credentials: CredentialPolicy | None = None,
) -> tuple[str, ProjectMetadata]
:func:generate_wheel_sbom, and the :class:ProjectMetadata read from
the wheel, for a caller that goes on to use the wheel's declared identity
(it need not read METADATA again, and warn about it twice).
wheel_path is a local wheel only (a PyPI URL is read by
:func:generate_wheel_sbom): check_url is not used and
max_download_bytes has no effect (one WARNING:; an invalid value
raises all the same). Both are accepted so that a caller forwarding
:func:generate_wheel_sbom's options can call this instead.
acquisition records how the wheel was downloaded (set by
:func:~pitloom.assemble.generate_pypi_sbom); it adds one provenance
record on the main package, and the gated models' INFO: is the one
for a download (reader-unsafe/remote, naming the file), not a local
wheel's; trust_model_files lifts the gate the same way.
Raises:
| Type | Description |
|---|---|
ValueError
|
The wheel is refused as a whole
(:class: |
FileNotFoundError
|
Nothing is at wheel_path, or not a regular
file; or project_dir is given and is not a directory
( |
CodedValueError
|
wheel_path cannot be looked at
( |
OSError
|
The file itself cannot be opened (its own permissions, a transient I/O error). |
Source code in pitloom/assemble/_generators_wheel.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
pitloom.assemble.generate_model_sbom ¶
generate_model_sbom(
source: Path | str,
*,
offline: bool | None = None,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
id_registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
enrich: bool | None = None,
max_source_metadata_bytes: int | None = None,
pitloom_config: PitloomConfig | None = None,
shown: str | None = None,
max_download_bytes: int | None = None,
check_url: Callable[[str], None] | None = None,
credentials: CredentialPolicy | None = None,
) -> str
Generate an Analyzed SPDX 3 AIBOM for a local model file or HF repository.
Settings resolve as :func:~pitloom.assemble.generate_wheel_sbom
describes: arguments, then an explicit pitloom_config, then the
built-in defaults. Nothing is read from the current directory or from
the model file's own directory.
Four parameters apply to one source kind only, and warn when given for
the other (see :data:pitloom.core.inert_options.INERT):
offline and max_download_bytes for a Hugging Face source (a local
file never reaches the network), and enrich/id_registry for a local
file; a local folder, its one model file
(:func:~pitloom.extract.model_target.model_path_of).
A Hugging Face source's metadata files are downloaded as
:func:~pitloom.extract.remote.read_huggingface describes, under the
policy every remote route resolves
(:func:~pitloom.core.config_cascade.resolve_fetch_policy): with
offline (else pitloom_config's) true nothing is fetched
(huggingface.offline, offline-unusable); each file is capped at
max_download_bytes (else pitloom_config's max-download-bytes,
else 512 MiB); check_url is called with each file's URL and each
redirect target before it is requested (a local file does not use it).
shown is how messages name a local model file (default: as given): a caller that copied it to a temporary directory names it as its user knows it (its path in a Git repository). The SBOM names the file by its own name alone either way.
credentials (:class:~pitloom.core.credential_policy.CredentialPolicy)
adds to the credentials pitloom_config accepts.
Raises:
| Type | Description |
|---|---|
CodedValueError
|
|
Source code in pitloom/assemble/_model_generator.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
pitloom.assemble.generate_env_sbom ¶
generate_env_sbom(
*,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
id_registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
offline: bool | None = None,
content_type_method: str | None = None,
update_id_registry: bool | None = None,
max_source_metadata_bytes: int | None = None,
pitloom_config: PitloomConfig | None = None,
credentials: CredentialPolicy | None = None,
) -> str
Generate a Deployed SPDX 3 SBOM for the current installed environment.
Settings and the registry resolve exactly as
:func:~pitloom.assemble.generate_wheel_sbom describes: arguments, then
an explicit pitloom_config, then the built-in defaults, with nothing
borrowed from the current directory.
content_type_method applies here for one of its two jobs only: it
steers whether each installed package's originator enrichment fetches a
remote authors file. The per-file contentType half needs file
scanning, which reading an installed environment never performs.
credentials (:class:~pitloom.core.credential_policy.CredentialPolicy)
adds to the credentials pitloom_config accepts.
Source code in pitloom/assemble/_generators_env.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
pitloom.assemble.enrich_model ¶
enrich_model(
source: Path | str,
*,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
enrich: bool | None = None,
project_target: Path | str | None = None,
id_registry: str | Path | IdRegistry | None = None,
use_lockfile: bool | None = None,
pitloom_config: PitloomConfig | None = None,
credentials: CredentialPolicy | None = None,
) -> str
Run enrichment only for a local model file.
Settings come from the arguments, then an explicit pitloom_config,
then the built-in defaults; nothing is read from the current directory
or from the model file's directory. The registry is id_registry,
else the explicit config's id-registry; with project_target, the
project's own id-registry key applies instead, since that project
is the document the fragment will merge into, and the credentials its
config accepts join those of pitloom_config and credentials
(:class:~pitloom.core.credential_policy.CredentialPolicy).
Source code in pitloom/assemble/_model_generator.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
Git repositories¶
pitloom.extract.remote.fetch_git_project ¶
fetch_git_project(
url: str,
*,
policy: RemoteFetchPolicy = RemoteFetchPolicy(),
trust_model_files: bool = False,
) -> Iterator[GitCheckout]
Fetch the repository url names into a temporary directory
(pitloom-git- and eight random characters), removed on exit (no
termination guard: Ctrl-C removes it, a process ended by SIGTERM or
SIGKILL leaves it); one that cannot be fully removed (a file still held
open on Windows) is left behind with one WARNING:, never an error.
Within the block, the reads are a temporary clone's
(:func:~pitloom.core.clone_mark.reading_remote_clone, as in
:meth:GitCheckout.reading): nothing out of the checkout's root is read,
the model readers a wheel scan does not run are not run, and the
repository's build-time code is not run. The mark is reset on every exit
and belongs to the calling thread's context alone.
With trust_model_files the caller vouches for the repository's model files: the readers a wheel scan does not run are run (the build-time code is still not run). The default is to run none of them.
policy (:func:~pitloom.core.config_cascade.resolve_fetch_policy)
says what the fetch may do. Its check_url is called with the URL of
every redirect target, without user information, before it is requested
and raises for one that must not be fetched; Pitloom does not check the
URL it is given (the caller does, as it knows its own policy; the PyPI
route, unlike this one, passes its first URLs to its check too). With
offline nothing is fetched. The fetch is stopped once the checkout
(the .git directory included) takes more disk than max_bytes
(git.too-large).
Raises:
| Type | Description |
|---|---|
RemoteSourceError
|
the URL names no fetchable repository, ref or
folder ( |
Exception
|
whatever |
Source code in pitloom/extract/remote/git.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
pitloom.extract.remote.RemoteSourceError ¶
RemoteSourceError(
code: str,
message: str,
*,
pitloom_code: str | None = None,
)
A remote source could not be read.
code names the failure for a caller that maps it to its own
vocabulary (git.clone-failed, git.timeout, git.not-found,
git.offline, git.url-invalid, git.ref-not-found,
git.path-not-found, git.too-many-redirects,
git.output-too-large, git.too-large, git.no-project; for a
PyPI URL pypi.offline, pypi.url-refused,
pypi.too-many-redirects, pypi.project-not-found,
pypi.release-not-found, pypi.no-wheel,
pypi.no-compatible-wheel, pypi.no-sdist,
pypi.response-invalid, pypi.digest-mismatch, pypi.too-large,
pypi.save-failed,
pypi.download-failed, pypi.download-timeout; for a Hugging Face
model huggingface.offline and, for one of its files,
huggingface.download-failed, huggingface.download-timeout,
huggingface.too-large, huggingface.url-refused,
huggingface.too-many-redirects, huggingface.save-failed; and any
code a caller's own URL check raises through :class:RemoteSourceError);
the message is for the user. pitloom_code is the catalogued code of
the condition when it has one, shared by the routes: over-cap for
git.too-large, git.output-too-large and <route>.too-large;
offline-unusable for each .offline; download-timeout for
git.timeout; download-network-failed for a git.clone-failed
whose cause is the network, git-repository-unusable for any other
(git-repository-unusable/empty for an empty repository); every
pypi.*, huggingface.* and git.* code has one. It is read by
:func:pitloom.messages.code_of.
Source code in pitloom/extract/remote/errors.py
47 48 49 50 51 52 53 54 55 56 57 | |
__reduce__ ¶
__reduce__() -> tuple[
type[RemoteSourceError],
tuple[str, str],
dict[str, object],
]
Copied and pickled by its code and message, and every attribute
set on it: args holds the message only, so the default would call
__init__ without the code.
Source code in pitloom/extract/remote/errors.py
59 60 61 62 63 64 65 | |
Wheel embedding¶
pitloom.embed.embed_wheel_sbom ¶
embed_wheel_sbom(
wheel_path: Path | str,
*,
project_dir: Path | str | None = None,
pitloom_config: PitloomConfig | None = None,
sbom_path: Path | str | None = None,
output_path: Path | str | None = None,
sbom_basename: str | None = None,
creation_metadata: CreationMetadata | None = None,
id_registry: str | Path | IdRegistry | None = None,
overrides: ConfigOverrides | None = None,
allow_mismatch: bool = False,
allow_signed_wheel: bool = False,
file_cache: EmbedFileCache | None = None,
) -> tuple[Path, str, str, tuple[str, ...], bool]
Generate and embed a PEP 770 SBOM into a built Python wheel.
When sbom_path supplies an externally-generated SBOM, its declared
subject name/version is cross-checked against the wheel's own
.dist-info/METADATA before anything is written -- see
:func:_enforce_sbom_name_version. A genuine mismatch raises
ValueError unless allow_mismatch. A signed wheel (RECORD.jws/
RECORD.p7s) raises ValueError unless allow_signed_wheel, which
removes the signature the embed would invalidate. A Pitloom-generated SBOM
(sbom_path unset) is never checked: it is built from the wheel's own
metadata.
With project_dir (the project the wheel was built from) the SBOM is a
Build SBOM from that directory's rescan and the wheel's own files;
without it, an Analyzed SBOM of the wheel alone. pitloom_config
replaces the project's own [tool.pitloom]; overrides are the
per-run settings (:class:~pitloom.core.config_cascade.ConfigOverrides);
sbom_basename, creation_metadata and id_registry are as for
:func:~pitloom.assemble.generate. output_path also receives a copy of
the SBOM JSON.
file_cache: advanced/batch use only -- share one
:class:EmbedFileCache across several calls that target the same
project_dir/pitloom_config/overrides.build_options (e.g. one
wheel per call, in a loop) to resolve project_dir's file list (and
run any --allow-build real PEP 517 build) once for the whole
batch instead of once per call. A batch logs each ineffective-option
warning, the model-usage INFO: hint and each gated-format INFO:
once. Left None (the default), this
call resolves and cleans up its own file list. When given, this
call does NOT clean up -- make every call of the batch inside one
with EmbedFileCache() as file_cache: block, whose exit does; a
cache used outside its block raises :class:RuntimeError.
Returns:
| Type | Description |
|---|---|
Path
|
``(wheel path, SBOM arcname in the wheel, SBOM JSON, arcnames removed, |
str
|
floored) |
str
|
returns them, with the SBOM JSON third. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The wheel is refused as a whole
(:class: |
FileNotFoundError
|
Nothing is at wheel_path, or not a regular
file ( |
CodedValueError
|
wheel_path cannot be looked at
( |
CodedOSError
|
The system refused a write
( |
OSError
|
The file itself cannot be opened (its own permissions, a transient I/O error). |
Source code in pitloom/embed.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
pitloom.embed.embed_sbom_in_wheel ¶
embed_sbom_in_wheel(
wheel_path: Path | str,
sbom_content: str | bytes,
*,
sbom_filename: str | None = None,
identity: tuple[str | None, str | None] | None = None,
allow_signed_wheel: bool = False,
) -> tuple[Path, str, tuple[str, ...], bool]
Embed an SPDX 3 SBOM into a built wheel archive (PEP 770).
A wheel carrying RECORD.jws/RECORD.p7s is refused unless
allow_signed_wheel: the embed rewrites RECORD, so the signature
would no longer verify, and it is removed (the removed names are in the
result, as for a stale SBOM).
identity is the wheel's declared (name, version), where the caller has
already read them from its METADATA: the default file name is made
from it, and METADATA is not read, or warned about, again.
Returns:
| Type | Description |
|---|---|
Path
|
|
str
|
the removed names are stale SBOMs and signature files; floored is |
tuple[str, ...]
|
true when the ZIP entry timestamp was raised to 1980-01-01, the |
bool
|
earliest a ZIP can hold. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
Nothing is at wheel_path, or not a regular
file ( |
ValueError
|
sbom_content is empty or white space only
( |
CodedValueError
|
wheel_path cannot be looked at
( |
CodedOSError
|
The system refused the write of the
new wheel (no write permission on its directory, a full disk):
|
OSError
|
An environment problem opening the file itself (its own
permissions, a transient I/O error) -- kept as its own
exception type, not folded into |
Source code in pitloom/_embed_wheel.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | |
pitloom.embed.ConfigOverrides
dataclass
¶
ConfigOverrides(
provenance: ProvenanceConfig | None = None,
enrich: bool | None = None,
extract_file_header: bool | None = None,
scan_model_usage: bool | None = None,
content_type: bool | None = None,
content_type_method: str | None = None,
offline: bool | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
update_id_registry: bool | None = None,
max_source_metadata_bytes: int | None = None,
max_model_extract_bytes: int | None = None,
max_download_bytes: int | None = None,
trust_model_files: bool | None = None,
credentials: CredentialPolicy | None = None,
build_options: BuildOptions = BuildOptions(),
)
Per-run overrides layered onto a project's [tool.pitloom] config.
Every field defaults to None, meaning "not given, defer to the
config"; any other value wins, including one equal to the built-in
default. Each maps to the PitloomConfig field of the same name,
except enrich -> enrich_local and content_type ->
content_type_enabled.
Attributes:
| Name | Type | Description |
|---|---|---|
provenance |
ProvenanceConfig | None
|
Replaces the config's whole provenance settings, not field by field: a field left at its default resets the config's value. |
max_source_metadata_bytes |
int | None
|
Overrides that one provenance field and
leaves the others as the config (or |
max_model_extract_bytes |
int | None
|
|
max_download_bytes |
int | None
|
|
pretty |
bool | None
|
The embed path ( |
trust_model_files |
bool | None
|
|
credentials |
CredentialPolicy | None
|
|
build_options |
BuildOptions
|
|
pitloom.embed.EmbedFileCache ¶
EmbedFileCache()
One file discovery, one build-flag settle and one cleanup for a
batch of embeds from the same project directory -- e.g. several wheels
in one loom embed-wheel run, or a library loop passing
file_cache= to :func:~pitloom.embed.embed_wheel_sbom.
Use it as a context manager around the whole batch. Inside the block,
:meth:resolve runs discovery (and any --allow-build build) on its
first call only, and :meth:settle warns about each ineffective build
flag once (:meth:once does the same for any other per-batch warning,
e.g. an option the embed cannot use) -- all hold a lock, so threads
sharing one batch still get one discovery and one warning each.
Leaving the block runs the discovery's cleanup once, after every wheel
is done -- never per wheel, as an earlier wheel's cleanup would delete
files a later one still reads. The block holds a
:class:~pitloom.core.build_signals.TerminationGuard, so a signal
during the batch still removes the build's temp directory -- but only
for a discovery the block's own thread ran. Guard ownership is
thread-local, so one a worker thread ran registers with that thread's
own guard. It is removed when the block exits normally, and leaks if
a signal ends the process first, or if the block's own exit is
interrupted once that discovery is already cached.
Every call in a batch must use the same project directory, file-scan
settings and build options: :meth:resolve raises :class:ValueError
otherwise. Using it outside the block, or entering it twice, raises
:class:RuntimeError. After the block it can be entered again and
resolves afresh.
Source code in pitloom/_embed_build_sbom.py
96 97 98 99 100 101 102 103 104 105 | |
first_use ¶
first_use(key: Hashable) -> bool
Whether this is the first call with key in this block, so a
once-per-batch message is emitted by exactly one caller. Shares
:meth:once's key space: use a key no :meth:once caller uses.
Raises :class:RuntimeError outside a with block.
Source code in pitloom/_embed_build_sbom.py
293 294 295 296 297 298 299 300 301 302 | |
identity_info_due ¶
identity_info_due() -> bool
Whether the unknown-identity INFO: is still due in this
block: one per batch.
Raises :class:RuntimeError outside a with block.
Source code in pitloom/_embed_build_sbom.py
312 313 314 315 316 317 318 | |
once ¶
once(
key: Hashable,
compute: Callable[[], _T],
method: str = "once",
) -> _T
compute's result, computed on the first call with key in this block and reused after -- so a warning compute logs is logged once for the batch. The caller keys on everything the result depends on.
Raises :class:RuntimeError outside a with block.
Source code in pitloom/_embed_build_sbom.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
registry_warning_due ¶
registry_warning_due() -> bool
Whether the in-tree registry WARNING: is still due in this
block: one per batch, discovery's included.
Raises :class:RuntimeError outside a with block.
Source code in pitloom/_embed_build_sbom.py
304 305 306 307 308 309 310 | |
resolve ¶
resolve(
project_dir: Path,
pitloom_config: PitloomConfig,
build_options: BuildOptions,
exclude_path: Path | None = None,
) -> list[ProjectFile]
Return the cached file list (without exclude_path, the declared registry), running discovery on first use.
Raises :class:RuntimeError outside a with block, and
:class:ValueError when a later call in the block asks for a
different project directory, file-scan settings, build options
or excluded file than the first -- the cached list would not match.
Source code in pitloom/_embed_build_sbom.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
settle ¶
settle(
build_options: BuildOptions,
subject: object,
reason: str | None = None,
) -> BuildOptions
Settle build_options -- with
:meth:~pitloom.core.build_options.BuildOptions.settle, or with
:meth:~pitloom.core.build_options.BuildOptions.settle_not_applicable
and reason when given -- once per block for each distinct
(build_options, reason) pair, reusing that result on later
calls, so each ineffective flag warns once for the batch. A call
with other options or another reason settles (and warns) itself.
Raises :class:RuntimeError outside a with block.
Source code in pitloom/_embed_build_sbom.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
pitloom.extract.wheel.wheel_identity ¶
wheel_identity(
metadata: ProjectMetadata,
) -> tuple[str | None, str | None]
The (name, version) the wheel's METADATA declared, from what
:func:read_wheel returned: None for each it did not.
metadata.name is the sentinel "unknown" where the header is
absent, so only provenance says whether either was read.
Source code in pitloom/extract/wheel.py
154 155 156 157 158 159 160 161 162 163 164 | |
Build options¶
pitloom.core.build_options.BuildOptions
dataclass
¶
BuildOptions(
allow: bool = False,
no_isolation: bool = False,
timeout: int | None = None,
)
Explicit build-and-read options for one call.
Attributes:
| Name | Type | Description |
|---|---|---|
allow |
bool
|
Opt into a real PEP 517 build of the scanned project to
discover its wheel file list ( |
no_isolation |
bool
|
Use the current environment's build backend instead
of an isolated build environment ( |
timeout |
int | None
|
Whole seconds the build may run before it is terminated
( |
no_isolation and timeout have no effect without allow.
The default instance means "no build flag given".
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
settings ¶
settings() -> BuildSettings | None
The resolved settings for a real build, or None when
allow is off.
Source code in pitloom/core/build_options.py
136 137 138 139 140 141 142 143 144 | |
settle ¶
settle(subject: object) -> BuildOptions
Resolve a no_isolation/timeout given without allow:
log one WARNING: per such flag and return
BuildOptions() (defaults) so nothing is left to warn about
later. Returns self unchanged when allow is set (nothing
stray to resolve) or nothing was given (already settled).
Call this as early as a caller can tell the target will reach
file discovery -- before resolving project metadata or a lock
file -- so the warning precedes those, not the other way round.
Idempotent: settling an already-settled value warns nothing and
returns it unchanged, so calling this again downstream (e.g.
inside get_wheel_files()) on a value a caller already
settled is always a silent no-op.
Source code in pitloom/core/build_options.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
settle_not_applicable ¶
settle_not_applicable(
subject: object, reason: str
) -> BuildOptions
Resolve a target a caller already knows will never reach file
discovery (e.g. an sdist archive, a non-project target, an
externally-supplied --sbom): log one WARNING: per given
flag and return BuildOptions()
(defaults), so a downstream call on the same value -- one this
caller forwards, or one a later layer resolves independently --
has nothing left to warn about.
Call this as early as the caller can tell the target's fate,
before reading any project metadata or lock file, so the
warning precedes those rather than following them. reason
follows "has no effect" (no trailing punctuation), e.g.
:data:SDIST_TARGET_REASON. Idempotent the same way :meth:settle
is: the returned (defaulted) value has no given flag to warn about.
Source code in pitloom/core/build_options.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
settle_target ¶
settle_target(target: Path) -> BuildOptions
Settle for a project-or-sdist target path, following
:func:target_settle_plan: an sdist archive gets
:meth:settle_not_applicable with :data:SDIST_TARGET_REASON, a
directory :meth:settle, anything else nothing.
Source code in pitloom/core/build_options.py
166 167 168 169 170 171 172 173 174 175 176 | |
Fragment merging¶
pitloom.assemble.generate_merged_sbom ¶
generate_merged_sbom(
fragments_dir: Path | str,
*,
output_path: Path | str | None = None,
pretty: bool = True,
credentials: CredentialPolicy | None = None,
on_merged: Callable[[int], None] | None = None,
) -> str
Merge every *.json SPDX 3 fragment in fragments_dir into one
SBOM, as loom merge does, and return it as JSON-LD.
The output is one SpdxDocument rooted at what the fragments' own
envelopes rooted; equal elements unify as in a project build with
fragments. The same fragments give the same bytes, whatever the
directory or the order the files were written in.
A fragment field holding a credential that credentials
(:class:~pitloom.core.credential_policy.CredentialPolicy) does not
accept is warned of, or, in its refuse mode, refused; fragments
have no [tool.pitloom] to add to it.
A fragment that cannot be merged is left out with one WARNING:
naming it by fragments_dir as given joined with its file name; when
none can be, nothing is written. on_merged, when given, is called with
the number of fragments merged, once the SBOM is written (loom
merge says it).
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
fragments_dir does not exist, or is not a
directory ( |
ValueError
|
it has no |
FragmentMergeError
|
no fragment of it could be
merged ( |
FragmentMergeError
|
the merge left a dangling
reference, a root included, or a licence relationship end of the
wrong type (a |
Source code in pitloom/assemble/_generators_merge.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
pitloom.assemble.merge_fragments ¶
merge_fragments(
project_dir: Path,
fragments: list[FragmentConfig],
exporter: Spdx3JsonExporter,
*,
adopt_fragment_roots: bool = False,
) -> int
Load SPDX 3 JSON-LD fragment files and merge them into the exporter; return how many were merged (a missing or unreadable one is not).
The main document's profileConformance gains what the merged
fragments' envelopes declared. With adopt_fragment_roots
(loom merge), its rootElement also gains what those envelopes
rooted, after unification; a project keeps its own roots. Every root
goes through the dangling-reference check below.
A fragment whose SpdxDocument id is the exporter's own document
(an earlier SBOM of the same project) is skipped with a WARNING:,
as a missing one is. An ai_AIPackage of the exporter's takes the
name the fragments unifying with it agree on, with one INFO: (see
:mod:pitloom.assemble.spdx3._fragments_model_names). A
not_measured provenance entry of a field the merged element now
holds goes, with one INFO: each (see
:mod:pitloom.assemble.spdx3._fragments_evidence).
A fragment left out is said in one WARNING: naming it as
configured (with adopt_fragment_roots, the directory project_dir as
the caller spelt it joined with its name).
Raises :class:FragmentMergeError (fragment-missing, naming the
configured paths) if any required=True fragment
(see :class:~pitloom.core.config.FragmentConfig) is missing, couldn't
be read or is the document itself, or if the merge leaves the graph
referentially broken (reference-not-found, see
:func:_raise_on_dangling_references) or has a
licence relationship end of the wrong type (see
:func:_raise_on_license_range_violations) -- the
latter two are skipped when fragments is empty or none of it could be
ingested, since there is then nothing new whose references could be
dangling.
Source code in pitloom/assemble/spdx3/fragments.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | |
pitloom.assemble.project_document_id ¶
project_document_id(project_dir: Path) -> str
The SpdxDocument id a loom project build of project_dir
gives (without --allow-build), resolved as :func:_doc_identity_of
resolves it; loom fragment list compares fragments with it.
Source code in pitloom/assemble/_model_generator.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
pitloom.assemble.FragmentMergeError ¶
FragmentMergeError(
message: Message,
/,
*,
line: Line | None = None,
**values: object,
)
A merge of fragments that must not succeed, a :class:ValueError
carrying its code: a required fragment not merged, or none of loom
merge's (fragment-missing), or a merged graph left referentially
broken (reference-not-found: see
:func:_raise_on_dangling_references).
Source code in pitloom/messages/_emit.py
144 145 146 147 148 149 | |
Tracking decorator¶
loom.run is the Run class below (run = Run) -- use it as a
decorator or a context manager, as shown on the Python
API page.
pitloom.loom.Run ¶
Run(
output_file: str | Path,
pretty: bool = False,
creation_metadata: CreationMetadata | None = None,
id_registry: str | Path | IdRegistry | None = None,
*,
pitloom_config: PitloomConfig
| str
| Path
| None = None,
max_dataset_hash_bytes: int | None = None,
credentials: CredentialPolicy | None = None,
)
Context manager and decorator for capturing SPDX fragments.
Each Run is a single recording session that weaves metadata about
a model and its datasets into an SBOM fragment.
Can be used as a context manager::
with loom.run("fragments/train.spdx3.json") as run:
run.set_model("my-model", path="model.bin")
run.add_dataset("train.txt")
run.add_validation_dataset("valid.txt")
# ... training code ...
run.set_model_hyperparameters({"lr": "0.1", "epoch": "5"})
Or as a function decorator::
@loom.run("fragments/preprocess.spdx3.json")
def preprocess():
loom.add_input_dataset("rawdata/neg.txt")
loom.add_output_dataset("data/train.txt",
data_preprocessing=["tokenization"])
The fragment's SPDX CreationInfo is configurable on par with the CLI
and Hatchling build hook: pass a CreationMetadata to name a creator
(a person, organisation, or automated agent), or override the tool,
timestamp, and comment. With none given, the fragment records the
SoftwareAgent "Pitloom" (createdBy) and Tool "Pitloom"
(createdUsing) of an unattended run::
loom.run(
"fragments/train.spdx3.json",
creation_metadata=CreationMetadata(
creators=[Creator(name="Alice", type="person")]
),
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_file
|
str | Path
|
Path to write the SBOM fragment to. |
required |
pretty
|
bool
|
Indent the JSON output with 2 spaces when |
False
|
creation_metadata
|
CreationMetadata | None
|
Creator, tool, timestamp, and comment overrides for
the fragment's |
None
|
id_registry
|
str | Path | IdRegistry | None
|
A |
None
|
pitloom_config
|
PitloomConfig | str | Path | None
|
A |
None
|
max_dataset_hash_bytes
|
int | None
|
The most bytes read to hash one dataset (a
file, or all files of a directory together); a dataset over it
gets no hash and a |
None
|
credentials
|
CredentialPolicy | None
|
A |
None
|
Source code in pitloom/loom.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
pitloom.loom.set_model ¶
set_model(
name: str,
model_type: str | None = None,
hyperparameters: dict[str, str] | None = None,
generated: bool | None = None,
*,
path: str | PathLike[str] | None = None,
) -> None
Declare the AI model being trained in the current run.
Resolved when the run ends without an exception: path, the model's file (relative to the current directory at this call), is then hashed; with a registry, the hash gates the lookup of the file's path key (of name outside the registry's root), and a model the registry does not know is registered. Without a usable path, name is looked up ungated. A file rewritten in between is a new model with a new id.
Source code in pitloom/loom.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
pitloom.loom.use_model ¶
use_model(
name: str,
model_type: str | None = None,
hyperparameters: dict[str, str] | None = None,
*,
path: str | PathLike[str] | None = None,
) -> None
Explicitly declare an AI model consumed by the current run (for
inference); path as for :func:set_model.
Source code in pitloom/loom.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
pitloom.loom.set_model_hyperparameters ¶
set_model_hyperparameters(
hyperparameters: dict[str, str],
) -> None
Update the active model with hyperparameters captured after training.
Source code in pitloom/loom.py
235 236 237 238 239 | |
pitloom.loom.add_dataset ¶
add_dataset(
name: str,
dataset_type: str = "text",
*,
croissant: str | PathLike[str] | None = None,
declared_license: str | None = None,
) -> None
Add a dataset the AI model in the current run uses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The dataset: a file, a directory, or a name for one that is
not local. A directory's dataset card (the YAML frontmatter of
its |
required |
dataset_type
|
str
|
An SPDX |
'text'
|
croissant
|
str | PathLike[str] | None
|
A local Croissant JSON-LD file describing the dataset;
its licence, version, description, creator and other dataset
fields are written onto the package, each with its provenance.
A URL raises |
None
|
declared_license
|
str | None
|
The dataset's licence (an SPDX expression or
other text) as the caller declares it. Declared on any call for
the dataset, it wins over every Croissant file's, which wins
over a dataset card's; of two declared, the first call's wins.
The caller's |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
declared_license is not a string. |
ValueError
|
croissant is a URL, not a regular file, or cannot be read as Croissant. |
Source code in pitloom/loom.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
pitloom.loom.add_validation_dataset ¶
add_validation_dataset(
name: str,
dataset_type: str = "text",
*,
croissant: str | PathLike[str] | None = None,
declared_license: str | None = None,
) -> None
Add a validation/test dataset in the current run; arguments as for
:func:add_dataset.
Source code in pitloom/loom.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
pitloom.loom.add_input_dataset ¶
add_input_dataset(
name: str,
dataset_type: str = "text",
*,
croissant: str | PathLike[str] | None = None,
declared_license: str | None = None,
) -> None
Declare a raw/source dataset consumed by a preprocessing step;
arguments as for :func:add_dataset.
Source code in pitloom/loom.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
pitloom.loom.add_output_dataset ¶
add_output_dataset(
name: str,
dataset_type: str = "text",
data_preprocessing: list[str] | None = None,
input_datasets: list[str] | None = None,
*,
croissant: str | PathLike[str] | None = None,
declared_license: str | None = None,
) -> None
Declare a derived/processed dataset produced by a preprocessing step.
data_preprocessing wins over a source's; input_datasets names the
add_input_dataset() declarations it derives from (None: all);
the other arguments as for :func:add_dataset.
Source code in pitloom/loom.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
Creation metadata¶
pitloom.core.creation.CreationMetadata
dataclass
¶
CreationMetadata(
creators: list[Creator] = list(),
tools: list[Tool] | None = None,
creation_datetime: str | None = None,
creation_comment: str | None = None,
build_datetime: str | None = None,
)
Metadata describing who and what generated an SBOM.
Pitloom's own model for creation provenance -- distinct from, but
mapping onto, SPDX 3 CreationInfo: each creator becomes an Agent
in createdBy (Person, Organization, SoftwareAgent, or
the generic Agent -- see Creator.type), and each tool becomes
a Tool in createdUsing. When no creator is named, the
assembler records the automated SoftwareAgent "Pitloom" in
createdBy -- Pitloom acting on its own -- rather than inventing a
Person.
Attributes:
| Name | Type | Description |
|---|---|---|
creators |
list[Creator]
|
Named creators, in order. When empty (default), no named
creator is asserted and the assembler emits the
|
tools |
list[Tool] | None
|
Creation tools, in order. |
creation_datetime |
str | None
|
ISO 8601 string for the creation timestamp.
Full ISO forms are accepted (e.g. offsets and fractional
seconds). Pitloom preserves input precision internally and
normalises to SPDX 3 DateTime ( |
creation_comment |
str | None
|
Optional comment to include on the SPDX
|
build_datetime |
str | None
|
ISO 8601 string for when the artifact was built
(e.g. the moment the Hatchling hook fires). When set, the
assembler records it as |
pitloom.core.creation.Creator
dataclass
¶
Creator(
name: str,
type: str = "person",
email: str | None = None,
)
A single named creator, mapping onto an SPDX 3 Agent.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Display name of the person or organisation that initiated
the SBOM generation. Stripped in |
type |
str
|
Agent subclass: |
email |
str | None
|
E-mail address of the creator. Recorded as an |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
pitloom.core.creation.Tool
dataclass
¶
Tool(name: str)
A single creation tool, mapping onto an SPDX 3 Tool.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the tool. A tool literally named |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
pitloom.core.creation.VALID_CREATOR_TYPES
module-attribute
¶
VALID_CREATOR_TYPES: frozenset[str] = frozenset(
{"person", "organization", "software-agent", "agent"}
)
pitloom.core.creation.resolve_source_date_epoch ¶
resolve_source_date_epoch() -> datetime | None
Read SOURCE_DATE_EPOCH as a UTC datetime, per reproducible-builds.org.
https://reproducible-builds.org/specs/source-date-epoch/: a single
environment variable the whole build toolchain honours for every
embedded timestamp, so an operator opts a build into reproducibility
once rather than configuring each tool individually. Shared by every
Pitloom timestamp that should respect it (SBOM created, the
Hatchling build hook's builtTime, embedded wheel ZIP entries) so
the parsing/validation rule -- and what counts as invalid -- stays in
one place.
Returns:
| Type | Description |
|---|---|
datetime | None
|
The resolved UTC datetime, or |
datetime | None
|
callers fall back to their own default. |
Raises:
| Type | Description |
|---|---|
ValueError
|
It is set and not an integer number of seconds, or out of range for a date: the specification says a build should fail on a malformed value, as Hatchling does. Every SBOM entry point reads it, whether or not a creation date is pinned, so each reports the one exception, once. |
Source code in pitloom/core/creation.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
Provenance configuration¶
pitloom.core.provenance.ProvenanceConfig
dataclass
¶
ProvenanceConfig(
format: str = "both",
schema: str = DEFAULT_PROVENANCE_SCHEMA,
detail: str = "minimal",
preserve_source_metadata: str = "auto",
max_source_metadata_bytes: int = 0,
)
Configuration settings for SPDX 3 metadata provenance annotations.
Attributes:
| Name | Type | Description |
|---|---|---|
format |
str
|
How to record metadata provenance ("annotation", "comment", "both"). |
schema |
str
|
Schema id for provenance Annotations. |
detail |
str
|
Provenance detail level ("minimal", "full"). |
preserve_source_metadata |
str
|
How to preserve source metadata ("auto", "always", "never"). |
max_source_metadata_bytes |
int
|
Byte budget for the serialised
artifact-metadata Annotation.statement; 0 (default) means
unlimited, below :data: |
__post_init__ ¶
__post_init__() -> None
Reject an invalid format, schema, detail, preserve setting or budget when built, however it got here, not when provenance is first written; keep the budget as a plain int.
Raises:
| Type | Description |
|---|---|
CodedValueError
|
A value is not one the setting
takes ( |
Source code in pitloom/core/provenance.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
pitloom.core.provenance.require_max_source_metadata_bytes ¶
require_max_source_metadata_bytes(
value: object,
where: ConfigPlace | Parameter = _BUDGET_PARAMETER,
) -> int
value as an int when it is 0 (no cap) or a budget of at least
:data:MIN_SOURCE_METADATA_BYTES, the smallest annotation that holds any
metadata. A smaller one is an error, never a silent "unlimited".
The one validator for every surface that takes the budget but the
command-line flag (:func:budget_problem): the config key,
ConfigOverrides and the library kwargs. where is the stage: a
:class:~pitloom.messages.config.ConfigPlace (a configuration file)
raises config-invalid, a :class:~pitloom.messages.config.Parameter
(a library caller's value) option-invalid. Any
:func:operator.index-able integer (a numpy.int64) passes; a bool
or a float does not.
Raises:
| Type | Description |
|---|---|
ValueError
|
value is not an integer, is negative, or is below the
minimum without being |
Source code in pitloom/core/provenance.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
Messages¶
pitloom.messages.code_of ¶
code_of(exc: BaseException) -> str | None
exc's pitloom_code (:data:~pitloom.logging_config.CODE_ATTR,
on the instance or its class) when it is a catalogued code, else
None. Any exception class can carry one; another attribute, such as
the code of an HTTP error, an exit or a remote-source error
(git.too-large), is never read. exc's cause is not consulted: a
wrapping exception states its own condition.
Source code in pitloom/messages/_emit.py
114 115 116 117 118 119 120 121 122 | |
pitloom.messages.trusted_message ¶
trusted_message(line: str) -> Message | None
The catalogued message line (one printed line, no line ending)
says, or None: no code, an uncatalogued one, a text that is not
one of the entry's lines at that level (:func:says), or a line longer
than :data:LONGEST_LINE.
Source code in pitloom/messages/_lines.py
67 68 69 70 71 72 73 74 75 76 77 78 79 | |
pitloom.messages.Message
dataclass
¶
Message(
*,
code: str,
condition: str,
lines: tuple[Line, ...],
summary: str,
did: str,
effect: str,
actor: str,
advice: str,
subject_key: str | None = None,
since: str = "0.22.0",
)
A catalogued message: what Pitloom prints, what it means, what it did and what a reader (a person, or an agent relaying it) should do.
Raises:
| Type | Description |
|---|---|
ValueError
|
A field breaks the catalogue's rules (see
:meth: |
__post_init__ ¶
__post_init__() -> None
Check the entry against the catalogue's rules.
Source code in pitloom/messages/_types.py
237 238 239 240 241 242 243 | |
line_for ¶
line_for(
level: str,
names: Collection[str],
line: Line | None = None,
) -> Line
Its line at level that names exactly names: line, which must be one of them, else the only one.
Raises:
| Type | Description |
|---|---|
ValueError
|
No line does, line is not one, or several do and line does not say which. |
Source code in pitloom/messages/_types.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
ID registry¶
pitloom.id_registry.IdRegistry ¶
IdRegistry(
namespace: str,
elements: dict[tuple[str, str], RegistryEntry]
| None = None,
path: Path | None = None,
project_root: Path | None = None,
*,
id_counters: Counters | None = None,
refuse_credentials: bool = False,
)
A Loom ID registry: stable spdxIds keyed by (compact type, name),
persisted as JSON.
Each entry may carry the element's SHA-256. Harvest records what an
element has; a lookup decides whether the hash must match
(:meth:lookup). :attr:id_counters keeps a retired id from being
minted again (:meth:reserve_id).
refuse_credentials is the run's url-credentials mode for a key
or file entry that holds a credential (:meth:load, :meth:rebase,
:meth:register): True refuses it, False (the warn mode,
the default) keeps it with a WARNING:.
Raises:
| Type | Description |
|---|---|
ValueError
|
namespace cannot be a document namespace
(:func: |
Source code in pitloom/id_registry/_registry.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
generate ¶
generate(
paths: list[Path],
project_root: Path,
*,
exclude: Path | None = None,
explicit: bool = True,
) -> None
(Re-)index files under paths into this registry, except the exclude file (the declared registry itself).
Each file is registered as (software_File, path key, sha256)
(:func:~pitloom.id_registry.keys.join_key of the project's
:func:~pitloom.id_registry.keys.project_prefix and the file's path
from project_root). A file a project scan lists as an AI model
also registers an ai_AIPackage under the same key and hash, so
a retrained model (other bytes) gets a new id. A key new or held
with other content whose one layout alias
(:func:~pitloom.id_registry.keys.alias_tail) is a held key of the
same type and hash takes over that entry, its id kept
(:meth:promote_alias). Promotion is one way, from the shorter key
to the longer; it is skipped when the shorter key is another walked
file's or names a file or directory below the root. Files whose
keys are equal once NFC-normalised are all left out, one WARNING:.
A path in paths that is not there raises FileNotFoundError
(input-not-found), and one that cannot be read or listed a
ValueError (file-unreadable, dir-unlistable), each naming
it as given; one outside project_root a ValueError
(option-invalid). With explicit false (default roots the caller
chose, not the user), a missing path is left out silently, and one
that cannot be read or listed with a WARNING:.
Source code in pitloom/id_registry/_registry.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
get ¶
get(type_name: str, name: str) -> RegistryEntry | None
Return the entry for name under type_name, or None.
Source code in pitloom/id_registry/_registry.py
300 301 302 | |
harvest ¶
harvest(
object_set: SHACLObjectSet,
keys: RecordedKeys | None = None,
hashes: RecordedHashes | None = None,
) -> tuple[int, bool]
A run's auto-harvest: every named element in object_set, each
under the key keys (spdxId -> (compact type, key), what the run's
lookups recorded) holds for it when of its type, else its type and
name (see :func:~pitloom.id_registry._harvest._harvest_elements).
A file in hashes (spdxId -> SHA-256: a Git LFS pointer's oid)
records that hash, not the one its element states.
Returns (new_ids, changed): new_ids counts the distinct
spdxIds new to the registry under keys new to it too (a replaced or
moved id is an update); changed says whether anything changed, an
id counter included: what a caller gates a save() on.
Source code in pitloom/id_registry/_registry.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
has_name ¶
has_name(name: str) -> bool
Return whether name is registered under any type, as given or as that type's own key form.
Source code in pitloom/id_registry/_registry.py
368 369 370 371 372 373 374 | |
id_count ¶
id_count() -> int
Return the number of distinct spdxIds.
Source code in pitloom/id_registry/_registry.py
376 377 378 | |
import_sbom ¶
import_sbom(sbom_path: Path) -> frozenset[tuple[str, str]]
Harvest ids from an existing SPDX 3 JSON-LD SBOM into this registry.
Returns the keys not imported because the SBOM holds several
elements under one key
(:func:~pitloom.id_registry._ambiguous._ambiguous_keys). An empty
registry adopts the SBOM's document id as its namespace when that
is a namespace IRI, else keeps its own, one WARNING:. The
imported id wins, even over a content-gated entry. A file, a
dataset package and a model are written under the key a run looks
them up by (:func:~pitloom.id_registry.import_keys.import_keys,
whose INFO: lines are logged for the elements written), any
other element under its name; none moves an id another key of its
type holds.
Source code in pitloom/id_registry/_registry.py
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
load
classmethod
¶
load(
path: str | PathLike[str],
*,
refuse_credentials: bool = False,
) -> IdRegistry
Load a registry from path.
A file that is not there (or not a file) raises
:class:~pitloom.messages.CodedFileNotFoundError
(input-not-found); every other failure raises a ValueError
carrying its code (:func:~pitloom.id_registry._format.read_registry_file);
it never returns None. A message names path as given (a
:class:~pitloom.core.given_path.GivenPath or
:class:~pitloom.core.given_path.TypedPath keeps its spelling, and
:attr:path keeps it too). Whether a registry
exists at all is decided upstream, by
:func:~pitloom.id_registry.resolve.resolve_registry. A file with
an entry whose key or id holds credentials is refused with
refuse_credentials (the refuse mode), else loaded as it is
with a WARNING: per entry; one whose namespace does is refused
in either mode (credentials-unsafe/registry, the value shown
masked): nothing is dropped or rewritten, the user edits the file.
Raises:
| Type | Description |
|---|---|
TypeError
|
path is not a |
Source code in pitloom/id_registry/_registry.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
lookup ¶
lookup(
type_name: str,
names: Sequence[str],
*,
sha256: str | None = None,
pin_without_hash: bool = False,
miss_hashed: bool = False,
) -> str | None
Return the spdxId of the first of names registered under
type_name, or None.
With sha256, an entry recording the same SHA-256 (any case) is a hit; an entry with no hash is one only with pin_without_hash (an explicit pin, held for any content), so then only an entry recording another hash misses. Without sha256, the entry's hash is ignored (with miss_hashed, a hashed entry misses: no content vouches for it), and so is pin_without_hash. The first of names to hit wins.
Source code in pitloom/id_registry/_registry.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
new
classmethod
¶
new(
project_name: str,
path: Path | None = None,
*,
namespace: str | None = None,
project_root: Path | None = None,
refuse_credentials: bool = False,
) -> IdRegistry
Create a fresh, empty registry (refuse_credentials: see
:class:IdRegistry).
The namespace is namespace (an absolute IRI without # or
credentials; a ValueError otherwise, see :class:IdRegistry),
else one minted from project_name (the
CLI passes the project directory's name) and a random UUID4. It is
fixed once the registry is created: the registry file is an input, so
a committed one gives identical ids.
A name-derived UUID would give two unrelated projects of one name the
same ids.
Source code in pitloom/id_registry/_registry.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
promote_alias ¶
promote_alias(
type_name: str, old_key: str, new_key: str
) -> bool
Re-key the entry of old_key under type_name as new_key, its
spdxId and SHA-256 kept (no mint, no counter); False and no
change when old_key is not held, new_key is, or is not UTF-8.
Source code in pitloom/id_registry/_registry.py
390 391 392 393 394 395 396 397 398 399 400 401 | |
rebase ¶
rebase() -> Rebase
Re-read :attr:path and apply this object's own changes again on
top (:func:~pitloom.id_registry._persist.replay_changes), so a
save keeps what another run saved meanwhile.
A change is a key whose entry differs from the table this object
last read or wrote; for one that has read or written none, every
entry is. The project root becomes the file's, and so does the
namespace, unless this object changed the one it read (id
import adopting an SBOM's) and the file still has that one. The
id counters merge by maximum, so neither run lowers one. With no
file at :attr:path yet, the registry is left as it is.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
the file is no longer there, or not a file. |
ValueError
|
the file cannot be loaded, or an entry holds a
credential in the |
Source code in pitloom/id_registry/_registry.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
refuse_mode ¶
refuse_mode() -> None
Turn this registry to the refuse mode (a run that refuses
was given it loaded), checking its entries as :meth:load would.
Raises:
| Type | Description |
|---|---|
CodedValueError
|
|
Source code in pitloom/id_registry/_registry.py
235 236 237 238 239 240 241 242 243 244 245 246 247 | |
register ¶
register(
type_name: str, name: str, *, sha256: str | None = None
) -> str
Register name under type_name and return its spdxId.
No entry: mint (prefix :func:type_id_prefix) and store sha256.
An entry and no sha256, or an equal one: reuse it unchanged, so an
ungated registration never erases a recorded hash. A dataset
package pin with no hash given one: keep its id, record sha256
(gated from now on), one INFO:. A sha256 that differs from
the entry's, or (any other type) an entry with none: log content
changed, mint a new id and replace the entry.
Raises:
| Type | Description |
|---|---|
ValueError
|
type_name or name cannot be encoded as UTF-8
(the file could never be saved), or name is a URL holding
credentials in the |
Source code in pitloom/id_registry/_registry.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
require_namespace ¶
require_namespace(namespace: str) -> None
Raise ValueError unless this registry's namespace is
namespace (id generate --namespace on an existing registry:
silently keeping the old one would ignore the flag).
Source code in pitloom/id_registry/_registry.py
341 342 343 344 345 346 347 348 349 350 351 352 | |
require_project_root ¶
require_project_root(project_root: Path) -> None
Raise ValueError unless this registry's project root
(:meth:root_dir) is project_root (same directory, whatever the
spelling): keys from two roots in one registry would not match.
Source code in pitloom/id_registry/_registry.py
354 355 356 357 358 359 360 361 362 363 364 365 366 | |
reserve_id ¶
reserve_id(spdx_id: str) -> None
Never mint spdx_id: when it is <namespace>#<prefix>-<n> in
this registry's namespace (:func:~pitloom.id_registry._counters.id_number),
raise the prefix's counter to n. Any other id is ignored, and so
is an n above
:data:~pitloom.id_registry._counters.RESERVE_CEILING: an SBOM
could otherwise use up every number. :meth:_mint_id skips such an
id while the table holds it.
Source code in pitloom/id_registry/_registry.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
root_dir ¶
root_dir() -> Path
Return the project root, else the registry file's directory,
else the current directory -- realpath'd (OSError when that
directory was deleted).
Source code in pitloom/id_registry/_registry.py
380 381 382 383 384 385 386 387 388 | |
save ¶
save(path: Path | None = None) -> None
Write this registry as JSON to path (default: :attr:path).
With no :attr:project_root yet, the registry file's directory
becomes the project root. Raises ValueError when there is no
path, or when the project root cannot be stored relative to it.
Source code in pitloom/id_registry/_registry.py
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
pitloom.id_registry.IdRegistrySession ¶
IdRegistrySession(registry: IdRegistry | None)
One document's registry lookups, first-claimant-wins.
Every element that would otherwise call registry.lookup directly,
across an entire document build (files, directories, AI models, the
project's own, dependency and phantom packages, deployed packages,
loom fragments), instead goes through one shared session so a
registry hit reused by two different elements is claimed by only the
first -- see :meth:lookup_key, :meth:lookup_package and
:meth:lookup_id.
Source code in pitloom/id_registry/_session.py
130 131 132 133 134 135 136 137 138 139 140 141 142 | |
registry
property
¶
registry: IdRegistry | None
The underlying :class:IdRegistry, or None when none applies.
claimed_ids ¶
claimed_ids() -> list[str]
Return every id claimed so far in this session, in claim order.
Source code in pitloom/id_registry/_session.py
363 364 365 | |
info_layout_alias_hits ¶
info_layout_alias_hits() -> None
Log the one INFO: (registry-key-moved) counting this
session's claimed hits found through a layout alias, if any.
Source code in pitloom/id_registry/_session.py
308 309 310 311 312 313 314 315 316 317 318 | |
lookup_id ¶
lookup_id(
claimant: str,
type_name: str,
names: Sequence[str],
*,
sha256: str | None = None,
on_miss: Callable[[], None] | None = None,
) -> str | None
Look up the id registered under type_name for the first of
names that hits, claim it, and return it -- or None.
names (a package's or a directory's name) are tried in order,
each as given, then display-escaped
(:func:~pitloom.core.untrusted_text.escape_display_controls): a
registry imported from an SBOM holds a name as the SBOM shows it,
escaped. With sha256, only an entry recording that hash is a hit
(see :meth:~pitloom.id_registry.IdRegistry.lookup). on_miss is
called only when every name is a raw miss -- never when a hit
exists but this session's claim is rejected (see :meth:_claim).
Returns None immediately, without calling on_miss, when no
registry is loaded in this session.
Source code in pitloom/id_registry/_session.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
lookup_key ¶
lookup_key(
claimant: str,
type_name: str,
lookup: LookupKey,
*,
sha256: str | None = None,
pin_without_hash: bool = False,
miss_hashed: bool = False,
on_miss: Callable[[], None] | None = None,
) -> str | None
Look up the id registered under type_name for lookup, claim
it, record the key it is harvested under, and return it -- or
None.
In order: (1) lookup.key as given; (2) display-escaped
(:func:~pitloom.core.untrusted_text.escape_display_controls), as
:meth:lookup_id does; (3) only when both miss, lookup.alias is
not NONE and sha256 is given: the one held layout alias in
lookup.alias's direction (either spelling, below
lookup.base) recording sha256
(:func:~pitloom.id_registry.keys.alias_candidates); more than one
is a miss with one INFO: per type and key in this session; (4)
a hit is claimed (see :meth:_claim); (5) a claimed id records
lookup.key (raw), or under LAYOUT the held key it matched
(see :meth:recorded_keys). With sha256, only an entry recording
that hash is a hit, or in (1) and (2) one recording none with
pin_without_hash (see :meth:IdRegistry.lookup); without it, no
alias is tried, and with miss_hashed an entry recording a hash
misses. A claimed alias hit is counted
(:meth:info_layout_alias_hits). on_miss is called on a miss,
never on a rejected claim. Returns None without calling
on_miss or recording when no registry is loaded.
Source code in pitloom/id_registry/_session.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
lookup_package ¶
lookup_package(
claimant: str, name: str, version: str | None
) -> str | None
Look up the id registered for the package name at version,
claim it, record its key for harvest, and return it -- or None.
The key is :func:~pitloom.id_registry._types.package_key: with
the version a package states, else bare, and a bare key never hits
a versioned entry or the reverse. It is tried as built, then built
from the display-escaped name and version (a registry imported from
an SBOM holds them as the SBOM shows them); a claimed hit records
the key as built (see :meth:recorded_keys), the key a harvest of
the element derives from its name and version. Ungated, as every
package lookup.
Source code in pitloom/id_registry/_session.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
record_key ¶
record_key(
spdx_id: str,
type_name: str,
key: str,
*,
sha256: str | None = None,
) -> None
Record the raw (never display-escaped) key under type_name
that spdx_id, minted after a miss, is harvested under. A key
recorded by a hit (:meth:lookup_key) wins. sha256, when given,
is the SHA-256 harvest records for spdx_id instead of the one its
element states (see :meth:recorded_hashes). No-op when no
registry is loaded.
Source code in pitloom/id_registry/_session.py
320 321 322 323 324 325 326 327 328 329 330 331 332 | |
recorded_hashes ¶
recorded_hashes() -> Mapping[str, str]
A read-only view of spdxId -> the SHA-256 harvest records for it
in place of the one its element states, given to :meth:record_key
(a Git LFS pointer's oid, whatever digest the SBOM states); an
id with none is absent.
Source code in pitloom/id_registry/_session.py
340 341 342 343 344 345 | |
recorded_keys ¶
recorded_keys() -> Mapping[str, tuple[str, str]]
A read-only view of spdxId -> (type name, raw key) recorded by
:meth:lookup_key and :meth:record_key; an id with no recorded
key is absent.
Source code in pitloom/id_registry/_session.py
334 335 336 337 338 | |
register_id ¶
register_id(
claimant: str, type_name: str, name: str, *, sha256: str
) -> str | None
Register name under type_name with sha256
(:meth:~pitloom.id_registry.IdRegistry.register) and claim the id
for claimant, as a hit would be (see :meth:_claim): a later
lookup hitting it in this session mints its own id.
Raises:
| Type | Description |
|---|---|
ValueError
|
no registry is loaded in this session. |
Source code in pitloom/id_registry/_session.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
pitloom.id_registry.resolve_registry ¶
resolve_registry(
id_registry: str | Path | IdRegistry | None,
configured: str | None,
base_dir: Path,
*,
refuse_credentials: bool = False,
) -> IdRegistry | None
Resolve the registry a build should consult -- an explicit source only, never searched for.
Precedence: id_registry (a flag/kwarg, or an already-loaded
:class:IdRegistry), else configured (the applicable config's own
id-registry: the project's own [tool.pitloom], or an explicit
--config, which replaces it). Neither given: None, silently --
no loom-id-registry.json is searched for, near the target or
anywhere else. A relative path resolves against base_dir (the
project directory, or the current directory for a target with none of
its own), itself resolved first, so the loaded registry's path is
absolute even for a relative base_dir; an already-absolute path (e.g.
a config's own key, made absolute by
:func:~pitloom.core.config_cascade.load_config_file, or a CLI flag
made absolute against cwd) is used as it is.
A resolved path that is not a file raises the input-not-found
FileNotFoundError, naming the path as given: id_registry or
configured as passed, or the spelling a
:class:~pitloom.core.given_path.GivenPath keeps (the CLI flag, a
--config file's key), never the resolved form. One that does not
load raises ValueError (via :meth:IdRegistry.load), naming the
path as given too -- a declared registry is always meant to load; this
function never swallows that failure. refuse_credentials is the run's
url-credentials mode (CredentialPolicy.refuse) for a registry
loaded here (:class:IdRegistry); one passed in is turned to the
refuse mode when the run refuses (:meth:IdRegistry.refuse_mode),
never back. That case is the library's only: a registry the caller
loaded in the warn mode (its entry that holds a credential already
said with a WARNING:) and passed to a run that refuses is checked
again here and raises credentials-unsafe/registry for that entry;
a registry passed in the refuse mode stays so in a warn run.
Source code in pitloom/id_registry/resolve.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
pitloom.id_registry.registry_base_dir ¶
registry_base_dir(target: Path) -> Path
The base directory a relative declared id-registry path
resolves against, for a target that may be either a project
directory or a single file (e.g. an sdist archive).
A file target has no directory to resolve a relative registry path
against (a registry path is not read from inside an archive), so the
current directory is used, as with no project_dir. For every
resolve_registry() call site whose target might be an sdist (or,
in :mod:pitloom.embed, any single-file project_dir).
Source code in pitloom/id_registry/resolve.py
36 37 38 39 40 41 42 43 44 45 46 47 | |
pitloom.id_registry.warn_claim_collision ¶
warn_claim_collision(
spdx_id: str, first: str, second: str
) -> None
Log the one WARNING: (registry-conflict) for spdx_id wanted
by second after first already took it; second mints its own id.
The fields escape each value: a claimant names a path, or a package and
its version, as read.
Source code in pitloom/id_registry/_session.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
pitloom.id_registry.persist_registry ¶
persist_registry(
registry: IdRegistry, new_ids: int, changed: bool
) -> None
Save what a run added to registry and log the outcome.
new_ids counts the distinct ids the run added; changed says whether
it changed anything at all. With no file path: the no-path WARNING:.
Nothing changed: nothing. Else :func:save_registry, and one INFO:
summary when it wrote, counting the new ids the save adds to the file,
at most new_ids (so neither another run's ids nor a refused one
count). A failure, the re-read included, is its own line as one
WARNING: (:func:~pitloom.messages.id_registry.say_save_failure)
and otherwise ignored: the run's own output is already built.
Source code in pitloom/id_registry/_persist.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
pitloom.id_registry.save_registry ¶
save_registry(registry: IdRegistry) -> Rebase
Re-read registry's file, apply this object's changes again
(:meth:~pitloom.id_registry.IdRegistry.rebase) and save the result
when it differs from the file; a new file is saved as it is.
Raises:
| Type | Description |
|---|---|
(OSError, ValueError)
|
the re-read or the write failed; the file is left as it was, unless its directory refuses a temporary file and the write in place fails part-way. |
Source code in pitloom/id_registry/_persist.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
pitloom.id_registry.registry_key_for_path ¶
registry_key_for_path(
registry: IdRegistry, path: Path
) -> str | None
path's software_File key in registry, as spelt:
:func:~pitloom.id_registry.keys.path_key without the on-disk
spelling step. None outside the root; "." for the root. Never
raises.
Source code in pitloom/id_registry/resolve.py
160 161 162 163 164 165 | |
pitloom.id_registry.type_id_prefix ¶
type_id_prefix(type_name: str) -> str
Return the spdxId fragment prefix for a compact type name: the part
after the first _ (software_File -> File), else the name.
Source code in pitloom/id_registry/_types.py
189 190 191 192 193 | |
pitloom.id_registry.RegistryEntry
dataclass
¶
RegistryEntry(spdx_id: str, sha256: str | None = None)
One registered element: its stable spdxId and, when known, the
SHA-256 of its content (lowercase hex).
sha256 is None when there is no hash; "" is never a hash
and is rejected, so "no hash" has one spelling.
pitloom.id_registry.DEFAULT_ID_REGISTRY_FILENAME
module-attribute
¶
DEFAULT_ID_REGISTRY_FILENAME = 'loom-id-registry.json'