Crate spdx

Crate spdx 

Source
Expand description

§🆔 spdx

Helper crate for SPDX license expressions

Embark Embark Crates.io Docs Minimum Stable Rust Version SPDX Version dependency status Build Status

§About

This crate’s main purpose is to parse and evaluate SPDX license expressions. It also optionally provides the ability to scan text data for SPDX license information. Each version of this crate contains a specific version of the official SPDX license list which can be retrieved via the spdx::identifiers::VERSION constant.

§Features

  • text - Includes the full canonical text of each license
  • detection - Allows analysis of text to determine if it might be an SPDX license text, or have an SPDX license header
  • detection-cache - Allows de/serialization of a Store for quicker loading
  • detection-inline-cache - Inlines a Store cache into this crate, which allows easier loading in downstream crates at the cost of increased binary size
  • detection-parallel - Performs license detection in parallel within the same text

§Usage

use spdx::Expression;

let this_is_fine = Expression::parse("MIT OR Apache-2.0").unwrap();

assert!(this_is_fine.evaluate(|req| {
    if let spdx::LicenseItem::Spdx { id, .. } = req.license {
        // Both MIT and Apache-2.0 are OSI approved, so this expression
        // evaluates to true
        return id.is_osi_approved();
    }

    false
}));

assert!(!this_is_fine.evaluate(|req| {
    if let spdx::LicenseItem::Spdx { id, .. } = req.license {
        // This is saying we don't accept any licenses that are OSI approved
        // so the expression will evaluate to false as both sides of the OR
        // are now rejected
        return !id.is_osi_approved();
    }

    false
}));

// `NOPE` is not a valid SPDX license identifier, so this expression
// will fail to parse
let _this_is_not = Expression::parse("MIT OR NOPE").unwrap_err();

§Updating SPDX list

You can update the list of SPDX identifiers for licenses and exceptions by running the update program cargo run --manifest-path=update/Cargo.toml -- v3.6 where v3.6 is the tag in the SPDX data repo.

§Contributing

Contributor Covenant

We welcome community contributions to this project.

Please read our Contributor Guide for more information on how to get started.

§License

Licensed under either of

at your option.

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Re-exports§

pub use error::ParseError;
pub use expression::Expression;
pub use lexer::ParseMode;

Modules§

detectiondetection
Allows analysis of text to determine if it resembles a license This module is basically an inling of askalono
error
Error types
expression
Types used in SPDX expressions, notably Expression
flags
Flags that can apply to licenses and/or license exceptions
identifiers
Auto-generated lists of license identifiers and exception identifiers
lexer
Contains types for lexing an SPDX license expression
texttext
Auto-generated full canonical text of each license

Structs§

AdditionRef
A user supplied AddtionRef-<user string> to specify additional text to associate with a license that falls outside the SPDX license list
Exception
An SPDX exception
ExceptionId
Unique identifier for a particular exception
License
An SPDX license
LicenseId
Unique identifier for a particular license
LicenseRef
SPDX allows the use of LicenseRef-<user supplied string> to provide arbitrary licenses that aren’t a part of the official SPDX license list
LicenseReq
Represents a single license requirement.
Licensee
A convenience wrapper for a license and optional additional text that can be checked against a license requirement to see if it satisfies the requirement placed by a license holder

Enums§

AdditionItem
A single addition term in a addition expression, according to the SPDX spec.
LicenseItem
A single license term in a license expression, according to the SPDX spec.

Functions§

exception_id
Attempts to find an ExceptionId for the string
gnu_license_id
Attempts to find a GNU license from its base name.
imprecise_license_id
Find license partially matching the name, e.g. “apache” => “Apache-2.0”
license_id
Attempts to find a LicenseId given a short id.
license_version
Returns the version number of the SPDX list from which the license and exception identifiers are sourced from