API Reference

license_tools.tools.cargo_tools

Tools related to Cargo/Rust.

class license_tools.tools.cargo_tools.PackageVersion(name: str, version: str, checksum: str)

Container for holding a package version.

checksum: str

The package checksum.

name: str

The package name.

to_download() Download

Generate the corresponding download URL.

Returns:

The corresponding download.

version: str

The package version.

license_tools.tools.cargo_tools.analyze_metadata(path: Path | str) dict[str, str | list[str]] | None

Analyze the Rust package metadata for the given directory.

Parameters:

path – The directory/file to analyze. Should either be a directory or Cargo.toml file.

Returns:

The package metadata.

license_tools.tools.cargo_tools.check_metadata(path: Path | str) str

Render the relevant details for the given package.

Parameters:

path – The package path.

Returns:

The rendered dictionary-like representation of the relevant fields.

license_tools.tools.cargo_tools.download_from_lock_file(lock_path: Path | str, target_directory: Path | str) None

Download the packages from the given lock file.

Parameters:
  • lock_path – The lock file to read.

  • target_directory – The directory to write the packages to.

license_tools.tools.cargo_tools.get_package_versions(lock_path: Path | str) Generator[PackageVersion]

Get the packages from the given lock file.

Parameters:

lock_path – The lock file to read.

Returns:

The packages retrieved from lock file.

license_tools.tools.cargo_tools.read_toml(path: Path) dict[str, Any]

Read the given TOML file.

Parameters:

path – The file to read.

Returns:

The parsed file content.

license_tools.tools.font_tools

Tools related to fonts.

license_tools.tools.font_tools.analyze_font(path: Path) dict[str, None | dict[str, str | int | datetime]] | None

Analyze the given font and provide a human-readable mapping for the head and name sections.

Parameters:

path – The font path.

Returns:

None if this is no known font type, the parsed results grouped by section name otherwise.

license_tools.tools.font_tools.check_font(path: Path) str | None

Render the relevant details for the given font.

Parameters:

path – The font path.

Returns:

None if no results could be determined, otherwise the rendered dictionary-like representation of the names section which usually holds the copyright data.

license_tools.tools.font_tools.convert_font_direction_hint(value: int) str

Convert the given font direction hint to a human-readable representation.

Parameters:

value – The hint value.

Returns:

The human-readable representation.

license_tools.tools.font_tools.convert_head_flags(value: int) str

Convert the given head flags value to a human-readable string.

Parameters:

value – The flags value.

Returns:

The corresponding human-readable interpretation.

license_tools.tools.font_tools.convert_loc_format(value: int) str

Convert the given loc value to a human-readable representation.

Parameters:

value – The loc value.

Returns:

The human-readable representation.

license_tools.tools.font_tools.convert_mac_style(value: int) str

Convert the mac style to a human-readable representation.

Parameters:

value – The style flags.

Returns:

The corresponding string representation.

license_tools.tools.font_tools.convert_timestamp_to_datetime(value: int) datetime

Convert the given font timestamp to a datetime object.

Parameters:

value – The font timestamp since the font epoch in 1904.

Returns:

The regular datetime object.

license_tools.tools.font_tools.convert_timestamp_to_string(value: int) str

Convert the given font timestamp to a string.

Parameters:

value – The font timestamp since the font epoch in 1904.

Returns:

The corresponding string representation.

license_tools.tools.font_tools.dump_to_ttx(source_path: Path, target_path: Path) Path

Utility function to convert the given font to its XML representation.

Parameters:
  • source_path – The font to read.

  • target_path – The path to write to.

Returns:

The target path. The same as the target_path if its suffix is .ttx, otherwise the target_path with the suffix added.

license_tools.tools.font_tools.handle_ttfont_head(head: table__h_e_a_d) OrderedDict[str, str | int | datetime]

Handle the head section of a TTFont instance.

Parameters:

head – The section to handle.

Returns:

The parsed/human-readable mapping.

license_tools.tools.font_tools.handle_ttfont_names(names: table__n_a_m_e) OrderedDict[str, str | int | datetime]

Handle the names section of a TTFont instance.

Parameters:

names – The names to handle.

Returns:

The parsed/human-readable mapping.

license_tools.tools.font_tools.identity(value: Any) Any

Utility function to return the value itself.

Parameters:

value – The value to return.

Returns:

The input value.

license_tools.tools.image_tools

Tools related to images.

license_tools.tools.image_tools.check_image_metadata(path: Path) str | None

Check the metadata of the given image.

Parameters:

path – The file path to analyze.

Returns:

The analysis results if the path points to an image file, None otherwise.

license_tools.tools.image_tools.is_image(path: Path) bool

Check if the given file is an image file.

Parameters:

path – The file to check.

Returns:

True if the file is an image, False otherwise.

license_tools.tools.linking_tools

Tools related to binary linking.

license_tools.tools.linking_tools.check_shared_objects(path: Path) str | None

Check which other shared objects a shared object links to.

Parameters:

path – The file path to analyze.

Returns:

The analysis results if the path points to a shared object, None otherwise.

license_tools.tools.linking_tools.get_elf_type(path: Path) Literal['executable', 'shared object', 'relocatable', 'unknown'] | None

Get the ELF type of the given file.

Parameters:

path – The file to check.

Returns:

The ELF type of the given file if it is an ELF binary, None otherwise.

license_tools.tools.linking_tools.is_elf(path: Path) bool

Check if the given file is an ELF file.

Parameters:

path – The file to check.

Returns:

True if the file is an ELF binary, False otherwise.

license_tools.tools.pip_tools

Tools related to pip.

license_tools.tools.pip_tools.analyze_metadata(path: Path | str) PackageInfo

Analyze the Python package metadata for the given directory.

Parameters:

path – The directory to analyze. Should either be a .dist-info one or the parent.

Returns:

The package metadata.

license_tools.tools.pip_tools.check_metadata(path: Path | str) str

Render the relevant details for the given package.

Parameters:

path – The package path.

Returns:

The rendered dictionary-like representation of the relevant fields.

license_tools.tools.pip_tools.download_package(package_definition: str, download_directory: Path | str, index_url: str | None = None, prefer_sdist: bool = False) None

Download the given package and save it to the given directory.

Parameters:
  • package_definition – The Python package definition to download.

  • download_directory – The directory to download the package to.

  • index_url – The PyPI index URL to use. Uses the default one from the .pypirc file if unset.

  • prefer_sdist – Download the source distribution instead of the wheel.

license_tools.tools.rpm_tools

Tools related to RPM files.

class license_tools.tools.rpm_tools.DependencyFlags(*values)

Flags used to indicate how to handle dependency relationships.

class license_tools.tools.rpm_tools.FileColor(*values)

Enumeration of file “color”/types.

class license_tools.tools.rpm_tools.FileDigestAlgorithm(*values)

Enumeration of allowed file digest algorithms.

class license_tools.tools.rpm_tools.FileFlags(*values)

Flags used to indicate the file types.

class license_tools.tools.rpm_tools.FileModes(*values)

Enumeration of known file modes.

classmethod make_verbose(mode: int) list[str]

Convert the given mode value into a verbose representation.

Parameters:

mode – The mode to convert.

Returns:

The corresponding named constants matching the given mode.

class license_tools.tools.rpm_tools.VerifyFlags(*values)

Flags used to indicate how to verify the file.

license_tools.tools.rpm_tools.check_rpm_headers(path: Path) str | None

Render the relevant header details for the given RPM.

Parameters:

path – The RPM path.

Returns:

None if no results could be determined, otherwise the rendered dictionary-like representation of the header section which usually holds the copyright data.

license_tools.tools.rpm_tools.extract(archive_path: Path, target_path: Path) None

Extract the given RPM file.

Parameters:
  • archive_path – The RPM file to unpack.

  • target_path – The directory to unpack to.

license_tools.tools.rpm_tools.get_headers(rpm_path: Path) dict[str, Any]

Get the RPM headers.

Parameters:

rpm_path – The RPM file to analyze.

Returns:

The corresponding headers.

license_tools.tools.rpm_tools.get_nice_headers(rpm_path: Path) dict[str, Any]

Get the RPM headers, but with nicer values and verbose names as keys.

Parameters:

rpm_path – The RPM file to analyze.

Returns:

The corresponding headers.

license_tools.tools.scancode_tools

Convenience interface for the ScanCode toolkit project using some predefined configuration and returning dataclass instances instead of dictionaries.

class license_tools.tools.scancode_tools.Author(author: str, start_line: int, end_line: int)

Matching information about an author.

author: str

The author name.

end_line: int

The corresponding end line.

start_line: int

The corresponding start line.

class license_tools.tools.scancode_tools.Copyright(copyright: str, start_line: int, end_line: int)

Matching information about copyrights.

copyright: str

The copyright statement.

end_line: int

The corresponding end line.

start_line: int

The corresponding start line.

class license_tools.tools.scancode_tools.Copyrights(copyrights: list[Copyright] = <factory>, holders: list[Holder] = <factory>, authors: list[Author] = <factory>)

Copyright-specific results.

authors: list[Author]

The detected authors.

copyrights: list[Copyright]

The detected copyright statements.

holders: list[Holder]

The detected copyright holders.

class license_tools.tools.scancode_tools.Email(email: str, start_line: int, end_line: int)

Matching information about an e-mail.

email: str

The e-mail address.

end_line: int

The corresponding end line.

start_line: int

The corresponding start line.

class license_tools.tools.scancode_tools.Emails(emails: list[Email] = <factory>)

E-mail-specific results.

emails: list[Email]

The detected e-mail addresses.

class license_tools.tools.scancode_tools.FileInfo(date: date, size: int, sha1: str | None, md5: str | None, sha256: str | None, mime_type: str, file_type: str, programming_language: str | None, is_binary: bool, is_text: bool, is_archive: bool, is_media: bool, is_source: bool, is_script: bool, sha1_git: str | None = None)

File-specific results.

date: date

The modification date.

file_type: str

The detected file type.

is_archive: bool

Whether this file is an archive.

is_binary: bool

Whether this file is a binary one.

is_media: bool

Whether this is some media file.

is_script: bool

Whether this file is some script.

is_source: bool

Whether this is some source code file.

is_text: bool

Whether this file is a plaintext one.

md5: str | None

The MD5 hash.

mime_type: str

The detected mime type.

programming_language: str | None

The detected programming language.

sha1: str | None

The SHA1 hash.

sha1_git: str | None = None

The hash according to the Git blob SHA1 convention (https://git-scm.com/book/en/v2/Git-Internals-Git-Objects#_object_storage).

sha256: str | None

The SHA256 hash.

size: int

The file size in bytes.

class license_tools.tools.scancode_tools.FileResults(path: Path, short_path: str, retrieve_copyrights: bool = False, retrieve_emails: bool = False, retrieve_urls: bool = False, retrieve_licenses: bool = False, retrieve_file_info: bool = False, copyrights: Copyrights | None = None, emails: Emails | None = None, urls: Urls | None = None, licenses: Licenses | None = None, file_info: FileInfo | None = None, email_limit: int | None = 50, url_limit: int | None = 50)

Container for all available file-level results.

copyrights: Copyrights | None = None

The detected copyrights.

email_limit: int | None = 50

The maximum number of e-mails to retrieve.

emails: Emails | None = None

The detected e-mail addresses.

file_info: FileInfo | None = None

The retrieved file information.

licenses: Licenses | None = None

The detected licenses.

path: Path

Full path of the analyzed file.

retrieve_copyrights: bool = False

Configuration option: Whether to retrieve copyright information.

retrieve_emails: bool = False

Configuration option: Whether to retrieve e-mail addresses.

retrieve_file_info: bool = False

Configuration option: Whether to retrieve file information.

retrieve_licenses: bool = False

Configuration option: Whether to retrieve license information.

retrieve_urls: bool = False

Configuration option: Whether to retrieve URLs.

short_path: str

Short path of the analyzed file, with the common prefix removed.

url_limit: int | None = 50

The maximum number of URLs to retrieve.

urls: Urls | None = None

The detected URLs.

class license_tools.tools.scancode_tools.Holder(holder: str, start_line: int, end_line: int)

Matching information about a copyright holder.

end_line: int

The corresponding end line.

holder: str

The copyright holder.

start_line: int

The corresponding start line.

class license_tools.tools.scancode_tools.LicenseClue(score: float, start_line: int, end_line: int, matched_length: int, match_coverage: float, matcher: str, license_expression: str, license_expression_spdx: str, rule_identifier: str, rule_relevance: int, rule_url: str | None, from_file: str | None, matched_text: str | None = None)

Matching information about a license. Compared to regular detections/matches, these are rather considered clues and not perfect detections.

Currently the same as LicenseMatch.

class license_tools.tools.scancode_tools.LicenseDetection(license_expression: str, license_expression_spdx: str, identifier: str, matches: list[LicenseMatch] = <factory>)

Information on a specific detected license.

identifier: str

An unique ID for this detection.

license_expression: str

The detected license expression.

license_expression_spdx: str

The detected license expression in SPDX format.

matches: list[LicenseMatch]

The corresponding detailed match data.

class license_tools.tools.scancode_tools.LicenseMatch(score: float, start_line: int, end_line: int, matched_length: int, match_coverage: float, matcher: str, license_expression: str, license_expression_spdx: str, rule_identifier: str, rule_relevance: int, rule_url: str | None, from_file: str | None, matched_text: str | None = None)

Matching information about a license.

end_line: int

The corresponding end line.

from_file: str | None

Unused/unclear.

license_expression: str

The detected license expression.

license_expression_spdx: str

The detected license expression in SPDX format.

match_coverage: float

How much of the rule text is part of the match?

matched_length: int

The length of the match in bytes/characters.

matched_text: str | None = None

The text of the match.

matcher: str

The corresponding matcher type.

rule_identifier: str

The corresponding matcher rule.

rule_relevance: int

The relevance of the corresponding rule.

rule_url: str | None

Upstream link for this rule.

score: float

The matching score.

start_line: int

The corresponding start line.

class license_tools.tools.scancode_tools.Licenses(detected_license_expression: str | None = None, detected_license_expression_spdx: str | None = None, percentage_of_license_text: float = 0.0, license_detections: list[LicenseDetection] = <factory>, license_clues: list[LicenseClue] = <factory>)

Information on all detected licenses.

detected_license_expression: str | None = None

The detected license expression.

detected_license_expression_spdx: str | None = None

The detected license expression in SPDX format.

get_scores_of_detected_license_expression_spdx() list[float]

Attempt to resolve the scores for the detected license expression.

Returns:

The corresponding scores if they could be resolved.

license_clues: list[LicenseClue]

The corresponding license clues.

license_detections: list[LicenseDetection]

The corresponding license detections.

percentage_of_license_text: float = 0.0

How much of the file content is part of the license text?

class license_tools.tools.scancode_tools.PackageResults(api_data_url: str | None = None, bug_tracking_url: str | None = None, code_view_url: str | None = None, copyright: str | None = None, datasource_id: str | None = None, declared_license_expression: str | None = None, declared_license_expression_spdx: str | None = None, description: str | None = None, download_url: str | None = None, extracted_license_statement: str | None = None, holder: str | None = None, homepage_url: str | None = None, keywords: list[str] = <factory>, license_detections: list[LicenseDetection] = <factory>, md5: str | None = None, name: str | None = None, namespace: str | None = None, notice_text: str | None = None, other_license_detections: list[LicenseDetection] = <factory>, other_license_expression: str | None = None, other_license_expression_spdx: str | None = None, parties: list[Party] = <factory>, primary_language: str | None = None, purl: str | None = None, qualifiers: dict[str, str]=<factory>, release_date: date | None = None, repository_download_url: str | None = None, repository_homepage_url: str | None = None, sha1: str | None = None, sha256: str | None = None, sha512: str | None = None, size: int | None = None, source_packages: list[str] | None = None, subpath: str | None = None, type: str | None = None, vcs_url: str | None = None, version: str | None = None, is_virtual: bool = False, is_private: bool = False)

Container for package-specific data, based upon packagedcode.models.PackageData.

api_data_url: str | None = None

API URL to obtain structured data for this package.

bug_tracking_url: str | None = None

URL to the issue or bug tracker.

code_view_url: str | None = None

An URL where th ecode can be browsed online.

copyright: str | None = None

Copyright statements for this package.

datasource_id: str | None = None

Data source identifier for the source of the package data.

declared_license_expression: str | None = None

License expression derived from metadata.

declared_license_expression_spdx: str | None = None

License expression derived from metadata in SPDX format.

description: str | None = None

Description for this package.

download_url: str | None = None

A direct download URL.

extracted_license_statement: str | None = None

License statement extracted from the metadata.

classmethod from_rpm(path: Path) PackageResults

Get the results for the given RPM path.

Parameters:

path – The RPM path to run on.

Returns:

The corresponding results.

holder: str | None = None

Copyright holders for this package.

homepage_url: str | None = None

URL to the homepage.

is_private: bool = False

Indicate private packages.

is_virtual: bool = False

Indicate virtual packages.

keywords: list[str]

Associated keywords.

license_detections: list[LicenseDetection]

Detected licenses.

md5: str | None = None

MD5 checksum.

name: str | None = None

Package name.

namespace: str | None = None

Package namespace.

notice_text: str | None = None

Corresponding notice text.

other_license_detections: list[LicenseDetection]

Additional license detections.

other_license_expression: str | None = None

Another/a secondary license derived from the metadata.

other_license_expression_spdx: str | None = None

Another/a secondary license derived from the metadata in SPDX format.

parties: list[Party]

Parties such as a person, project or organization.

primary_language: str | None = None

Primary programming language.

purl: str | None = None

Corresponding PURL identifier.

qualifiers: dict[str, str]

Mapping of package qualifiers.

release_date: date | None = None

Release date of the package.

repository_download_url: str | None = None

Download URL for this package in its package repository.

repository_homepage_url: str | None = None

URL to the page for this package in its package repository.

sha1: str | None = None

SHA1 checksum.

sha256: str | None = None

SHA256 checksum.

sha512: str | None = None

SHA512 checksum.

size: int | None = None

Size of the package download in bytes.

source_packages: list[str] | None = None

PURLs for related source packages.

subpath: str | None = None

Subpath inside a package, relative to its root.

type: str | None = None

Short code for package type.

vcs_url: str | None = None

An URL to the VCS repository in SPDX format.

version: str | None = None

Package version.

class license_tools.tools.scancode_tools.Party(type: Literal[None, 'person', 'project', 'organization'] = None, role: str | None = None, name: str | None = None, email: str | None = None, url: str | None = None)

A party related to a package.

PARTY_TYPES

Available party types.

alias of Literal[None, ‘person’, ‘project’, ‘organization’]

email: str | None = None

The corresponding e-mail address.

name: str | None = None

The corresponding name.

role: str | None = None

The associated role.

type: Literal[None, 'person', 'project', 'organization'] = None

The party type.

url: str | None = None

The corresponding URL/webpage.

class license_tools.tools.scancode_tools.Url(url: str, start_line: int, end_line: int)

Matching information about an URL.

end_line: int

The corresponding end line.

start_line: int

The corresponding start line.

url: str

The URL.

class license_tools.tools.scancode_tools.Urls(urls: list[Url] = <factory>)

URL-specific results.

urls: list[Url]

The detected URLs.

license_tools.tools.scancode_tools.cleanup(directory: Path | str) None

Remove the given directory.

license_tools.tools.translation_tools

Tools related to translations.

license_tools.tools.translation_tools.check_compiled_gettext_metadata(path: Path) str | None

Check the metadata of the given compiled gettext translation file.

Parameters:

path – The file path to analyze.

Returns:

The analysis results if the path points to a compiled gettext translation file, None otherwise.

license_tools.tools.translation_tools.is_compiled_gettext_file(path: Path) bool

Check if the given file is a compiled gettext translation file.

Parameters:

path – The file to check.

Returns:

True if the file is a compiled gettext translation file, False otherwise.

license_tools.utils.archive_utils

Archive handling.

license_tools.utils.archive_utils.can_extract(archive_path: Path) bool

Check if the given archive can be extracted.

Parameters:

archive_path – The path to check for.

Returns:

The check result.

license_tools.utils.archive_utils.extract(archive_path: Path, target_directory: Path, recurse: bool = False) None

Extract the given archive recursively.

Parameters:
  • archive_path – The archive to unpack.

  • target_directory – The target directory to use.

  • recurse – Whether to use a recursive approach.

license_tools.utils.download_utils

Download handling.

exception license_tools.utils.download_utils.ChecksumError

Error indicating a wrong checksum.

class license_tools.utils.download_utils.Download(url: str, filename: str, sha256: str | None = None)

Configuration for one file download.

filename: str

The target filename.

sha256: str | None = None

The expected SHA256 checksum.

url: str

The download URL.

verify_checksum(data: bytes) None

Check if the checksum of the given data matches the expected one.

Raises ChecksumError if something is wrong.

Parameters:

data – The data to check.

exception license_tools.utils.download_utils.DownloadError

Error indicating some (generic) download failure.

license_tools.utils.download_utils.download_file(url: str, file_object: BinaryIO) None

Download the given file to the given file object.

Parameters:
  • url – The download URL to use.

  • file_object – The binary file to download to. Reset after writing.

license_tools.utils.download_utils.download_file_to_directory(download: Download, directory: Path, session: Session | None = None) None

Download the given file to the given directory.

Parameters:
  • download – Download to perform.

  • directory – Directory to download to.

  • session – Session to use.

license_tools.utils.download_utils.download_one_file_per_second(downloads: list[Download], directory: Path) None

Download the given files with not more than one request per second. This conforms to https://crates.io/data-access#api accordingly.

Parameters:
  • downloads – List of downloads to perform.

  • directory – Directory to download to.

license_tools.utils.download_utils.get_session() Session

Get an identifiable session.

Returns:

The session which identifies us against the server.

license_tools.utils.path_utils

class license_tools.utils.path_utils.DirectoryWithFixedNameContext(directory: str | Path, fallback_to_random_if_exists: bool = True, delete_afterwards: bool = True)

Create the directory with the given name. Similar to tempfile.TemporaryDirectory, but with a fixed name.

Parameters:
  • directory – The target directory to create temporarily.

  • fallback_to_random_if_exists – Specify whether to fail if the target directory already exists or whether to fall back to a random directory with the same parent in this case.

  • delete_afterwards – Specify whether to delete the directory on exit.

license_tools.utils.path_utils.get_file_type(path: Path) str

Get the file type.

Param:

The file to check.

Returns:

The guessed file type.

license_tools.utils.path_utils.get_files_from_directory(directory: str | Path, prefix: str | None = None) Generator[tuple[Path, str]]

Get the files from the given directory, recursively.

Parameters:
  • directory – The directory to walk through.

  • prefix – Custom prefix to use.

Returns:

For each file, the complete Path object as well as the path string relative to the given directory.

license_tools.utils.path_utils.get_mime_type(path: Path) str

Get the mime type.

Param:

The file to check.

Returns:

The guessed mime type.

license_tools.utils.rendering_utils

Rendering utilities.

license_tools.utils.rendering_utils.render_dictionary(dictionary: dict[str, Any], verbose_names_mapping: dict[str, str], multi_value_keys: set[str]) str

Render the given dictionary as string.

Parameters:
  • dictionary – The dictionary to render.

  • verbose_names_mapping – The mapping dictionary to use for the keys. Keys not available inside this dictionary will be skipped.

  • multi_value_keys – Dictionary keys which could have multiple values.

license_tools.retrieval

Retrieve license-related data.

class license_tools.retrieval.RetrievalFlags

Data retrieval flags to get shorter parameter lists.

classmethod all(as_kwargs: bool = False) int | dict[str, bool]

Utility method to enable all flags.

Param:

If enabled, return kwargs instead of the integer value.

Returns:

The value for all flags enabled.

classmethod is_set(flags: int, flag: int) bool

Check if the given flag is set.

Parameters:
  • flags – The flags to check inside.

  • flag – The flag value to check for.

Returns:

The check result.

classmethod to_int(retrieve_copyrights: bool = False, retrieve_emails: bool = False, retrieve_file_info: bool = False, retrieve_urls: bool = False, retrieve_ldd_data: bool = False, retrieve_font_data: bool = False, retrieve_python_metadata: bool = False, retrieve_cargo_metadata: bool = False, retrieve_image_metadata: bool = False) int

Convert the given boolean parameter values to a single integer flag value.

Parameters:
  • retrieve_copyrights – Whether to retrieve copyright information.

  • retrieve_emails – Whether to retrieve e-mails.

  • retrieve_file_info – Whether to retrieve file-specific information.

  • retrieve_urls – Whether to retrieve URLs.

  • retrieve_ldd_data – Whether to retrieve linking data for shared objects.

  • retrieve_font_data – Whether to retrieve font data.

  • retrieve_python_metadata – Whether to retrieve Python package metadata.

  • retrieve_cargo_metadata – Whether to retrieve Cargo metadata.

  • retrieve_image_metadata – Whether to retrieve image metadata.

Returns:

The flags derived from the given parameters.

classmethod to_kwargs(flags: int) dict[str, bool]

Convert the given flags to keyword arguments.

Parameters:

flags – The flags to convert.

Returns:

The associated keyword arguments.

license_tools.retrieval.run(*, directory: Path | str | None = None, file_path: Path | str | None = None, archive_path: Path | str | None = None, package_definition: str | None = None, download_url: str | None = None, index_url: str | None = None, prefer_sdist: bool = False, job_count: int = 4, retrieve_copyrights: bool = False, retrieve_emails: bool = False, retrieve_file_info: bool = False, retrieve_urls: bool = False, retrieve_ldd_data: bool = False, retrieve_font_data: bool = False, retrieve_python_metadata: bool = False, retrieve_cargo_metadata: bool = False, retrieve_image_metadata: bool = False, file_size_limit: int = 9223372036854775807) list[FileResults]

Run the analysis for the given input definition.

The directory, file_path, archive_path and package_definition parameters are mutually exclusive, but exactly one has to be set.

Parameters:
  • directory – The directory to run on.

  • file_path – The file to run on.

  • archive_path – The package archive to run on.

  • package_definition – The package definition to run for.

  • download_url – The package URL to download and run on.

  • index_url – The PyPI index URL to use. Uses the default one from the .pypirc file if unset.

  • prefer_sdist – For PyPI downloads, prefer/use the source distribution over/instead of the wheel.

  • job_count – The number of parallel jobs to use.

  • retrieve_copyrights – Whether to retrieve copyright information.

  • retrieve_emails – Whether to retrieve e-mails.

  • retrieve_file_info – Whether to retrieve file-specific information.

  • retrieve_urls – Whether to retrieve URLs.

  • retrieve_ldd_data – Whether to retrieve linking data for shared objects.

  • retrieve_font_data – Whether to retrieve font data.

  • retrieve_python_metadata – Whether to retrieve Python package metadata.

  • retrieve_cargo_metadata – Whether to retrieve Cargo metadata.

  • retrieve_image_metadata – Whether to retrieve image metadata.

  • file_size_limit – The file size limit in bytes to skip analysis for.

Returns:

The requested results.

license_tools.retrieval.run_on_directory(directory: str, job_count: int = 4, retrieval_flags: int = 0, prefix: str | None = None, allow_random_directory_for_archive: bool = True, delete_unpacked_archive_directories: bool = True, file_size_limit: int = 9223372036854775807) Generator[FileResults]

Run the analysis on the given directory.

Parameters:
  • directory – The directory to analyze.

  • job_count – The number of parallel jobs to use.

  • retrieval_flags – Values to retrieve.

  • prefix – Custom prefix to use.

  • allow_random_directory_for_archive – Allow a random directory for unpacking archives.

  • delete_unpacked_archive_directories – Delete the directories of unpacked archives afterwards.

  • file_size_limit – The file size limit in bytes to skip analysis for.

Returns:

The requested results per file.

license_tools.retrieval.run_on_downloaded_archive_file(download_url: str, job_count: int = 4, retrieval_flags: int = 0, file_size_limit: int = 9223372036854775807) Generator[FileResults]

Run the analysis on the given archive file after downloading it.

Parameters:
  • download_url – The URL to download the archive from.

  • job_count – The number of parallel jobs to use.

  • retrieval_flags – Values to retrieve.

  • file_size_limit – The file size limit in bytes to skip analysis for.

Returns:

The requested results.

license_tools.retrieval.run_on_downloaded_package_file(package_definition: str, index_url: str | None = None, job_count: int = 4, retrieval_flags: int = 0, prefer_sdist: bool = False, file_size_limit: int = 9223372036854775807) Generator[FileResults]

Run the analysis for the given package definition.

Parameters:
  • package_definition – The package definition to get the files for.

  • index_url – The PyPI index URL to use. Uses the default one from the .pypirc file if unset.

  • job_count – The number of parallel jobs to use.

  • retrieval_flags – Values to retrieve.

  • prefer_sdist – Download the source distribution instead of the wheel.

  • file_size_limit – The file size limit in bytes to skip analysis for.

Returns:

The requested results.

license_tools.retrieval.run_on_file(path: Path, short_path: str, retrieval_flags: int = 0, file_size_limit: int = 9223372036854775807) FileResults

Run the analysis on the given file.

Parameters:
  • path – The file path to analyze.

  • short_path – The short path to use for display.

  • retrieval_flags – Values to retrieve.

  • file_size_limit – The file size limit in bytes to skip analysis for.

Returns:

The requested results.

license_tools.retrieval.run_on_package_archive_file(archive_path: Path, job_count: int = 4, retrieval_flags: int = 0, file_size_limit: int = 9223372036854775807) Generator[FileResults]

Run the analysis on the given package archive file.

Parameters:
  • archive_path – The package archive path to analyze.

  • job_count – The number of parallel jobs to use.

  • retrieval_flags – Values to retrieve.

  • file_size_limit – The file size limit in bytes to skip analysis for.

Returns:

The requested results.