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,包含 版本tools Python 软件包 1.9.1。
请注意 vt191 Software Collection metapackage 中的以下内容:
- vt191 Software Collection metapackage 设置了以下构建依赖项:
BuildRequires: %{scl_prefix_python}scldevel例如,这扩展至 python27-scldevel。python27-scldevel 子软件包提供了两个重要的宏%scl_python和%scl_prefix_python。请注意,这些宏在 metapackage spec 文件的顶部定义。虽然定义不是必需的,但它们提供了一个可视化提示,但 vt191 软件集合已设计为基于 python27 Software Collection 构建。它们也充当回退值。 - 要正确设置
site-packages目录,请使用%python27python_sitelib宏的值,并将python27替换为vt191。请注意,如果您使用其他提供程序构建 Software Collection (例如/opt/myorganization/而不是/opt/rh/),则需要更改它们。重要由于/opt/rh/供应商用于安装红帽提供的 Software Collections,因此强烈建议使用不同的供应商来避免可能的冲突。请参阅 第 2.3 节 “Software Collection Root 目录” 了解更多信息。 - vt191-build 子软件包设置了以下依赖项:
Requires: %{scl_prefix_python}scldevel例如,这扩展至 python27-scldevel。这种依赖项的目的是确保在为 vt191 软件集合构建软件包时始终存在宏。 - vt191 Software Collection 的
enablescriptlet 使用以下行:. scl_source enable %{scl_python}请注意行开头的点。当 vt191 Software Collection 启动时,此行使 Python Software Collection 会隐式启动,以便用户只能键入 scl enable vt191 命令而不是 scl enable python27 vt191 命令在 Software Collection 环境中运行命令。 - 宏文件
macros.vt191-config调用%scl_package_override功能来正确覆盖%__os_install_post、、Python 依赖项生成器,以及其它软件包规格文件中使用的特定于 Python 的宏。
# 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_python}而不是%{scl_prefix}。%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 软件包。 - 安装 python27-python-setuptools 软件包,这是 版本tools 的构建要求。
- 构建
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