LoginSignup
11
3

More than 3 years have passed since last update.

いろんなパッケージマネージャで使用しているモジュールのライセンスを確認してみたく

Last updated at Posted at 2019-12-08

毎々お世話になっております、株式会社 日立製作所 OSSソリューションセンタ の 神山直也(hi-naoya) です。
日立グループ OSS Advent Calendar 2019 の9日目、書かせて頂きたく。

私は社内システムの設計、構築、運用、etc …ゆりかごから墓場まで面倒を見ています。
社内システムを作るにもOSSを使うわけですが…このOSSのライセンスって調べるのが本当に大変!!!
なので、備忘録がてら、調べ方を調べてみました。

Python/pip 編

Pythonの場合は pip show コマンドで調べられます。

$ pip3 show PyYAML (python3.7.3 / pip18.1)を実行すると、

Name: PyYAML
Version: 3.13
Summary: YAML parser and emitter for Python
Home-page: http://pyyaml.org/wiki/PyYAML
Author: Kirill Simonov
Author-email: xi@resolvent.net
License: MIT
Location: /usr/lib/python3/dist-packages
Requires: 
Required-by: 

が得られるので、こちらで License を確認できます。
同様の内容は、リポジトリのページから参照できます。

多数のモジュールを一気に見たい場合は pip-licenses モジュールが便利そうです。
$ pip-licenses を実行すると、

 Name      Version  License     
 Click     7.0      BSD         
 greenlet  0.4.15   MIT License 
 msgpack   0.6.2    Apache 2.0  
 neovim    0.3.1    Apache      
 pynvim    0.4.0    Apache

このような形で一覧で、取れます。便利。

Ruby/gem 編

Ruby の場合は、gemの情報を返す gem specification で調べられます。

$ gem specification zlib (ruby2.5.5p157 / gem2.6.7.2)

--- !ruby/object:Gem::Specification
name: zlib
version: !ruby/object:Gem::Version
  version: 1.0.0
...(中略)...
licenses:
- BSD-2-Clause
metadata: {}
...(攻略)..

pip-licenses のgem版みたいなものがあればよかったのですが、見当たらなかったのでワンライナーを書いてみました。

gem list | cut -f1 -d' ' | xargs -n 1 gem specification | grep 'licenses:' -A 3 | grep -oP '(?<=^- ).+$' | sort | uniq

これで、

2-clause BSDL
BSD 2-Clause
BSD-2-Clause
MIT
PSFL
Ruby
Ruby's
ruby

このような形で、使ってるモジュールのライセンスを集計して表示できます。
実際は、どのモジュールがどのライセンスか等細かく見ていく必要があるかと思いますが、ざっくりと全貌掴むには十分そうです。

CentOS/yum 編

Yum の場合は、 yum info でライセンスを含むパッケージ情報が取得できます。

$ yum info openssl (CentOS7.7.1908 / yum3.4.3)

読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.usonyx.net
 * epel: epel.dionipe.id
 * extras: download.nus.edu.sg
 * updates: download.nus.edu.sg
インストール済みパッケージ
名前                : openssl
アーキテクチャー    : x86_64
エポック            : 1
バージョン          : 1.0.2k
リリース            : 19.el7
容量                : 814 k
リポジトリー        : installed
提供元リポジトリー  : base
要約                : Utilities from the general purpose cryptography library with TLS implementation
URL                 : http://www.openssl.org/
ライセンス          : OpenSSL
説明                : The OpenSSL toolkit provides support for secure communications between
                    : machines. OpenSSL includes a certificate management tool and shared
                    : libraries which provide various cryptographic algorithms and
                    : protocols.

こちらもワンライナーで一覧とってみようと思いましたが、yum コマンド実行するとロックがかかるようで、gem と同じ方法ではできませんでした…残念。

最後に

今回調べた方法はほんの一例で、もっと効率的な方法はありそうです。
使うOSSが増えてくると人力で探すのは限界があるので、うまいこと自動化していきたいところです。

TODO

https://github.com/github/licensed
「OSS」「ライセンス」あたりで調べてると、こちらのツールが見つかりました。
やりたいことに合致してそうなので、調べてみたいと思います。

11
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
3