背景
OSS の homeassistant を使おうとしていたけれども、公式サイト
にはライセンス記載が何も無い。
- 「Home Assistant Operating System」
- 「Home Assistant Container」
- 「Home Assistant Core」
の3種類のパッケージがある。
「Home Assistant Operating System」はOSイメージ、「Home Assistant Container」はDocker環境。「Home Assistant Core」は Python で記述されていて pip でインストールするようになっています。では最もプリミティブな「Home Assistant Core」を用いてライセンスを調べてみよう。
作戦
pip-licenses を使って、 pip でインストールしたライブラリのライセンスを調べます。ライセンスを調べるためで、インストールは必要ないので、 venv を使ってインストールし、ライセンスがわかったら venv 環境ごと削除してきれいにします。
環境
試したのはRaspberryPiで行っています。
- Raspberry Pi OS Lite
Release date: January 28th 2022
System: 32-bit
Kernel version: 5.10 - Python 3.9.2
venv インストール
venv を使おうとしたら・・・
$ python3 -m venv testenv
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/home/pi/homeassistant/testenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
なので Raspberry Pi OS で用意されている pip をインストールし、venv を pip でインストールしようとしたが・・・
$ sudo apt install python3-pip
こちらはOKだけど
$ sudo pip3 install venv
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
ERROR: Could not find a version that satisfies the requirement venv
ERROR: No matching distribution found for venv
pip では venv は入らないみたい。なので apt でインストールしました。
$ sudo apt-get install python3-venv
testenv というテスト環境を作って作業することにします。
$ python3 -m venv testenv
$ source testenv/bin/activate
(testenv) $ python -V
Python 3.9.2
venv 上の pip はどう使ったらいいのかな?
(testenv) $ sudo pip3 list
Package Version
------------- ---------
certifi 2020.6.20
chardet 4.0.0
colorzero 1.1
distro 1.5.0
gpiozero 1.6.2
idna 2.10
pip 20.3.4
pip-licenses 3.5.3
PTable 0.9.2
python-apt 2.2.1
requests 2.25.1
RPi.GPIO 0.7.0
setuptools 52.0.0
six 1.16.0
spidev 3.5
ssh-import-id 5.10
urllib3 1.26.5
wheel 0.34.2
(testenv) $ pip3 list
Package Version
------------- -------
pip 20.3.4
pkg-resources 0.0.0
setuptools 44.1.1
(testenv) $ pip list
Package Version
------------- -------
pip 20.3.4
pkg-resources 0.0.0
setuptools 44.1.1
上記から、sudo 無しの pip3 または pip でいいみたいですね。
では、 sudo 無しの pip コマンドを使って pip-licenses を venv 内にインストールすることにします。
(testenv) $ pip install pip-licenses
では、homeassistant をインストール。
(testenv) $ pip install homeassistant
.
.
.
Attempting uninstall: pip
Found existing installation: pip 20.3.4
Uninstalling pip-20.3.4:
Successfully uninstalled pip-20.3.4
Successfully installed MarkupSafe-2.0.1 PyJWT-2.1.0 aiohttp-3.8.1 aiosignal-1.2.0 anyio-3.5.0 astral-2.2 async-timeout-4.0.2 atomicwrites-1.4.0 attrs-21.2.0 awesomeversion-22.1.0 bcrypt-3.1.7 certifi-2021.10.8 cffi-1.15.0 charset-normalizer-2.0.11 ciso8601-2.2.0 cryptography-35.0.0 frozenlist-1.3.0 h11-0.12.0 homeassistant-2022.2.2 httpcore-0.14.7 httpx-0.21.3 idna-3.3 ifaddr-0.1.7 jinja2-3.0.3 multidict-6.0.2 pip-20.2.4 pycparser-2.21 python-slugify-4.0.1 pytz-2021.3 pyyaml-6.0 requests-2.27.1 rfc3986-1.5.0 six-1.16.0 sniffio-1.2.0 text-unidecode-1.3 typing-extensions-4.0.1 urllib3-1.26.8 voluptuous-0.12.2 voluptuous-serialize-2.5.0 yarl-1.7.2
homeassistant はインストールできました。何故か pip が20.2.4 になってしまって、venv を使って良かったですね。
homeassistant のライセンスを調べる
(testenv) $ pip-licenses -p homeassistant
Name Version License
homeassistant 2022.2.2 Apache Software License
Apache ライセンスでした。
(testenv) $ pip-licenses --with-urls --with-description -p homeassistant
Name Version License URL Description
homeassistant 2022.2.2 Apache Software License https://www.home-assistant.io/ Open-source home automation platform running on Python 3.
homeassistant の環境を確認しておいて
(testenv) $ cd homeassistant
(testenv) $ du --max-depth=1 -h
408K ./util
24K ./backports
368K ./auth
96K ./generated
104K ./scripts
264K ./__pycache__
1.4M ./helpers
128M ./components
131M .
(testenv) $ cd ..
仮想環境を抜けて、仮想環境ディレクトリをまるごと削除しておしまいです。
(testenv) $ deactivate
$ rm -rf testenv