4.5.4. Python 程序示例的 spec 文件示例


您可以对使用 Python 编程语言编写的 pello 程序使用以下示例 spec 文件作为参考。

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

Name:           pello
Version:        0.1.1
Release:        1%{?dist}
Summary:        Hello World example implemented in Python

License:        GPLv3+
URL:            https://www.example.com/%{name}
Source0:        https://www.example.com/%{name}/releases/%{name}-%{version}.tar.gz

BuildRequires:  python
Requires:       python
Requires:       bash

BuildArch:      noarch

%description
The long-tail description for our Hello World Example implemented in Python.

%prep
%setup -q

%build

python -m compileall %{name}.py

%install

mkdir -p %{buildroot}/%{_bindir}
mkdir -p %{buildroot}/usr/lib/%{name}

cat > %{buildroot}/%{_bindir}/%{name} <<EOF
#!/bin/bash
/usr/bin/python /usr/lib/%{name}/%{name}.pyc
EOF

chmod 0755 %{buildroot}/%{_bindir}/%{name}

install -m 0644 %{name}.py* %{buildroot}/usr/lib/%{name}/

%files
%license LICENSE
%dir /usr/lib/%{name}/
%{_bindir}/%{name}
/usr/lib/%{name}/%{name}.py*

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

  • Requires 指令指定软件包的运行时依赖项,其中包括两个软件包:

    • python 软件包需要在运行时执行字节编译的代码。
    • bash 软件包需要执行小入口点脚本。
  • BuildRequires 指令指定软件包的 build-time 依赖项,它只包括 python 软件包。pello 程序需要 python 来执行字节编译构建过程。
  • %build 部分指定如何构建软件,创建脚本的字节编译版本。请注意,在实际打包中,它通常会根据所使用的发行版自动完成。
  • %install 部分对应于这样的事实,即您必须将字节文件安装到系统上的库目录中,以便可以访问它。

spec 文件中内联创建包装程序脚本的示例表明 spec 文件本身是可以写成脚本的。此打包程序脚本使用 此文档 执行 Python 字节编译的代码。

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部