やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

licenseeをインストールしてライセンス情報を取得する

 LICENSEファイルから検出するコマンドツール。

Licensee

 GitHubは以下ツールを使ってライセンスを検出するらしい。ローカルにインストールして確認したい。

インストール

sudo apt-get install -y ruby bundler cmake pkg-config git libssl-dev
sudo gem install licensee

 ヘルプ。

licensee help

help

Licensee commands:
  licensee detect [PATH]        # Detect the license of the given project
  licensee diff [PATH]          # Compare the given license text to a known license
  licensee help [COMMAND]       # Describe available commands or one specific command
  licensee license-path [PATH]  # Returns the path to the given project's license file
  licensee version              # Return the Licensee version

Options:
  [--remote], [--no-remote]  # Assume PATH is a GitHub owner/repo path

 ライセンス検出。カレントディレクトリにLICENSE(.md|.txt)?などFILENAME_REGEXESに一致するファイルが存在すること。

licensee detect

 他にも引数を渡すことが可能。

licensee detect LICENSE.txt
licensee detect https://github.com/facebook/react

複数ライセンス

$ licensee detect https://github.com/rust-lang/rust
License:        NOASSERTION
Matched files:  COPYRIGHT, LICENSE-APACHE, LICENSE-MIT, README.md
COPYRIGHT:
  Content hash:  1cd9558044f4f004a7dad97f882ef269e269e298
  License:       NOASSERTION
  Closest non-matching licenses:
    Artistic-2.0 similarity:  38.17%
LICENSE-APACHE:
  Content hash:  ab3901051663cb8ee5dea9ebdff406ad136910e3
  Confidence:    100.00%
  Matcher:       Licensee::Matchers::Exact
  License:       Apache-2.0
LICENSE-MIT:
  Content hash:  d64f3bb4282a97b37454b5bb96a8a264a3363dc3
  Confidence:    100.00%
  Matcher:       Licensee::Matchers::Exact
  License:       MIT
README.md:
  Content hash:  90a881cd04d1646559c73b08b6ce0c99460cf1b8
  Confidence:    90.00%
  Matcher:       Licensee::Matchers::Reference
  License:       MIT

 ライセンスキーのみ取得する。

$ licensee detect https://github.com/rust-lang/rust | grep 'License:' | grep -v 'NOASSERTION' | sort | uniq | sed -e 's/License://g' | sed 's/ //g'
Apache-2.0
MIT

 HTTPをソースにするとすぐにリクエスト上限に達してエラーになってしまった。

 カレントディレクトリに対して行うなら以下。

licensee detect | grep 'License:' | grep -v 'NOASSERTION' | sort | uniq | sed -e 's/License://g' | sed 's/ //g'

 複数ライセンスのときは以下のようにする。

  • LICENSE.md
  • LICENSE-${license-key}.${ext}

 ライセンスヘッダとしてLICENSE.mdREADME.mdに以下の様なテンプレートを挿入すればよいと思われる。

LICENSE.md

Copyright (c) yyyy author

このソフトウェアは以下のマルチライセンスです。詳細は各ライセンスを参照してください。

* [AGPL-3.0](LICENSE-AGPL.3.0)
* [Apache-2.0](LICENSE-Apache.3.0)

所感

  • licenseeの動作が少し重い
  • マルチライセンスのときは大変そう

対象環境

$ uname -a
Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l GNU/Linux