Detection
License detection for one installed distribution — declared metadata first, a bundled-license-file text-matching fallback second. See How detection works for the full priority order and rationale.
trustedlicenses.DistributionLicence(name, keys, categories, source, suggested=frozenset(), version='')
dataclass
The licenses detected for one installed distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Canonical (PEP 503 normalised) distribution name. |
keys |
frozenset[str]
|
SPDX license identifiers detected for the distribution (e.g. |
categories |
frozenset[str]
|
Categories of |
source |
str
|
Where the detection came from, for a failure report. |
suggested |
frozenset[tuple[str, str]]
|
|
version |
str
|
The installed version, so a later, opt-in index check knows what "newer" means. Empty when unknown. |
trustedlicenses.canonical_name(raw)
Normalise a distribution name per PEP 503.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
str
|
Distribution name as written in metadata or configuration. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The lower-cased name with runs of |
Source code in src/trustedlicenses/detection.py
128 129 130 131 132 133 134 135 136 137 | |
trustedlicenses.inspect_distribution(dist, name=None)
Detect the licenses of one installed distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
Distribution
|
The installed distribution. |
required |
name
|
str | None
|
Its canonical name. Computed from |
None
|
Returns:
| Type | Description |
|---|---|
DistributionLicence
|
What was detected, and where it was detected from. |
Source code in src/trustedlicenses/detection.py
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 | |
trustedlicenses.inspect_installed(name)
Detect the licenses of an installed distribution by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The distribution's project name, as installed (any case/separator). |
required |
Returns:
| Type | Description |
|---|---|
DistributionLicence
|
What was detected, and where it was detected from. |
Raises:
| Type | Description |
|---|---|
PackageNotFoundError
|
No such distribution is installed. |
Source code in src/trustedlicenses/detection.py
442 443 444 445 446 447 448 449 450 451 452 453 454 | |