Policy
Policy evaluation: which detected licenses are acceptable, and for which packages. Deliberately separate from detection — detection says what license a package carries, policy says whether that's acceptable for this project.
trustedlicenses.Policy(allowed_categories, ignored_packages=frozenset(), project_license_keys=frozenset(), trust_corrected_licenses=False, verified_packages=dict(), verified_statements=dict())
dataclass
A project's license policy.
Attributes:
| Name | Type | Description |
|---|---|---|
allowed_categories |
frozenset[str]
|
scancode license categories this project accepts (e.g.
|
ignored_packages |
frozenset[str]
|
Canonical (PEP 503 normalised) names of distributions exempted from the check entirely, regardless of what they detect as. |
project_license_keys |
frozenset[str]
|
SPDX identifiers the consuming project's own declared
license resolves to (from its |
trust_corrected_licenses |
bool
|
Trust every free-text correction
(:attr: |
verified_packages |
Mapping[str, tuple[str, str]]
|
Canonical package name -> the exact |
verified_statements |
Mapping[str, str]
|
Declared statement text -> the SPDX id a human verified
it corrects to, for any package with that exact statement (e.g. several
internal packages sharing identical boilerplate). Same re-check-on-change
property as |
trustedlicenses.PolicyResult(failures, checked, compatibility_notes=tuple())
dataclass
The outcome of evaluating a :class:Policy against installed distributions.
Attributes:
| Name | Type | Description |
|---|---|---|
failures |
tuple[DistributionLicence, ...]
|
Distributions that detected no license in an allowed category, sorted by name. |
checked |
int
|
How many distributions were evaluated (ignored ones excluded). |
compatibility_notes |
tuple[str, ...]
|
Informational (never pass/fail-affecting) notes about a
specific, FSF-documented copyleft compatibility concern between the
consuming project's own declared license and a dependency's -- see
:func: |
Attributes
passed
property
Whether every checked distribution had an allowed license.
trustedlicenses.detect_all(distributions_=None, *, exclude=frozenset())
Detect the license of every distribution, with no policy applied.
Used both by :func:evaluate and for report-only output when no policy is
configured yet (see :func:trustedlicenses.cli.main) -- detection doesn't need a
policy to run, only to judge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distributions_
|
Iterable[Distribution] | None
|
Distributions to inspect. Defaults to every distribution installed in the current environment; overridable for testing, or for inspecting an arbitrary install location (e.g. an isolated temporary directory a candidate package was resolved into). |
None
|
exclude
|
frozenset[str]
|
Canonical (PEP 503 normalised) names to skip entirely. |
frozenset()
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
DistributionLicence
|
class: |
...
|
(canonical-name-deduped) distribution, sorted by name. |
Source code in src/trustedlicenses/policy.py
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 | |
trustedlicenses.evaluate(policy, distributions_=None)
Detect every installed distribution and evaluate it against a policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy
|
Policy
|
The policy to evaluate against. |
required |
distributions_
|
Iterable[Distribution] | None
|
Distributions to check. Defaults to every distribution installed in the current environment; overridable for testing. |
None
|
Returns:
| Type | Description |
|---|---|
PolicyResult
|
The distributions that failed the policy, and how many were checked. |
Source code in src/trustedlicenses/policy.py
297 298 299 300 301 302 303 304 305 306 307 308 309 | |
trustedlicenses.format_failure(failure)
Render one policy failure as a human-readable line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
failure
|
DistributionLicence
|
The failing distribution. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A description of what was detected and why it was rejected. |
Source code in src/trustedlicenses/policy.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
trustedlicenses.format_remediation(failure)
Suggest a policy change that would let one failure pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
failure
|
DistributionLicence
|
The failing distribution. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A one-line suggestion: add the failure's own categories to |
str
|
|
str
|
detected at all but a free-text correction was found, points at trusting that |
str
|
instead (interactively, or via policy config) -- see :func: |
str
|
When nothing was detected and no correction applies either, points at manual |
str
|
verification. |
Source code in src/trustedlicenses/policy.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
trustedlicenses.format_suggestion(failure)
Describe an untrusted free-text correction, and how to trust it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
failure
|
DistributionLicence
|
A failing distribution with a non-empty |
required |
Returns:
| Type | Description |
|---|---|
str
|
A one-line hint naming what the correction looks like and the three ways to |
str
|
trust it -- visible from a plain (non-interactive) report, not just the |
str
|
interactive review wizard. |
Source code in src/trustedlicenses/policy.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |