跳转到: 导航, 搜索

Rpm-packaging/ContentStyle

代码风格定义

代码应该以常见的方式编写,并且易于阅读。

Head

  • 所有 %global 变量必须在最开始声明
  • 名称: 值,在 py2name 上下文函数中使用时,必须等于 pypi 名称!
  • 版本: 值几乎等于 git 标签。对于包含 dev、alpha、beta、rc 等的版本,应使用 波浪号=~ 作为数值版本部分的定界符。

缩进

  • 水平缩进 - 值应紧跟 BuildRequires: 之后,并缩进 2 个空格。
  • 垂直缩进 - 所有逻辑块,如 %pre, %build, %install, %files 等,应使用 1 个空行分隔。

示例

%global sname py_name
Name:           {{ py2name('py_name') }}
Version:        X.Y.Z
Release:        0
Summary:        A for .... functionality for OpenStack projects
License:        {{ 'Apache-2.0' | license }}
Group:          Development/Languages/Python
Url:            http://www.homepage.org/
Source:         https://pypi.io/packages/source/o/%{sname}/%{sname}-%{version}.tar.gz
BuildRequires:  openstack-macros
BuildRequires:  {{ py2pkg('devel') }}
BuildRequires:  {{ py2pkg('build_req0') }}
BuildRequires:  {{ py2pkg('build_req1') }}
Requires:       {{ py2pkg('runtume_req0') }}
Requires:       {{ py2pkg('runtume_req1') }}
BuildArch:      noarch

%description
A py_name ......... for OpenStack projects
* Documentation: https://docs.openstack.org/developer/py_name
* Source: http://git.openstack.org/cgit/openstack/py_name
* Bugs: http://bugs.launchpad.net/py_name

%package doc
Summary:        Documentation for the py_name
Group:          Documentation
BuildRequires:  {{ py2pkg('doc builld req0') }}
BuildRequires:  {{ py2pkg('doc builld req0') }}
Requires:       %{name} = ${version}

%description doc
Documentation for py_name .........

%prep
%setup -q -n %{sname}-%{version}

%build
%{__python2} setup.py build
# generate html docs
%{__python2} setup.py build_sphinx
# remove the sphinx-build leftovers
rm -rf doc/build/html/.{doctrees,buildinfo}

%install
%{__python2} setup.py install --prefix=%{_prefix} --root=%{buildroot}

%check
export PATH="$PATH:%{buildroot}/%{_bindir}"
export PYTHONPATH="%{python2_sitearch}:%{python2_sitelib}:%{buildroot}%{python2_sitelib}"
%{__python2} setup.py testr

%files
%defattr(-,root,root,-)
%license LICENSE
%doc README.rst ChangeLog
%{_bindir}/py_name_cli
%{python2_sitelib}/py_name
%{python2_sitelib}/py_name*egg-info

%files doc
%license LICENSE
%doc doc/build/html

%changelog