Skip to main content

pyp2spec

This project is a thought descendant of specfile_generator.

It generates working Fedora RPM spec file for Python projects. The produced spec files must be compliant with the current Python Packaging Guidelines (in effect since 2021). It utilizes the benefits of pyproject-rpm-macros.

This project's maturity state is alpha. Its API may be a subject of change.

What it does

pyp2spec gathers all the necessary information from PyPI to produce a valid Fedora spec file and stores it in the current directory alongside with the config file used to produce the spec file.

Inside, there are two parts:

  • pyp2conf: gathers of all the necessary information to produce a spec file and stores it in a configuration file
  • conf2spec: produces working spec file using all the information from configuration file

How to run

To run whatever this project offers at this point, install package pyp2spec from PyPI with the command:

pip install pyp2spec

Then you can run:

pyp2spec <pypi_package_name>

or those two commands which will together produce the same result as pyp2spec:

pyp2conf <pypi_package_name>
conf2spec <config_file>

To see all available command-line options, run --help with the respective commands.

Development

Alternatively, you can clone the project from GitHub and install the dependencies to you virtual environment:

python -m pip install -r requirements.txt

To run the script and generate both the config and spec file, type:

python -m pyp2spec.pyp2spec <pypi_package_name>

You can run either of the tools separately to generate partial results:

python -m pyp2spec.pyp2conf <pypi_package_name>
python -m pyp2spec.conf2spec <config_file>

Tests

To run the tests, run tox:

tox

You can install tox from your OS repository or PyPI. Test dependencies are defined in the project's [test] extra.

Configuration file specification

Configuration data is stored in a TOML file.

Mandatory fields

  • Generated by pyp2conf
Field Description Type
pypi_name package name as stored in PyPI string
python_name pypi_name prepended with python- and alternative Python version, if python_alt_version is defined string
archive_name source tarball name, stripped of version and file extension string
version package version to create spec file for (RPM format) string
pypi_version package version string as in PyPI, '%{version}' if the same as version string
summary short package summary string
license license name string
url project URL string
source %{pypi_source} macro with optional arguments (tarball URL can be used instead) string
description long package description multiline string
extras extra subpackages names list of strings
archful package contains compiled extensions, implies not using BuildArch: noarch and adding BuildRequires: gcc bool
python_alt_version specific Python version to create the spec file for, e.g. 3.9, 3.10, 3.12 string

Optional fields

  • Not generated by pyp2conf
  • Can be also added to config files generated by pyp2conf
Field Description Type
test_method pytest, tox string
test_top_level filter and test only top-level modules in %check bool
unwanted_tests test names to skip with pytest list
binary_files list binary files from the package list
license_files list license files from the package list
doc_files list doc files from the package list

Example config file generated by pyp2spec

description = "This is package 'aionotion' generated automatically by pyp2spec."
summary = "A simple Python 3 library for Notion Home Monitoring"
version = "2.0.3"
license = "MIT"
pypi_name = "aionotion"
pypi_version = %{version}
python_name = "python-aionotion"
url = "https://github.com/bachya/aionotion"
source = "%{pypi_source aionotion}"
archive_name = "aionotion"
extras = []
archful = false

Spec file generated using the example config

Name:           python-aionotion
Version:        3.0.2
Release:        %autorelease
Summary:        A simple Python 3 library for Notion Home Monitoring

# Check if the automatically generated License and its spelling is correct for Fedora
# https://docs.fedoraproject.org/en-US/packaging-guidelines/LicensingGuidelines/
License:        MIT
URL:            https://github.com/bachya/aionotion
Source:         %{pypi_source aionotion}

BuildArch:      noarch
BuildRequires:  python3-devel

%global _description %{expand:
This is package 'aionotion' generated automatically by pyp2spec.}


%description %_description

%package -n     python3-aionotion
Summary:        %{summary}

%description -n python3-aionotion %_description


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


%generate_buildrequires
%pyproject_buildrequires


%build
%pyproject_wheel


%install
%pyproject_install
# For official Fedora packages, including files with '*' +auto is not allowed
# Replace it with a list of relevant Python modules/globs and list extra files in %%files
%pyproject_save_files '*' +auto


%check
%pyproject_check_import


%files -n python3-aionotion -f %{pyproject_files}


%changelog
%autochangelog

License

The code is licensed under MIT.

The spec file template - template.spec and the files generated by the tool are licensed under MIT-0 (No Attribution).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyp2spec-0.9.0.tar.gz (217.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyp2spec-0.9.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file pyp2spec-0.9.0.tar.gz.

File metadata

  • Download URL: pyp2spec-0.9.0.tar.gz
  • Upload date:
  • Size: 217.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for pyp2spec-0.9.0.tar.gz
Algorithm Hash digest
SHA256 952785d4950cff5e20010ebd22175bf27e3467e565431fd80587c8b96c361842
MD5 709d37681db6539b13000f9392309fe9
BLAKE2b-256 ca858fa0c0ea0b03e04cda8aa8d7edf16fe132a9a401e6434eb612268f2419ff

See more details on using hashes here.

File details

Details for the file pyp2spec-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: pyp2spec-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for pyp2spec-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3221e3135ab2fb9b729092c3086e35c1323dbf3a6488ec177cd7b717a99cad00
MD5 8f9afbfcebad9dbd3a435748a03305f9
BLAKE2b-256 e19f49941012dd232e73f85a518619612350482271168a8565c167f3baa33e67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page