2个版本
0.1.1 | 2023年1月6日 |
---|---|
0.1.0 | 2021年4月29日 |
#205 in 构建实用工具
每月32次下载
18KB
218 行
获取许可助手
使用cargo-license的JSON输出(cargo license --json
)来尝试找到并自动下载你的Rust项目依赖项许可文件。
它基于启发式方法,因此你可能需要手动下载自动找不到的许可证(特别是如果crate不是来自crates.io)。
用例
在创建conda-forge
配方时帮助打包许可证。
例如,查看meta.yaml
中的license_file
部分和cdshealpix-feedstock中的library_licenses
目录(据说)模仿wasmer-feedstock。
安装
首先需要cargo-license
cargo install cargo-license
然后,从本地克隆的存储库安装
cargo install --path .
或直接从crates.io安装
cargo install get-license-helper
使用方法
get-license-helper --help
的结果
get-license-helper 0.1.0
Help in downloading license files from the cargo-license --json output.
USAGE:
get-license-helper [OPTIONS] [input]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-l <license-dir> Directory storing the licenses [default: library_licenses]
ARGS:
<input> Input file (result of cargo-license --json), stdin if not present
注意:使用两次相同的命令更快,因为已经下载的许可证不会被重新下载。
示例
在项目目录中键入
cargo license --json | get-license-helper
并检查library_licenses
目录的内容。
你可以显然重定向输出
cargo license --json | get-license-helper > list.yaml
更改下载许可证的输出目录
cargo license --json | get-license-helper -l my_licenses > list.yaml
或使用保存的cargo-license
结果
cargo license --json > licenses.json
get-license-helper licenses.json -l my_licenses > list.yaml
启发式方法
理想情况下,启发式方法应该首先在https://docs.rs/crate/${name}/${version}/source/
中搜索,但我不知道是否可以下载原始文件而不是HTML页面。
到目前为止,我们依赖于repositories
- 查看提供的
cargo-license
仓库- 如果
github
:在https://raw.githubusercontent.com/${repo}
中寻找许可协议- 使用
${repo}
=${repository}
移除起始的https://github.com/
和可能的结束.git
- 使用
- 如果
gitlab
:在${repository}/-/raw
中寻找许可协议,移除可能的结束.git
到${repository}
- 否则,发出警告
- 如果
- 关于许可协议文件的名称
- 查找提供的
cargo-license
中的license
(如果存在多个许可协议,则在 ' OR ' 上分割)- "MIT":寻找
LICENSE-MIT(.txt|.md)
或LICENSE(.txt|.md)
- "Apache-2.0":寻找
LICENSE-APACHE(.txt|.md)
,LICENSE-Apache(.txt|.md)
或LICENSE(.txt|.md)
- "BSD-3-Clause":寻找
LICENSE-BSD(.txt|.md)
或LICENSE(.txt|.md)
- "BSD-2-Clause":寻找
LICENSE-BSD(.txt|.md)
或LICENSE(.txt|.md)
- "ISC":寻找
LICENSE-ISC(.txt|.md)
或LICENSE(.txt|.md)
- "CC0-1.0":寻找
LICENSE(.txt|.md)
或LICENCE(.txt|.md)
- "MPL-2.0": 查找
LICENSE(.txt|.md)
或LICENCE(.txt|.md)
- "0BSD": 查找
LICENSE-0BSD(.txt|.md)
或LICENCE-0BSD(.txt|.md)
- "Zlib": 查找
LICENSE-ZLIB(.txt|.md)
或LICENCE-ZLIB(.txt|.md)
- "BSL-1.0": 查找
LICENSE-BOOST(.txt|.md)
,LICENSE-BST(.txt|.md)
或LICENSE(.txt|.md)
- "Unlicense": 无需操作
- "MIT":寻找
- 如果没有
license
,查看提供的cargo-license
license-file
- 如果未找到,仍然查找
LICENSE(.txt|.md)
- 如果未找到,仍然查找
- 查找提供的
待改进
- 性能:实现一个
async
工作池以同时探索(HTTP查询)n
个 crate。 - 添加更多许可证:在出现新案例时进行。
- ? 功能:检查许可证文件是否不为空并且与声明的许可证类型一致
- ? 功能:如果找不到许可证,则自动创建一个 LICENSE 文件(从给定的模板)
- ...
警告
- 使用顺序阻塞 HTTP 请求,这很慢。
- 如果相同的 crate(不同版本)被多次使用,则创建重复的输出行
- 不会检查许可证文本是否与声明的许可证一致
许可证
像大多数 Rust 项目一样,该项目在以下许可证下之一发布
- Apache License,版本 2.0,(LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
根据您的要求。
贡献
除非您明确表示,否则根据Apache-2.0许可证定义的,您有意提交给本项目的内容将作为双重许可,如上所述,不附加任何额外条款或条件。
依赖项
~5–20MB
~258K SLoC