5.4.4. 使用 Python 编写的程序的 spec 文件示例


您可以将以下示例 spec 文件用于使用 Python 编程语言编写的 pello 程序供您参考。

使用 Python 编写的程序的 spec 文件示例

%global python3_pkgversion 3.12                                       
1


Name:           python-pello                                          
2

Version:        1.0.2
Release:        1%{?dist}
Summary:        Example Python library

License:        MIT
URL:            https://github.com/fedora-python/Pello
Source:         %{url}/archive/v%{version}/Pello-%{version}.tar.gz

BuildArch:      noarch
BuildRequires:  python%{python3_pkgversion}-devel                     
3


# Build dependencies needed to be specified manually
BuildRequires:  python%{python3_pkgversion}-setuptools

# Test dependencies needed to be specified manually
# Also runtime dependencies need to be BuildRequired manually to run tests during build
BuildRequires:  python%{python3_pkgversion}-pytest >= 3


%global _description %{expand:
Pello is an example package with an executable that prints Hello World! on the command line.}

%description %_description

%package -n python%{python3_pkgversion}-pello                         
4

Summary:        %{summary}

%description -n python%{python3_pkgversion}-pello %_description


%prep
%autosetup -p1 -n Pello-%{version}


%build
# The macro only supported projects with setup.py
%py3_build                                                            
5



%install
# The macro only supported projects with setup.py
%py3_install


%check                                                                
6

%{pytest}


# Note that there is no %%files section for the unversioned python module
%files -n python%{python3_pkgversion}-pello
%doc README.md
%license LICENSE.txt
%{_bindir}/pello_greeting

# The library files needed to be listed manually
%{python3_sitelib}/pello/

# The metadata files needed to be listed manually
%{python3_sitelib}/Pello-*.egg-info/

%changelog
* Tue May 31 2016 Adam Miller <maxamillion@fedoraproject.org> - 1.0.2-1
- First pello package

1
通过定义 python3_pkgversion 宏,您可以设置将为哪个 Python 版本构建此软件包。要为默认的 Python 版本 3.9 构建,请将宏设置为默认值 3 或完全删除行。
2
将 Python 项目打包到 RPM 中时,需要将 python- 前缀添加到项目的原始名称中。这里原始名称为 pello,因此源 RPM (SRPM)的名称是 python-pello
3
BuildRequires 指令指定需要哪些软件包来构建和测试此软件包。在 BuildRequires 中,始终包括提供构建 Python 软件包所需的工具: python3-devel (或 python3.11-develpython3.12-devel)以及您软件包的特定软件所需的相关软件包,如 python3-setuptools (或 python3.11-setuptoolspython3.12-setuptools)或运行 %check 部分中测试所需的运行时和测试依赖项。
4
当为二进制 RPM 选择名称(用户必须安装的软件包)时,请添加版本化的 Python 前缀。对默认的 Python 3.9 使用 python3- 前缀,对Python 3.11 使用 python3.11- 前缀或对 Python 3.12 使用 python3.12- 前缀。您可以使用 %{python3_pkgversion} 宏,它针对默认的 Python 版本 3.9 评估为 3,除非您将其设置为显式版本,例如 3.11 (请参阅脚注 1)。
5
%py3_build%py3_install 宏会分别运行 setup.py buildsetup.py install 命令,使用附加参数来指定安装位置、要使用的解释器以及其他详情。
6
%check 部分应该运行打包项目的测试。确切的命令取决于项目本身,但可以使用 %pytest 宏,以 RPM 友好的方式运行 pytest 命令。
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部