7 个版本 (稳定版)
2.0.0 | 2023年6月7日 |
---|---|
1.1.2 | 2023年5月30日 |
0.0.3 | 2023年5月25日 |
#776 在 数据库接口
16KB
221 行
WhichLicense 分类 & 合规性工具
此工具旨在存储一个小型许可证标识符数据库,其中包括相应的许可证分类和其他重要参数。该工具提供了一种机制,可以根据它持有的矩阵检测各种许可证分类的合规性状态。
基本用法(分类)
// loading from file
let classifier = CompatibilityIndex::from_file("./data");
// or the longer way
let mut classifier = CompatibilityIndex {
data: std::collections::HashMap::new(),
};
classifier.load_from_file("./data");
// loading from memory
let classifier = CompatibilityIndex::from_memory(&raw)
// or the longer way
let mut classifier = CompatibilityIndex {
data: std::collections::HashMap::new(),
};
classifier.load_from_memory(&raw);
// saving to a file
classifier.save_to_file("./test_data");
// adding an entry
classifier.add("host_license", LicenseEntry {
name: "host_license".to_owned(),
compatibility: hmap!(
"compatible_1".to_owned() => CompatibilityEntry {
name: "compatible_1".to_owned(),
compatible: CompatibilityStatus::Compatible,
explanation: "compatible_1".to_owned(),
},
"incompatible_1".to_owned() => CompatibilityEntry {
name: "incompatible_1".to_owned(),
compatible: CompatibilityStatus::Incompatible,
explanation: "incompatible_1".to_owned(),
},
"unknown_1".to_owned() => CompatibilityEntry {
name: "unknown_1".to_owned(),
compatible: CompatibilityStatus::Unknown,
explanation: "unknown_1".to_owned(),
},
),
spdx_license_key: None,
});
合规性检查
compliancy_check
函数接收要检查的主许可证分类(即,前导许可证),以及所有其他发现的许可证分类(即,从属许可证)(例如,在所有传递依赖项中)。该方法返回一个 CompliancyStatus
。
注意:
CompliancyStatus::NonCompliant
不返回与主机分类相符的分类,只返回那些不符的分类。
// ...
let res = index.check_compliancy("host_license", &vec![
"compatible_1", // assuming that this is compatible with the host license
"compatible_2", // assuming that this is compatible with the host license
]);
let res = index.check_compliancy("host_license", &vec![
"compatible_1", // assuming that this is compatible with the host license
"compatible_2", // assuming that this is compatible with the host license
"incompatible_1", // assuming that this is NOT compatible with the host license
"incompatible_2", // assuming that this is NOT compatible with the host license
]);
assert_eq!(res, CompliancyStatus::NonCompliant(vec![
// gives back the incompatible entries along with their explanations.
CompatibilityEntry {
name: "incompatible_1".to_owned(),
compatible: CompatibilityStatus::Incompatible,
explanation: "incompatible_1".to_owned(),
},
CompatibilityEntry {
name: "incompatible_2".to_owned(),
compatible: CompatibilityStatus::Incompatible,
explanation: "incompatible_2".to_owned(),
}
]));
assert_eq!(res, CompliancyStatus::Compliant);
依赖项
~0.6–1.2MB
~28K SLoC