Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ nosetests.xml
*.egg-info
.venv*
.tox
.eggs
.eggs
*.orig

180 changes: 163 additions & 17 deletions py2pack/templates/fedora.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,205 @@
# Copyright (c) {{ year }} {{ user_name }}.
#

Name: python-{{ name }}
# python3_pkgversion macro for EPEL in older RHEL
%{!?python3_pkgversion:%global python3_pkgversion 3}

# Fedora and RHEL split python2 and python3
# Older RHEL requires EPEL and python34 or python36
%global with_python3 1

# Fedora >= 38 no longer publishes python2 by default
%if 0%{?fedora} >= 30
%global with_python2 0
%else
%global with_python2 1
%endif

# Older RHEL does not use dnf, does not support "Suggests"
%if 0%{?fedora} || 0%{?rhel} > 7
%global with_dnf 1
%else
%global with_dnf 0
%endif

%global pypi_name {{ name }}

# Descriptions can get long and clutter .spec file
%global common_description %{expand:
{{ description }}
}

# Common SRPM package
Name: python-%{pypi_name}
Version: {{ version }}
Release: 0
Release: 0%{?dist}
Url: {{ home_page }}
Summary: {{ summary }}
License: {{ license }}
Group: Development/Languages/Python
Source: {{ source_url|replace(version, '%{version}') }}
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: python-devel {%- if requires_python %} = {{ requires_python }} {% endif %}
# Stop using py2pack macros, use local macros published by Fedora
Source0: https://files.pythonhosted.org/packages/source/%(n=%{pypi_name}; echo ${n:0:1})/%{pypi_name}/%{pypi_name}-%{version}.tar.gz
{%- if not has_ext_modules %}
BuildArch: noarch
{%- endif %}

%description
{{ description }}

%if %{with_python2}
%package -n python2-%{pypi_name}
Version: {{ version }}
Release: 0%{?dist}
Url: {{ home_page }}
Summary: {{ summary }}
License: {{ license }}

BuildRequires: python2-devel
BuildRequires: python2-setuptools
# requires stanza of py2pack
{%- for req in requires %}
BuildRequires: python-{{ req|replace('(','')|replace(')','') }}
Requires: python-{{ req|replace('(','')|replace(')','') }}
BuildRequires: python2-{{ req|replace('(','')|replace(')','') }}
Requires: python2-{{ req|replace('(','')|replace(')','') }}
{%- endfor %}
# install_requires stanza of py2pack
{%- for req in install_requires %}
BuildRequires: python-{{ req|replace('(','')|replace(')','') }}
Requires: python-{{ req|replace('(','')|replace(')','') }}
BuildRequires: python2-{{ req|replace('(','')|replace(')','') }}
Requires: python2-{{ req|replace('(','')|replace(')','') }}
{%- endfor %}
%if %{with_dnf}
{%- if extras_require %}
{%- for reqlist in extras_require.values() %}
{%- for req in reqlist %}
Suggests: python-{{ req|replace('(','')|replace(')','') }}
Suggests: python2-{{ req|replace('(','')|replace(')','') }}
{%- endfor %}
{%- endfor %}
{%- endif %}
%endif # with_dnf
%{?python_provide:%python_provide python2-%{pypi_name}}

%description
%description -n python2-%{pypi_name}
{{ description }}

%endif # with_python2

%if %{with_python3}
%package -n python%{python3_pkgversion}-%{pypi_name}
Version: {{ version }}
Release: 0%{?dist}
Url: {{ home_page }}
Summary: {{ summary }}
License: {{ license }}

# requires stanza of py2pack
{%- for req in requires %}
BuildRequires: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }}
Requires: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }}
{%- endfor %}
# install_requires stanza of py2pack
{%- for req in install_requires %}
BuildRequires: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }}
Requires: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }}
{%- endfor %}
%if %{with_dnf}
{%- if extras_require %}
{%- for reqlist in extras_require.values() %}
{%- for req in reqlist %}
Suggests: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }}
{%- endfor %}
{%- endfor %}
{%- endif %}
%endif # with_dnf
%{?python_provide:%python_provide python%{python3_pkgversion}-%{pypi_name}}

%description -n python%{python3_pkgversion}-%{pypi_name}
{{ description }}

%endif # with_python3

%prep
%setup -q -n {{ name }}-%{version}
%setup -q -n %{pypi_name}-%{version}

%build
{%- if is_extension %}
export CFLAGS="%{optflags}"
{%- endif %}
python setup.py build
%if %{with_python2}
%py2_build
%endif # with_python2

%if %{with_python3}
%py3_build
%endif # with_python3

%install
python setup.py install --prefix=%{_prefix} --root=%{buildroot}
%if %{with_python2}
%py2_install
{%- if scripts %}
{%- for script in scripts %}
%{__mv} $RPM_BUILD_ROOT%{_bindir}/{{ script }} $RPM_BUILD_ROOT%{_bindir}/{{ script }}-%{python2_version}
{%- endfor %}

%if ! %{with_python3}
{%- for script in scripts %}
%{__ln_s} {{ script }}-%{python2_version} $RPM_BUILD_ROOT%{_bindir}/{{ script }}
{%- endfor %}
%endif # ! with_python3
{%- endif %}
%endif # with_python2

%if %{with_python3}
%py3_install
{%- for script in scripts %}
%{__mv} $RPM_BUILD_ROOT%{_bindir}/{{ script }} $RPM_BUILD_ROOT%{_bindir}/{{ script }}-%{python3_version}
%{__ln_s} {{ script }}-%{python3_version} $RPM_BUILD_ROOT%{_bindir}/{{ script }}
{%- endfor %}
%endif # with_python3

%clean
rm -rf %{buildroot}

%files
%if %{with_python2}
%files -n python2-%{pypi_name}
%defattr(-,root,root,-)
{%- if doc_files %}
%doc {{ doc_files|join(" ") }}
{%- endif %}
{%- for script in scripts %}
%{_bindir}/{{ script }}-%{python2_version}
{%- endfor %}
{%- if is_extension %}

%if ! %{with_python3}
# Symlinks for binaries to script-2, only if with_python3 is not enabled
{%- for script in scripts %}
%{_bindir}/{{ script }}
{%- endfor %}
%endif # with_python3
%{python2_archlib}/*
{%- endif %}
{%- if not is_extension %}
%{python2_sitelib}/*
{%- endif %}
%endif # with_python2

%if %{with_python3}
%files -n python%{python3_pkgversion}-%{pypi_name}
%defattr(-,root,root,-)
{%- if doc_files %}
%doc {{ doc_files|join(" ") }}
{%- endif %}
{%- for script in scripts %}
%{_bindir}/{{ script }}-%{python3_version}
{%- endfor %}
{%- for script in scripts %}
%{_bindir}/{{ script }}
{%- endfor %}
%{python_sitelib}/*
{%- if is_extension %}
%{python3_archlib}/*
{%- endif %}
{%- if not is_extension %}
%{python3_sitelib}/*
{%- endif %}
%endif # with_python3

%changelog

Loading