4.2. python27 および rh-python35 Software Collections の拡張
本セクションでは、依存する Software Collection を作成して python27 および rh-python35 の Software Collections を拡張する方法を説明します。
Red Hat Software Collections 3.8 では、scl ツールはマクロ
%scl_package_override()
をサポートするように拡張されました。これにより、依存する Software Collection のパッケージ化が容易になりました。
4.2.1. vt191 Software Collection
以下は、依存する Software Collection を構築する例です。Software Collection には
vt191
という名前が付けられ、versiontools Python パッケージバージョン 1.9.1 が同梱されています。
vt191 Software Collection のメタパッケージでは、以下の点に注意してください。
- vt191 Software Collection メタパッケージには、以下のビルド依存関係が設定されています。
BuildRequires: %{scl_prefix_python}scldevel
これは、たとえば python27-scldevel などに展開されます。python27-scldevel サブパッケージには、2 つの重要なマクロ%scl_python
および%scl_prefix_python
が同梱されています。このマクロは、メタパッケージの spec ファイルの上部に定義されていることに注意してください。定義は必須ではありませんが、vt191 Software Collection が python27 Software Collection に構築されるように設計されているという視覚的なヒントを提供します。フォールバック値としても機能します。 site-packages
ディレクトリーを正しく設定するには、%python27python_sitelib
マクロの値を使用して、python27
をvt191
に置き換えます。Software Collection を別のプロバイダー (例:/opt/myorganization/
instead of/opt/rh/
) を使用して構築する場合は、これらも変更する必要があります。重要/opt/rh/
プロバイダーは Red Hat が提供する Software Collections のインストールに使用するため、競合の可能性を回避するために別のプロバイダーを使用することを強く推奨します。詳細は、「Software Collection Root ディレクトリー」 を参照してください。- vt191-build サブパッケージには、以下の依存関係セットがあります。
Requires: %{scl_prefix_python}scldevel
これは、たとえば python27-scldevel などに展開されます。この依存関係の目的は、vt191 Software Collection のパッケージを構築する際にマクロが常に存在することを確認することです。 - vt191 Software Collection の
enable
スクリプトレットは、以下の行を使用します。. scl_source enable %{scl_python}
行の先頭にあるドットに注意してください。この行では、vt191 Software Collection が起動すると、Python Software Collection が暗黙的に起動されます。これにより、ユーザーは scl enable python27 vt191 command のかわりに、scl enable vt191 command のみを入力して、Software Collection 環境で command を実行できます。 - マクロファイル
macros.vt191-config
は、%__os_install_post
、Python 依存関係ジェネレーター、および他のパッケージの spec ファイルで使用される特定の Python 固有のマクロを適切に上書きする%scl_package_override
を呼び出します。
# define name of the scl %global scl vt191 %scl_package %scl # Defaults for the values for the python27/rh-python35 Software Collection. These # will be used when python27-scldevel (or rh-python35-scldevel) is not in the # build root %{!?scl_python:%global scl_python python27} %{!?scl_no_vendor:%global scl_no_vendor python27} %{!?scl_prefix_python:%global scl_prefix_python %{scl_python}-} # Only for this build, you need to override default __os_install_post, # because the default one would find /opt/.../lib/python2.7/ and try # to bytecompile with the system /usr/bin/python2.7 %global __os_install_post %{%{scl_no_vendor}_os_install_post} # Similarly, override __python_requires for automatic dependency generator %global __python_requires %{%{scl_no_vendor}_python_requires} # The directory for site packages for this Software Collection %global vt191_sitelib %(echo %{python27python_sitelib} | sed 's|%{scl_python}|%{scl}|') Summary: Package that installs %scl Name: %scl_name Version: 1 Release: 1%{?dist} License: GPLv2+ BuildRequires: scl-utils-build # Always make sure that there is the python27-sclbuild (or rh-python35-sclbuild) # package in the build root BuildRequires: %{scl_prefix_python}scldevel # Require python27-python-devel, you will need macros from that package BuildRequires: %{scl_prefix_python}python-devel Requires: %{scl_prefix}python-versiontools %description This is the main package for %scl Software Collection. %package runtime Summary: Package that handles %scl Software Collection. Requires: scl-utils Requires: %{scl_prefix_python}runtime %description runtime Package shipping essential scripts to work with %scl Software Collection. %package build Summary: Package shipping basic build configuration Requires: scl-utils-build # Require python27-scldevel (or rh-python35-scldevel) so that there is always access # to the %%scl_python and %%scl_prefix_python macros in builds for this Software # Collection Requires: %{scl_prefix_python}scldevel %description build Package shipping essential configuration macros to build %scl Software Collection. %prep %setup -c -T %install %scl_install # Create the enable scriptlet that: # - Adds an additional load path for the Python interpreter. # - Runs scl_source so that you can run: # scl enable vt191 "bash" # instead of: # scl enable python27 vt191 "bash" cat >> %{buildroot}%{_scl_scripts}/enable << EOF . scl_source enable %{scl_python} export PYTHONPATH="%{vt191_sitelib}\${PYTHONPATH:+:\${PYTHONPATH}}" EOF mkdir -p %{buildroot}%{vt191_sitelib} # - Enable Software Collection-specific bytecompilation macros from # the python27-python-devel package. # - Also override the %%python_sitelib macro to point to the vt191 Software # Collection. # - If you have architecture-dependent packages, you will also need to override # the %%python_sitearch macro. cat >> %{buildroot}%{_root_sysconfdir}/rpm/macros.%{scl}-config << EOF %%scl_package_override() %%{expand:%{?python27_os_install_post:%%global __os_install_post %%python27_os_install_post} %%global __python_requires %%python27_python_requires %%global __python_provides %%python27_python_provides %%global __python %python27__python %%global python_sitelib %vt191_sitelib %%global python2_sitelib %vt191_sitelib } EOF %files %files runtime -f filelist %scl_files %vt191_sitelib %files build %{_root_sysconfdir}/rpm/macros.%{scl}-config %changelog * Wed Jan 22 2014 John Doe <jdoe@example.com> - 1-1 - Initial package.
4.2.2. python-versiontools パッケージ
以下は、python-versiontools パッケージの spec ファイルのコメントされた例です。spec ファイルでは、以下の点に注意してください。
BuildRequires
タグの接頭辞は、%{scl_prefix}
ではなく、%{?scl_prefix_python}
になります。%install
セクションは、--install-purelib
を明示的に指定します。
%{?scl:%scl_package python-versiontools} %{!?scl:%global pkg_name %{name}} %global pypi_name versiontools Name: %{?scl_prefix}python-versiontools Version: 1.9.1 Release: 1%{?dist} Summary: Smart replacement for plain tuple used in __version__ License: LGPLv3 URL: https://launchpad.net/versiontools Source0: http://pypi.python.org/packages/source/v/versiontools/versiontools-1.9.1.tar.gz BuildArch: noarch BuildRequires: %{?scl_prefix_python}python-devel BuildRequires: %{?scl_prefix_python}python-setuptools %{?scl:BuildRequires: %{scl}-build %{scl}-runtime} %{?scl:Requires: %{scl}-runtime} %description Smart replacement for plain tuple used in __version__ %prep %setup -q -n %{pypi_name}-%{version} %build %{?scl:scl enable %{scl} "} %{__python} setup.py build %{?scl:"} %install # Explicitly specify --install-purelib %{python_sitelib}, which is now overriden # to point to vt191, otherwise Python will try to install into the python27 # Software Collection site-packages directory %{?scl:scl enable %{scl} "} %{__python} setup.py install -O1 --skip-build --root %{buildroot} --install-purelib %{python_sitelib} %{?scl:"} %files %{python_sitelib}/%{pypi_name}* %changelog * Wed Jan 22 2014 John Doe <jdoe@example.com> - 1.9.1-1 - Built for vt191 SCL.
4.2.3. vt191 Software Collection の構築
vt191 Software Collection を構築するには、以下を実行します。
- python27 Software Collection に含まれる python27-scldevel サブパッケージおよび python27-python-devel サブパッケージをインストールします。
vt191.spec
を構築して、vt191-runtime パッケージおよび vt191-build パッケージをインストールします。- versiontools のビルド要件である python27-python-setuptools パッケージをインストールします。
python-versiontools.spec
をビルドします。
4.2.4. vt191 Software Collection のテスト
vt191 Software Collection をテストするには、以下を実行します。
- vt191-python-versiontools パッケージをインストールします。
- 次のコマンドを実行します。
$
scl enable vt191 "python -c 'import versiontools; print(versiontools.__file__)'"
- 出力に以下の行が含まれることを確認します。
/opt/rh/vt191/root/usr/lib/python2.7/site-packages/versiontools/__init__.pyc
パスのプロバイダーrh
は、%_scl_prefix
マクロの再定義により異なる可能性があることに注意してください。詳細は、「Software Collection Root ディレクトリー」 を参照してください。