4 步打包一个新的 Python 模块( 二 )

%package -n python3-%{pypi_name}
 

  •  
    Summary: %{summary}
     
  •  
    %{?python_provide:%python_provide python3-%{pypi_name}}
     
  •  
     
  •  
    Requires: (python3dist(hug) >= 2.6.1 with python3dist(hug) < 3~~)
     
  •  
    Requires: python3dist(setuptools)
     
  •  
    %description -n python3-%{pypi_name}
     
  •  
    Concentration [![PyPI version]( [![Test Status]( [![Lint Status]( [![codecov](
     
  •  
     
  •  
     
  •  
    %prep
     
  •  
    %autosetup -n %{pypi_name}-%{pypi_version}
     
  •  
     
  •  
    %build
     
  •  
    %py3_build
     
  •  
     
  •  
    %install
     
  •  
    %py3_install
     
  •  
     
  •  
    %files -n python3-%{pypi_name}
     
  •  
    %license LICENSE
     
  •  
    %doc README.md
     
  •  
    %{_bindir}/concentration
     
  •  
    %{python3_sitelib}/%{pypi_name}
     
  •  
    %{python3_sitelib}/%{pypi_name}-%{pypi_version}-py%{python3_version}.egg-info
     
  •  
     
  •  
    %changelog
     
  •  
    * - 1.1.5-1
     
  •  
    - Initial package.
     
  •  
    2、运行 rpmlint
    为了确保 spec 文件符合标准,你需要对文件使用rpmlint命令:
     
    1.  
      $ rpmlint ~/rpmbuild/SPEC/concentration.spec
       
    2.  
      error: bad date in %changelog: - 1.1.5-1
       
    3.  
      0 packages and 1 specfiles checked; 0 errors, 0 warnings.
       
     
    看起来更新日志(%changelog)需要记录日期 。
     
    1.  
      %changelog
       
    2.  
      * Sat Jun 11 2022 Tux - 1.1.5-1
       
     
    再次运行rpmint
     
    1.  
      $ rpmlint ~/rpmbuild/SPEC/concentration.spec
       
    2.  
      0 packages and 1 specfiles checked; 0 errors, 0 warnings.
       
     
    成功!
    3、下载源码
    你需要下载好打包的代码才能进一步构建 RPM 包 。一种简单的方式是解析你的 spec 文件以获取源码的网址 。
    首先,通过dnf安装spectool
     
    1.  
      $ sudo dnf install spectool
       
     
    然后通过spectool来下载源码:
     
    1.  
      $ cd ~/rpmbuild
       
    2.  
      $ spectool -g -R SPEC/concentration.spec
       
    3.  
      Downloading: https://files.pythonhosted.org/...concentration-1.1.5.tar.gz
       
    4.  
      6.0 KiB / 6.0 KiB [=====================================]
       
    5.  
      Downloaded: concentration-1.1.5.tar.gz
       
     
    这样就创建了一个SOURCES目录并将源码放入其中 。
    4、构建源软件包
    现在你已经验证过 spec 文件了,接下来就可以通过


    推荐阅读