From aa6aca4e6522d6cd7f2d50d23b71f3dbdfbd5b54 Mon Sep 17 00:00:00 2001 From: nkadel Date: Sat, 21 Jul 2018 10:09:46 -0400 Subject: [PATCH 01/23] Add el.spec template, for RHEL and CentOS --- py2pack/templates/el.spec | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 py2pack/templates/el.spec diff --git a/py2pack/templates/el.spec b/py2pack/templates/el.spec new file mode 100644 index 0000000..af2cce9 --- /dev/null +++ b/py2pack/templates/el.spec @@ -0,0 +1,62 @@ +# +# spec file for package python-{{ name }} +# +# Copyright (c) {{ year }} {{ user_name }}. +# + +Name: python-{{ name }} +Version: {{ version }} +Release: 0 +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 %} +{%- for req in requires %} +BuildRequires: python-{{ req|replace('(','')|replace(')','') }} +Requires: python-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +{%- for req in install_requires %} +BuildRequires: python-{{ req|replace('(','')|replace(')','') }} +Requires: python-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +{%- if extras_require %} +{%- for reqlist in extras_require.values() %} +{%- for req in reqlist %} +Suggests: python-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +{%- endfor %} +{%- endif %} + +%description +{{ description }} + +%prep +%setup -q -n {{ name }}-%{version} + +%build +{%- if is_extension %} +export CFLAGS="%{optflags}" +{%- endif %} +python setup.py build + +%install +python setup.py install --prefix=%{_prefix} --root=%{buildroot} + +%clean +rm -rf %{buildroot} + +%files +%defattr(-,root,root,-) +{%- if doc_files %} +%doc {{ doc_files|join(" ") }} +{%- endif %} +{%- for script in scripts %} +%{_bindir}/{{ script }} +{%- endfor %} +%{python_sitelib}/* + +%changelog + From 7c2bcff895ff9484e68738b0bfc6028fe45534d6 Mon Sep 17 00:00:00 2001 From: nkadel Date: Sat, 21 Jul 2018 10:11:56 -0400 Subject: [PATCH 02/23] Add template for "el", or CentOS or RHEL, .spec files --- test/examples/py2pack-el.spec | 170 ++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 test/examples/py2pack-el.spec diff --git a/test/examples/py2pack-el.spec b/test/examples/py2pack-el.spec new file mode 100644 index 0000000..73a93e3 --- /dev/null +++ b/test/examples/py2pack-el.spec @@ -0,0 +1,170 @@ +# +# spec file for package python-py2pack +# +# Copyright (c) 2018 __USER__. +# + +Name: python-py2pack +Version: 0.8.0 +Release: 0 +Url: http://github.com/openSUSE/py2pack +Summary: Generate distribution packages from PyPI +License: Apache-2.0 +Group: Development/Languages/Python +Source: https://files.pythonhosted.org/packages/source/p/py2pack/py2pack-%{version}.tar.gz +BuildRoot: %{_tmppath}/%{name}-%{version}-build +BuildRequires: python-devel + +%description +Py2pack: Generate distribution packages from PyPI +================================================= + +.. image:: https://travis-ci.org/openSUSE/py2pack.png?branch=master + :target: https://travis-ci.org/openSUSE/py2pack + + +This script allows to generate RPM spec or DEB dsc files from Python modules. +It allows to list Python modules or search for them on the Python Package Index +(PyPI). Conveniently, it can fetch tarballs and changelogs making it an +universal tool to package Python modules. + + +Installation +------------ + +To install py2pack from the `Python Package Index`_, simply: + +.. code-block:: bash + + $ pip install py2pack + +Or, if you absolutely must: + +.. code-block:: bash + + $ easy_install py2pack + +But, you really shouldn't do that. Lastly, you can check your distro of choice +if they provide packages. For openSUSE, you can find packages in the `Open +Build Service`_ for all releases. If you happen to use openSUSE:Factory (the +rolling release / development version), simply: + +.. code-block:: bash + + $ sudo zypper install python-py2pack + + +Usage +----- + +Lets suppose you want to package zope.interface_ and you don't know how it is named +exactly. First of all, you can search for it and download the source tarball if +you found the correct module: + +.. code-block:: bash + + $ py2pack search zope.interface + searching for module zope.interface... + found zope.interface-3.6.1 + $ py2pack fetch zope.interface + downloading package zope.interface-3.6.1... + from http://pypi.python.org/packages/source/z/zope.interface/zope.interface-3.6.1.tar.gz + + +As a next step you may want to generate a package recipe for your distribution. +For RPM_-based distributions (let's use openSUSE_ as an example), you want to +generate a spec file (named 'python-zope.interface.spec'): + +.. code-block:: bash + + $ py2pack generate zope.interface -t opensuse.spec -f python-zope.interface.spec + +The source tarball and the package recipe is all you need to generate the RPM_ +(or DEB_) file. +This final step may depend on which distribution you use. Again, +for openSUSE_ (and by using the `Open Build Service`_), the complete recipe is: + +.. code-block:: bash + + $ osc mkpac python-zope.interface + $ cd python-zope.interface + $ py2pack fetch zope.interface + $ py2pack generate zope.interface -f python-zope.interface.spec + $ osc build + ... + +Depending on the module, you may have to adapt the resulting spec file slightly. +To get further help about py2pack usage, issue the following command: + +.. code-block:: bash + + $ py2pack help + + +Hacking and contributing +------------------------ + +You can test py2pack from your git checkout by executing the py2pack module: + +.. code-block:: bash + + $ python -m py2pack + +Fork `the repository`_ on Github to start making your changes to the **master** +branch (or branch off of it). Don't forget to write a test for fixed issues or +implemented features whenever appropriate. You can invoke the testsuite from +the repository root directory via `tox`_: + +.. code-block:: bash + + $ tox + +To run a single test class via `tox`_, use i.e.: + +.. code-block:: bash + + $ tox -epy27 test.test_py2pack:Py2packTestCase + + +You can also run `nose`_ directly: + +.. code-block:: bash + + $ nosetests + +It assumes you have the test dependencies installed (available on PYTHONPATH) +on your system. + +:copyright: (c) 2013 Sascha Peilicke. +:license: Apache-2.0, see LICENSE for more details. + + +.. _argparse: http://pypi.python.org/pypi/argparse +.. _Jinja2: http://pypi.python.org/pypi/Jinja2 +.. _zope.interface: http://pypi.python.org/pypi/zope.interface/ +.. _openSUSE: http://www.opensuse.org/en/ +.. _RPM: http://en.wikipedia.org/wiki/RPM_Package_Manager +.. _DEB: http://en.wikipedia.org/wiki/Deb_(file_format) +.. _`Python Package Index`: https://pypi.python.org/pypi/rapport +.. _`Open Build Service`: https://build.opensuse.org/package/show?package=rapport&project=devel:languages:python +.. _`the repository`: https://github.com/openSUSE/py2pack +.. _`nose`: https://nose.readthedocs.org +.. _`tox`: http://testrun.org/tox + +%prep +%setup -q -n py2pack-%{version} + +%build +python setup.py build + +%install +python setup.py install --prefix=%{_prefix} --root=%{buildroot} + +%clean +rm -rf %{buildroot} + +%files +%defattr(-,root,root,-) +%{python_sitelib}/* + +%changelog From 5e931766ece1acd43db8a41e40ad3aa3fe4ee95e Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Thu, 11 Oct 2018 06:34:48 -0400 Subject: [PATCH 03/23] Activate with_python2 and with_python3 settings --- py2pack/templates/fedora.spec | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index af2cce9..4e228ed 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -4,6 +4,22 @@ # Copyright (c) {{ year }} {{ user_name }}. # +# Fedora and RHEL split python2 and python3 +# EPEL does not publish python3 by default +%if 0%{?fedora} || 0%{?rhel} > 7 +%global with_python3 1 +%else +%global with_python3 0 +%endif + +# Fedora > 28 no longer publishes python2 by default +%if 0%{?fedora} > 28 +%global with_python2 0 +%else +%global with_python2 1 +%endif + +# Common SRPM package Name: python-{{ name }} Version: {{ version }} Release: 0 From 9a20ac58f4f0f0f5fb677bc96a2a7655731c5e1f Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Thu, 11 Oct 2018 08:20:42 -0400 Subject: [PATCH 04/23] Disable Suggests unless dnf exists in fedora.spec --- py2pack/templates/fedora.spec | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index 4e228ed..c103f90 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -19,6 +19,13 @@ %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 + # Common SRPM package Name: python-{{ name }} Version: {{ version }} @@ -38,6 +45,7 @@ Requires: python-{{ req|replace('(','')|replace(')','') }} BuildRequires: python-{{ req|replace('(','')|replace(')','') }} Requires: python-{{ req|replace('(','')|replace(')','') }} {%- endfor %} +%if 0%{with_dnf} {%- if extras_require %} {%- for reqlist in extras_require.values() %} {%- for req in reqlist %} @@ -45,6 +53,7 @@ Suggests: python-{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- endfor %} {%- endif %} +%endif # with_dnf %description {{ description }} From a409d3dc96a2f23197e212b5c007acc1294b16b2 Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Thu, 11 Oct 2018 08:22:53 -0400 Subject: [PATCH 05/23] Enable split of python2 and python3 packages for RHEL and fedora --- py2pack/templates/fedora.spec | 112 ++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 11 deletions(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index c103f90..74a2fbe 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -5,7 +5,7 @@ # # Fedora and RHEL split python2 and python3 -# EPEL does not publish python3 by default +# Older RHEL does not include python3 by default %if 0%{?fedora} || 0%{?rhel} > 7 %global with_python3 1 %else @@ -36,28 +36,88 @@ 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 %} +%if 0%{?with_python2} +BuildRequires: python2-devel {%- if requires_python %} = {{ requires_python }} {% endif %} {%- for req in requires %} -BuildRequires: python-{{ req|replace('(','')|replace(')','') }} -Requires: python-{{ req|replace('(','')|replace(')','') }} +BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- for req in install_requires %} -BuildRequires: python-{{ req|replace('(','')|replace(')','') }} -Requires: python-{{ req|replace('(','')|replace(')','') }} +BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +%endif # with_python2 +%if 0%{?with_python3} +BuildRequires: python3-devel {%- if requires_python %} = {{ requires_python }} {% endif %} +{%- for req in requires %} +BuildRequires: python3-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +{%- for req in install_requires %} +BuildRequires: python3-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +%endif # with_python3 + +%if 0%{?with_python2} +%package -n python2-{{ name }} +Version: {{ version }} +Release: 0 +Url: {{ home_page }} +Summary: {{ summary }} +License: {{ license }} +{%- for req in requires %} +Requires: python20{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +{%- for req in install_requires %} +Requires: python20{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +%if 0%{with_dnf} +{%- if extras_require %} +{%- for reqlist in extras_require.values() %} +{%- for req in reqlist %} +Suggests: python2-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +{%- endfor %} +{%- endif %} +%endif # with_dnf +%{?python_provide:%python_provide python2-%{srcname}} +%endif # with_python2 + +%if 0%{?with_python3} +%package -n python3-{{ name }} +Version: {{ version }} +Release: 0 +Url: {{ home_page }} +Summary: {{ summary }} +License: {{ license }} +{%- for req in requires %} +Requires: python3-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +{%- for req in install_requires %} +Requires: python3-{{ req|replace('(','')|replace(')','') }} {%- endfor %} %if 0%{with_dnf} {%- if extras_require %} {%- for reqlist in extras_require.values() %} {%- for req in reqlist %} -Suggests: python-{{ req|replace('(','')|replace(')','') }} +Suggests: python3-{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- endfor %} {%- endif %} %endif # with_dnf +%{?python_provide:%python_provide python2-%{srcname}} +%endif # with_python3 %description {{ description }} +%if 0%{?with_python2} +%description -n python2-{{ name }} +{{ description }} +%endif # with_python2 + +%if 0%{?with_python3} +%description -n python3-{{ name }} +{{ description }} +%endif # with_python3 + %prep %setup -q -n {{ name }}-%{version} @@ -65,15 +125,44 @@ Suggests: python-{{ req|replace('(','')|replace(')','') }} {%- if is_extension %} export CFLAGS="%{optflags}" {%- endif %} -python setup.py build +%if 0%{?with_python2} +%py2_build +%endif # with_python2 +%if 0%{?with_python3} +%py2_build +%endif # with_python3 %install -python setup.py install --prefix=%{_prefix} --root=%{buildroot} +%if 0%{?with_python2} +%py2_install +{%- for script in scripts %} +%{__mv} $RPM_BUILD_ROOT%{_bindir}/${script} $RPM_BUILD_ROOT%{_bindir}/${script}2 +{%- endfor %} +%endif # with_python2 +%if 0%{?with_python3} +%py3_install +{%- for script in scripts %} +%{__mv} $RPM_BUILD_ROOT%{_bindir}/${script} $RPM_BUILD_ROOT%{_bindir}/${script}3 +{%- endfor %} +%endif # with_python3 %clean rm -rf %{buildroot} -%files +%if 0%{with_python2} +%files -n python2-{{ name }} +%defattr(-,root,root,-) +{%- if doc_files %} +%doc {{ doc_files|join(" ") }} +{%- endif %} +{%- for script in scripts %} +%{_bindir}/{{ script }} +{%- endfor %} +%{python2_sitelib}/* +%endif # with_python2 + +%if 0%{with_python3} +%files -n python3-{{ name }} %defattr(-,root,root,-) {%- if doc_files %} %doc {{ doc_files|join(" ") }} @@ -81,7 +170,8 @@ rm -rf %{buildroot} {%- for script in scripts %} %{_bindir}/{{ script }} {%- endfor %} -%{python_sitelib}/* +%{python3_sitelib}/* +%endif # with_python3 %changelog From 79a8d1c6d6066da0c6393f6fa07df58e75ad14a1 Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Thu, 11 Oct 2018 08:36:47 -0400 Subject: [PATCH 06/23] Discard el.spec file, simply use fedora.spec --- py2pack/templates/el.spec | 62 --------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 py2pack/templates/el.spec diff --git a/py2pack/templates/el.spec b/py2pack/templates/el.spec deleted file mode 100644 index af2cce9..0000000 --- a/py2pack/templates/el.spec +++ /dev/null @@ -1,62 +0,0 @@ -# -# spec file for package python-{{ name }} -# -# Copyright (c) {{ year }} {{ user_name }}. -# - -Name: python-{{ name }} -Version: {{ version }} -Release: 0 -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 %} -{%- for req in requires %} -BuildRequires: python-{{ req|replace('(','')|replace(')','') }} -Requires: python-{{ req|replace('(','')|replace(')','') }} -{%- endfor %} -{%- for req in install_requires %} -BuildRequires: python-{{ req|replace('(','')|replace(')','') }} -Requires: python-{{ req|replace('(','')|replace(')','') }} -{%- endfor %} -{%- if extras_require %} -{%- for reqlist in extras_require.values() %} -{%- for req in reqlist %} -Suggests: python-{{ req|replace('(','')|replace(')','') }} -{%- endfor %} -{%- endfor %} -{%- endif %} - -%description -{{ description }} - -%prep -%setup -q -n {{ name }}-%{version} - -%build -{%- if is_extension %} -export CFLAGS="%{optflags}" -{%- endif %} -python setup.py build - -%install -python setup.py install --prefix=%{_prefix} --root=%{buildroot} - -%clean -rm -rf %{buildroot} - -%files -%defattr(-,root,root,-) -{%- if doc_files %} -%doc {{ doc_files|join(" ") }} -{%- endif %} -{%- for script in scripts %} -%{_bindir}/{{ script }} -{%- endfor %} -%{python_sitelib}/* - -%changelog - From f67570522a2486423a0491c979ea15a1b41b9c5c Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Sat, 13 Oct 2018 03:42:56 -0400 Subject: [PATCH 07/23] Correct python* naming, activate has_ext_modules checks --- py2pack/templates/fedora.spec | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index 74a2fbe..94e05b6 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -29,12 +29,15 @@ # Common SRPM package Name: python-{{ name }} Version: {{ version }} -Release: 0 +Release: 0.1 Url: {{ home_page }} Summary: {{ summary }} License: {{ license }} Group: Development/Languages/Python Source: {{ source_url|replace(version, '%{version}') }} +{%- if not has_ext_modules %} +BuildArch: noarch +{%- endif %} BuildRoot: %{_tmppath}/%{name}-%{version}-build %if 0%{?with_python2} BuildRequires: python2-devel {%- if requires_python %} = {{ requires_python }} {% endif %} @@ -63,16 +66,16 @@ Url: {{ home_page }} Summary: {{ summary }} License: {{ license }} {%- for req in requires %} -Requires: python20{{ req|replace('(','')|replace(')','') }} +Requires: python2-{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- for req in install_requires %} -Requires: python20{{ req|replace('(','')|replace(')','') }} +Requires: python2-{{ req|replace('(','')|replace(')','') }} {%- endfor %} %if 0%{with_dnf} {%- if extras_require %} {%- for reqlist in extras_require.values() %} {%- for req in reqlist %} -Suggests: python2-{{ req|replace('(','')|replace(')','') }} +Suggests: python20{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- endfor %} {%- endif %} @@ -158,7 +161,12 @@ rm -rf %{buildroot} {%- for script in scripts %} %{_bindir}/{{ script }} {%- endfor %} +{%- if is_extension %} +%{python2_archlib}/* +{%- endif %} +{%- if not is_extension %} %{python2_sitelib}/* +{%- endif %} %endif # with_python2 %if 0%{with_python3} @@ -170,8 +178,12 @@ rm -rf %{buildroot} {%- for script in scripts %} %{_bindir}/{{ script }} {%- endfor %} +{%- if is_extension %} +%{python3_archlib}/* +{%- endif %} +{%- if not is_extension %} %{python3_sitelib}/* +{%- endif %} %endif # with_python3 %changelog - From b2094ca6c5d86b1447ed30f884c4addcf890d3ed Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Sat, 13 Oct 2018 04:10:30 -0400 Subject: [PATCH 08/23] Re-arrange bin lists of ${script}2, ${script}3, ${script} so python2 only hosts get correct symlink in fedora.spec --- py2pack/templates/fedora.spec | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index 94e05b6..53763db 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -140,12 +140,14 @@ export CFLAGS="%{optflags}" %py2_install {%- for script in scripts %} %{__mv} $RPM_BUILD_ROOT%{_bindir}/${script} $RPM_BUILD_ROOT%{_bindir}/${script}2 +%{__ln_s} ${script}2 $RPM_BUILD_ROOT%{_bindir}/${script} {%- endfor %} %endif # with_python2 %if 0%{?with_python3} %py3_install {%- for script in scripts %} %{__mv} $RPM_BUILD_ROOT%{_bindir}/${script} $RPM_BUILD_ROOT%{_bindir}/${script}3 +%{__ln_s} ${script}3 $RPM_BUILD_ROOT%{_bindir}/${script} {%- endfor %} %endif # with_python3 @@ -159,9 +161,15 @@ rm -rf %{buildroot} %doc {{ doc_files|join(" ") }} {%- endif %} {%- for script in scripts %} -%{_bindir}/{{ script }} +%{_bindir}/{{ script }}2 {%- endfor %} {%- if is_extension %} +%if ! 0%{with_python3} +# Symlinks for binaries renamed 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 %} @@ -176,6 +184,9 @@ rm -rf %{buildroot} %doc {{ doc_files|join(" ") }} {%- endif %} {%- for script in scripts %} +%{_bindir}/{{ script }}3 +{%- endfor %} +{%- for script in scripts %} %{_bindir}/{{ script }} {%- endfor %} {%- if is_extension %} From 18a0399978e91ca460096bc4ea4e608f8534734f Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Sat, 13 Oct 2018 20:56:44 +0200 Subject: [PATCH 09/23] fix tests for fedora updates --- test/examples/py2pack-fedora.spec | 361 +++++++++++++++++++++++++++++- 1 file changed, 354 insertions(+), 7 deletions(-) diff --git a/test/examples/py2pack-fedora.spec b/test/examples/py2pack-fedora.spec index 73a93e3..adf5422 100644 --- a/test/examples/py2pack-fedora.spec +++ b/test/examples/py2pack-fedora.spec @@ -4,16 +4,69 @@ # Copyright (c) 2018 __USER__. # +# Fedora and RHEL split python2 and python3 +# Older RHEL does not include python3 by default +%if 0%{?fedora} || 0%{?rhel} > 7 +%global with_python3 1 +%else +%global with_python3 0 +%endif + +# Fedora > 28 no longer publishes python2 by default +%if 0%{?fedora} > 28 +%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 + +# Common SRPM package Name: python-py2pack Version: 0.8.0 -Release: 0 +Release: 0.1 Url: http://github.com/openSUSE/py2pack Summary: Generate distribution packages from PyPI License: Apache-2.0 Group: Development/Languages/Python Source: https://files.pythonhosted.org/packages/source/p/py2pack/py2pack-%{version}.tar.gz +BuildArch: noarch BuildRoot: %{_tmppath}/%{name}-%{version}-build -BuildRequires: python-devel +%if 0%{?with_python2} +BuildRequires: python2-devel +%endif # with_python2 +%if 0%{?with_python3} +BuildRequires: python3-devel +%endif # with_python3 + +%if 0%{?with_python2} +%package -n python2-py2pack +Version: 0.8.0 +Release: 0 +Url: http://github.com/openSUSE/py2pack +Summary: Generate distribution packages from PyPI +License: Apache-2.0 +%if 0%{with_dnf} +%endif # with_dnf +%{?python_provide:%python_provide python2-%{srcname}} +%endif # with_python2 + +%if 0%{?with_python3} +%package -n python3-py2pack +Version: 0.8.0 +Release: 0 +Url: http://github.com/openSUSE/py2pack +Summary: Generate distribution packages from PyPI +License: Apache-2.0 +%if 0%{with_dnf} +%endif # with_dnf +%{?python_provide:%python_provide python2-%{srcname}} +%endif # with_python3 %description Py2pack: Generate distribution packages from PyPI @@ -151,20 +204,314 @@ on your system. .. _`nose`: https://nose.readthedocs.org .. _`tox`: http://testrun.org/tox +%if 0%{?with_python2} +%description -n python2-py2pack +Py2pack: Generate distribution packages from PyPI +================================================= + +.. image:: https://travis-ci.org/openSUSE/py2pack.png?branch=master + :target: https://travis-ci.org/openSUSE/py2pack + + +This script allows to generate RPM spec or DEB dsc files from Python modules. +It allows to list Python modules or search for them on the Python Package Index +(PyPI). Conveniently, it can fetch tarballs and changelogs making it an +universal tool to package Python modules. + + +Installation +------------ + +To install py2pack from the `Python Package Index`_, simply: + +.. code-block:: bash + + $ pip install py2pack + +Or, if you absolutely must: + +.. code-block:: bash + + $ easy_install py2pack + +But, you really shouldn't do that. Lastly, you can check your distro of choice +if they provide packages. For openSUSE, you can find packages in the `Open +Build Service`_ for all releases. If you happen to use openSUSE:Factory (the +rolling release / development version), simply: + +.. code-block:: bash + + $ sudo zypper install python-py2pack + + +Usage +----- + +Lets suppose you want to package zope.interface_ and you don't know how it is named +exactly. First of all, you can search for it and download the source tarball if +you found the correct module: + +.. code-block:: bash + + $ py2pack search zope.interface + searching for module zope.interface... + found zope.interface-3.6.1 + $ py2pack fetch zope.interface + downloading package zope.interface-3.6.1... + from http://pypi.python.org/packages/source/z/zope.interface/zope.interface-3.6.1.tar.gz + + +As a next step you may want to generate a package recipe for your distribution. +For RPM_-based distributions (let's use openSUSE_ as an example), you want to +generate a spec file (named 'python-zope.interface.spec'): + +.. code-block:: bash + + $ py2pack generate zope.interface -t opensuse.spec -f python-zope.interface.spec + +The source tarball and the package recipe is all you need to generate the RPM_ +(or DEB_) file. +This final step may depend on which distribution you use. Again, +for openSUSE_ (and by using the `Open Build Service`_), the complete recipe is: + +.. code-block:: bash + + $ osc mkpac python-zope.interface + $ cd python-zope.interface + $ py2pack fetch zope.interface + $ py2pack generate zope.interface -f python-zope.interface.spec + $ osc build + ... + +Depending on the module, you may have to adapt the resulting spec file slightly. +To get further help about py2pack usage, issue the following command: + +.. code-block:: bash + + $ py2pack help + + +Hacking and contributing +------------------------ + +You can test py2pack from your git checkout by executing the py2pack module: + +.. code-block:: bash + + $ python -m py2pack + +Fork `the repository`_ on Github to start making your changes to the **master** +branch (or branch off of it). Don't forget to write a test for fixed issues or +implemented features whenever appropriate. You can invoke the testsuite from +the repository root directory via `tox`_: + +.. code-block:: bash + + $ tox + +To run a single test class via `tox`_, use i.e.: + +.. code-block:: bash + + $ tox -epy27 test.test_py2pack:Py2packTestCase + + +You can also run `nose`_ directly: + +.. code-block:: bash + + $ nosetests + +It assumes you have the test dependencies installed (available on PYTHONPATH) +on your system. + +:copyright: (c) 2013 Sascha Peilicke. +:license: Apache-2.0, see LICENSE for more details. + + +.. _argparse: http://pypi.python.org/pypi/argparse +.. _Jinja2: http://pypi.python.org/pypi/Jinja2 +.. _zope.interface: http://pypi.python.org/pypi/zope.interface/ +.. _openSUSE: http://www.opensuse.org/en/ +.. _RPM: http://en.wikipedia.org/wiki/RPM_Package_Manager +.. _DEB: http://en.wikipedia.org/wiki/Deb_(file_format) +.. _`Python Package Index`: https://pypi.python.org/pypi/rapport +.. _`Open Build Service`: https://build.opensuse.org/package/show?package=rapport&project=devel:languages:python +.. _`the repository`: https://github.com/openSUSE/py2pack +.. _`nose`: https://nose.readthedocs.org +.. _`tox`: http://testrun.org/tox +%endif # with_python2 + +%if 0%{?with_python3} +%description -n python3-py2pack +Py2pack: Generate distribution packages from PyPI +================================================= + +.. image:: https://travis-ci.org/openSUSE/py2pack.png?branch=master + :target: https://travis-ci.org/openSUSE/py2pack + + +This script allows to generate RPM spec or DEB dsc files from Python modules. +It allows to list Python modules or search for them on the Python Package Index +(PyPI). Conveniently, it can fetch tarballs and changelogs making it an +universal tool to package Python modules. + + +Installation +------------ + +To install py2pack from the `Python Package Index`_, simply: + +.. code-block:: bash + + $ pip install py2pack + +Or, if you absolutely must: + +.. code-block:: bash + + $ easy_install py2pack + +But, you really shouldn't do that. Lastly, you can check your distro of choice +if they provide packages. For openSUSE, you can find packages in the `Open +Build Service`_ for all releases. If you happen to use openSUSE:Factory (the +rolling release / development version), simply: + +.. code-block:: bash + + $ sudo zypper install python-py2pack + + +Usage +----- + +Lets suppose you want to package zope.interface_ and you don't know how it is named +exactly. First of all, you can search for it and download the source tarball if +you found the correct module: + +.. code-block:: bash + + $ py2pack search zope.interface + searching for module zope.interface... + found zope.interface-3.6.1 + $ py2pack fetch zope.interface + downloading package zope.interface-3.6.1... + from http://pypi.python.org/packages/source/z/zope.interface/zope.interface-3.6.1.tar.gz + + +As a next step you may want to generate a package recipe for your distribution. +For RPM_-based distributions (let's use openSUSE_ as an example), you want to +generate a spec file (named 'python-zope.interface.spec'): + +.. code-block:: bash + + $ py2pack generate zope.interface -t opensuse.spec -f python-zope.interface.spec + +The source tarball and the package recipe is all you need to generate the RPM_ +(or DEB_) file. +This final step may depend on which distribution you use. Again, +for openSUSE_ (and by using the `Open Build Service`_), the complete recipe is: + +.. code-block:: bash + + $ osc mkpac python-zope.interface + $ cd python-zope.interface + $ py2pack fetch zope.interface + $ py2pack generate zope.interface -f python-zope.interface.spec + $ osc build + ... + +Depending on the module, you may have to adapt the resulting spec file slightly. +To get further help about py2pack usage, issue the following command: + +.. code-block:: bash + + $ py2pack help + + +Hacking and contributing +------------------------ + +You can test py2pack from your git checkout by executing the py2pack module: + +.. code-block:: bash + + $ python -m py2pack + +Fork `the repository`_ on Github to start making your changes to the **master** +branch (or branch off of it). Don't forget to write a test for fixed issues or +implemented features whenever appropriate. You can invoke the testsuite from +the repository root directory via `tox`_: + +.. code-block:: bash + + $ tox + +To run a single test class via `tox`_, use i.e.: + +.. code-block:: bash + + $ tox -epy27 test.test_py2pack:Py2packTestCase + + +You can also run `nose`_ directly: + +.. code-block:: bash + + $ nosetests + +It assumes you have the test dependencies installed (available on PYTHONPATH) +on your system. + +:copyright: (c) 2013 Sascha Peilicke. +:license: Apache-2.0, see LICENSE for more details. + + +.. _argparse: http://pypi.python.org/pypi/argparse +.. _Jinja2: http://pypi.python.org/pypi/Jinja2 +.. _zope.interface: http://pypi.python.org/pypi/zope.interface/ +.. _openSUSE: http://www.opensuse.org/en/ +.. _RPM: http://en.wikipedia.org/wiki/RPM_Package_Manager +.. _DEB: http://en.wikipedia.org/wiki/Deb_(file_format) +.. _`Python Package Index`: https://pypi.python.org/pypi/rapport +.. _`Open Build Service`: https://build.opensuse.org/package/show?package=rapport&project=devel:languages:python +.. _`the repository`: https://github.com/openSUSE/py2pack +.. _`nose`: https://nose.readthedocs.org +.. _`tox`: http://testrun.org/tox +%endif # with_python3 + %prep %setup -q -n py2pack-%{version} %build -python setup.py build +%if 0%{?with_python2} +%py2_build +%endif # with_python2 +%if 0%{?with_python3} +%py2_build +%endif # with_python3 %install -python setup.py install --prefix=%{_prefix} --root=%{buildroot} +%if 0%{?with_python2} +%py2_install +%endif # with_python2 +%if 0%{?with_python3} +%py3_install +%endif # with_python3 %clean rm -rf %{buildroot} -%files +%if 0%{with_python2} +%files -n python2-py2pack +%defattr(-,root,root,-) +%{python2_sitelib}/* +%endif # with_python2 + +%if 0%{with_python3} +%files -n python3-py2pack %defattr(-,root,root,-) -%{python_sitelib}/* +%{python3_sitelib}/* +%endif # with_python3 -%changelog +%changelog \ No newline at end of file From 6456b94e85910dd1c11e3de9f77cdccbe5af23fc Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Thu, 18 Oct 2018 05:45:04 -0400 Subject: [PATCH 10/23] Do not create python2 links in fedora.spec if python3 is enabled --- py2pack/templates/fedora.spec | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index 53763db..a591895 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -140,10 +140,15 @@ export CFLAGS="%{optflags}" %py2_install {%- for script in scripts %} %{__mv} $RPM_BUILD_ROOT%{_bindir}/${script} $RPM_BUILD_ROOT%{_bindir}/${script}2 +{%- endfor %} +%if ! 0%{with_python3} +{%- for script in scripts %} %{__ln_s} ${script}2 $RPM_BUILD_ROOT%{_bindir}/${script} {%- endfor %} +%endif # ! with_python3 %endif # with_python2 %if 0%{?with_python3} + %py3_install {%- for script in scripts %} %{__mv} $RPM_BUILD_ROOT%{_bindir}/${script} $RPM_BUILD_ROOT%{_bindir}/${script}3 From d4d66b0b9e2c76376a4752e528f92f54c3e47c63 Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Thu, 18 Oct 2018 06:03:40 -0400 Subject: [PATCH 11/23] Update examples/py2pack-fedora.spec to match python2/ython3 split handling --- test/examples/py2pack-fedora.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/examples/py2pack-fedora.spec b/test/examples/py2pack-fedora.spec index adf5422..961eb25 100644 --- a/test/examples/py2pack-fedora.spec +++ b/test/examples/py2pack-fedora.spec @@ -494,8 +494,11 @@ on your system. %install %if 0%{?with_python2} %py2_install +%if ! 0%{with_python3} +%endif # ! with_python3 %endif # with_python2 %if 0%{?with_python3} + %py3_install %endif # with_python3 @@ -514,4 +517,4 @@ rm -rf %{buildroot} %{python3_sitelib}/* %endif # with_python3 -%changelog \ No newline at end of file +%changelog From 637d51d01538249142229ba2508a3acd3dbf4303 Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Thu, 18 Oct 2018 06:45:53 -0400 Subject: [PATCH 12/23] Lower release number in fedora.spec back to zero --- py2pack/templates/fedora.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index a591895..8fa0f81 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -29,7 +29,7 @@ # Common SRPM package Name: python-{{ name }} Version: {{ version }} -Release: 0.1 +Release: 0 Url: {{ home_page }} Summary: {{ summary }} License: {{ license }} From c72a852285e8961569aa55f7e57dfb2b5045aa79 Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Thu, 18 Oct 2018 07:04:19 -0400 Subject: [PATCH 13/23] Restore correct py3_build to fedora.spec --- py2pack/templates/fedora.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index 8fa0f81..1e4b200 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -132,7 +132,7 @@ export CFLAGS="%{optflags}" %py2_build %endif # with_python2 %if 0%{?with_python3} -%py2_build +%py3_build %endif # with_python3 %install From 4d38d1b9663566e7f8978f5b15c22b509bcacf7f Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Thu, 18 Oct 2018 07:06:24 -0400 Subject: [PATCH 14/23] Restore py3_build to test template for fedoraa.spec --- test/examples/py2pack-el.spec | 170 ------------------------------ test/examples/py2pack-fedora.spec | 2 +- 2 files changed, 1 insertion(+), 171 deletions(-) delete mode 100644 test/examples/py2pack-el.spec diff --git a/test/examples/py2pack-el.spec b/test/examples/py2pack-el.spec deleted file mode 100644 index 73a93e3..0000000 --- a/test/examples/py2pack-el.spec +++ /dev/null @@ -1,170 +0,0 @@ -# -# spec file for package python-py2pack -# -# Copyright (c) 2018 __USER__. -# - -Name: python-py2pack -Version: 0.8.0 -Release: 0 -Url: http://github.com/openSUSE/py2pack -Summary: Generate distribution packages from PyPI -License: Apache-2.0 -Group: Development/Languages/Python -Source: https://files.pythonhosted.org/packages/source/p/py2pack/py2pack-%{version}.tar.gz -BuildRoot: %{_tmppath}/%{name}-%{version}-build -BuildRequires: python-devel - -%description -Py2pack: Generate distribution packages from PyPI -================================================= - -.. image:: https://travis-ci.org/openSUSE/py2pack.png?branch=master - :target: https://travis-ci.org/openSUSE/py2pack - - -This script allows to generate RPM spec or DEB dsc files from Python modules. -It allows to list Python modules or search for them on the Python Package Index -(PyPI). Conveniently, it can fetch tarballs and changelogs making it an -universal tool to package Python modules. - - -Installation ------------- - -To install py2pack from the `Python Package Index`_, simply: - -.. code-block:: bash - - $ pip install py2pack - -Or, if you absolutely must: - -.. code-block:: bash - - $ easy_install py2pack - -But, you really shouldn't do that. Lastly, you can check your distro of choice -if they provide packages. For openSUSE, you can find packages in the `Open -Build Service`_ for all releases. If you happen to use openSUSE:Factory (the -rolling release / development version), simply: - -.. code-block:: bash - - $ sudo zypper install python-py2pack - - -Usage ------ - -Lets suppose you want to package zope.interface_ and you don't know how it is named -exactly. First of all, you can search for it and download the source tarball if -you found the correct module: - -.. code-block:: bash - - $ py2pack search zope.interface - searching for module zope.interface... - found zope.interface-3.6.1 - $ py2pack fetch zope.interface - downloading package zope.interface-3.6.1... - from http://pypi.python.org/packages/source/z/zope.interface/zope.interface-3.6.1.tar.gz - - -As a next step you may want to generate a package recipe for your distribution. -For RPM_-based distributions (let's use openSUSE_ as an example), you want to -generate a spec file (named 'python-zope.interface.spec'): - -.. code-block:: bash - - $ py2pack generate zope.interface -t opensuse.spec -f python-zope.interface.spec - -The source tarball and the package recipe is all you need to generate the RPM_ -(or DEB_) file. -This final step may depend on which distribution you use. Again, -for openSUSE_ (and by using the `Open Build Service`_), the complete recipe is: - -.. code-block:: bash - - $ osc mkpac python-zope.interface - $ cd python-zope.interface - $ py2pack fetch zope.interface - $ py2pack generate zope.interface -f python-zope.interface.spec - $ osc build - ... - -Depending on the module, you may have to adapt the resulting spec file slightly. -To get further help about py2pack usage, issue the following command: - -.. code-block:: bash - - $ py2pack help - - -Hacking and contributing ------------------------- - -You can test py2pack from your git checkout by executing the py2pack module: - -.. code-block:: bash - - $ python -m py2pack - -Fork `the repository`_ on Github to start making your changes to the **master** -branch (or branch off of it). Don't forget to write a test for fixed issues or -implemented features whenever appropriate. You can invoke the testsuite from -the repository root directory via `tox`_: - -.. code-block:: bash - - $ tox - -To run a single test class via `tox`_, use i.e.: - -.. code-block:: bash - - $ tox -epy27 test.test_py2pack:Py2packTestCase - - -You can also run `nose`_ directly: - -.. code-block:: bash - - $ nosetests - -It assumes you have the test dependencies installed (available on PYTHONPATH) -on your system. - -:copyright: (c) 2013 Sascha Peilicke. -:license: Apache-2.0, see LICENSE for more details. - - -.. _argparse: http://pypi.python.org/pypi/argparse -.. _Jinja2: http://pypi.python.org/pypi/Jinja2 -.. _zope.interface: http://pypi.python.org/pypi/zope.interface/ -.. _openSUSE: http://www.opensuse.org/en/ -.. _RPM: http://en.wikipedia.org/wiki/RPM_Package_Manager -.. _DEB: http://en.wikipedia.org/wiki/Deb_(file_format) -.. _`Python Package Index`: https://pypi.python.org/pypi/rapport -.. _`Open Build Service`: https://build.opensuse.org/package/show?package=rapport&project=devel:languages:python -.. _`the repository`: https://github.com/openSUSE/py2pack -.. _`nose`: https://nose.readthedocs.org -.. _`tox`: http://testrun.org/tox - -%prep -%setup -q -n py2pack-%{version} - -%build -python setup.py build - -%install -python setup.py install --prefix=%{_prefix} --root=%{buildroot} - -%clean -rm -rf %{buildroot} - -%files -%defattr(-,root,root,-) -%{python_sitelib}/* - -%changelog diff --git a/test/examples/py2pack-fedora.spec b/test/examples/py2pack-fedora.spec index 961eb25..502c18f 100644 --- a/test/examples/py2pack-fedora.spec +++ b/test/examples/py2pack-fedora.spec @@ -488,7 +488,7 @@ on your system. %py2_build %endif # with_python2 %if 0%{?with_python3} -%py2_build +%py3_build %endif # with_python3 %install From 9ecde89bc6187ad27ead6c188575957dd39116e7 Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Thu, 18 Oct 2018 07:13:14 -0400 Subject: [PATCH 15/23] Use "%{with" consistently --- py2pack/templates/fedora.spec | 20 ++++++++++---------- test/examples/py2pack-fedora.spec | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index 1e4b200..320f69b 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -39,7 +39,7 @@ Source: {{ source_url|replace(version, '%{version}') }} BuildArch: noarch {%- endif %} BuildRoot: %{_tmppath}/%{name}-%{version}-build -%if 0%{?with_python2} +%if 0%{with_python2} BuildRequires: python2-devel {%- if requires_python %} = {{ requires_python }} {% endif %} {%- for req in requires %} BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} @@ -48,7 +48,7 @@ BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} {%- endfor %} %endif # with_python2 -%if 0%{?with_python3} +%if 0%{with_python3} BuildRequires: python3-devel {%- if requires_python %} = {{ requires_python }} {% endif %} {%- for req in requires %} BuildRequires: python3-{{ req|replace('(','')|replace(')','') }} @@ -58,7 +58,7 @@ BuildRequires: python3-{{ req|replace('(','')|replace(')','') }} {%- endfor %} %endif # with_python3 -%if 0%{?with_python2} +%if 0%{with_python2} %package -n python2-{{ name }} Version: {{ version }} Release: 0 @@ -83,7 +83,7 @@ Suggests: python20{{ req|replace('(','')|replace(')','') }} %{?python_provide:%python_provide python2-%{srcname}} %endif # with_python2 -%if 0%{?with_python3} +%if 0%{with_python3} %package -n python3-{{ name }} Version: {{ version }} Release: 0 @@ -111,12 +111,12 @@ Suggests: python3-{{ req|replace('(','')|replace(')','') }} %description {{ description }} -%if 0%{?with_python2} +%if 0%{with_python2} %description -n python2-{{ name }} {{ description }} %endif # with_python2 -%if 0%{?with_python3} +%if 0%{with_python3} %description -n python3-{{ name }} {{ description }} %endif # with_python3 @@ -128,15 +128,15 @@ Suggests: python3-{{ req|replace('(','')|replace(')','') }} {%- if is_extension %} export CFLAGS="%{optflags}" {%- endif %} -%if 0%{?with_python2} +%if 0%{with_python2} %py2_build %endif # with_python2 -%if 0%{?with_python3} +%if 0%{with_python3} %py3_build %endif # with_python3 %install -%if 0%{?with_python2} +%if 0%{with_python2} %py2_install {%- for script in scripts %} %{__mv} $RPM_BUILD_ROOT%{_bindir}/${script} $RPM_BUILD_ROOT%{_bindir}/${script}2 @@ -147,7 +147,7 @@ export CFLAGS="%{optflags}" {%- endfor %} %endif # ! with_python3 %endif # with_python2 -%if 0%{?with_python3} +%if 0%{with_python3} %py3_install {%- for script in scripts %} diff --git a/test/examples/py2pack-fedora.spec b/test/examples/py2pack-fedora.spec index 502c18f..74c7b35 100644 --- a/test/examples/py2pack-fedora.spec +++ b/test/examples/py2pack-fedora.spec @@ -37,14 +37,14 @@ Group: Development/Languages/Python Source: https://files.pythonhosted.org/packages/source/p/py2pack/py2pack-%{version}.tar.gz BuildArch: noarch BuildRoot: %{_tmppath}/%{name}-%{version}-build -%if 0%{?with_python2} +%if 0%{with_python2} BuildRequires: python2-devel %endif # with_python2 -%if 0%{?with_python3} +%if 0%{with_python3} BuildRequires: python3-devel %endif # with_python3 -%if 0%{?with_python2} +%if 0%{with_python2} %package -n python2-py2pack Version: 0.8.0 Release: 0 @@ -56,7 +56,7 @@ License: Apache-2.0 %{?python_provide:%python_provide python2-%{srcname}} %endif # with_python2 -%if 0%{?with_python3} +%if 0%{with_python3} %package -n python3-py2pack Version: 0.8.0 Release: 0 @@ -204,7 +204,7 @@ on your system. .. _`nose`: https://nose.readthedocs.org .. _`tox`: http://testrun.org/tox -%if 0%{?with_python2} +%if 0%{with_python2} %description -n python2-py2pack Py2pack: Generate distribution packages from PyPI ================================================= @@ -342,7 +342,7 @@ on your system. .. _`tox`: http://testrun.org/tox %endif # with_python2 -%if 0%{?with_python3} +%if 0%{with_python3} %description -n python3-py2pack Py2pack: Generate distribution packages from PyPI ================================================= @@ -484,20 +484,20 @@ on your system. %setup -q -n py2pack-%{version} %build -%if 0%{?with_python2} +%if 0%{with_python2} %py2_build %endif # with_python2 -%if 0%{?with_python3} +%if 0%{with_python3} %py3_build %endif # with_python3 %install -%if 0%{?with_python2} +%if 0%{with_python2} %py2_install %if ! 0%{with_python3} %endif # ! with_python3 %endif # with_python2 -%if 0%{?with_python3} +%if 0%{with_python3} %py3_install %endif # with_python3 From be4dfe19aac454a02aba922b4ca25c7196ec41ae Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Sun, 21 Oct 2018 15:37:06 -0400 Subject: [PATCH 16/23] Correct handling of python-provide for fedora.spec and python3 --- py2pack/templates/fedora.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index 320f69b..619dd95 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -105,7 +105,7 @@ Suggests: python3-{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- endif %} %endif # with_dnf -%{?python_provide:%python_provide python2-%{srcname}} +%{?python_provide:%python_provide python3-%{srcname}} %endif # with_python3 %description From 8332b2855adecb0fe0eabb36fe1509bffbc87418 Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Sun, 21 Oct 2018 16:45:48 -0400 Subject: [PATCH 17/23] Add python-setuptools requirements to fedora.spec --- py2pack/templates/fedora.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index 619dd95..2bf0a4b 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -41,6 +41,7 @@ BuildArch: noarch BuildRoot: %{_tmppath}/%{name}-%{version}-build %if 0%{with_python2} BuildRequires: python2-devel {%- if requires_python %} = {{ requires_python }} {% endif %} +BuildRequires: python2-setuptools {%- for req in requires %} BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} {%- endfor %} @@ -50,6 +51,7 @@ BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} %endif # with_python2 %if 0%{with_python3} BuildRequires: python3-devel {%- if requires_python %} = {{ requires_python }} {% endif %} +BuildRequires: python3-setuptools {%- for req in requires %} BuildRequires: python3-{{ req|replace('(','')|replace(')','') }} {%- endfor %} From 9c553ff8274367a845b4f42bd7cb4386029f49d3 Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Sun, 21 Oct 2018 17:10:47 -0400 Subject: [PATCH 18/23] Replace erroneous srcname with name macro in fedora.spec --- py2pack/templates/fedora.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index 2bf0a4b..6b5cf3c 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -82,7 +82,7 @@ Suggests: python20{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- endif %} %endif # with_dnf -%{?python_provide:%python_provide python2-%{srcname}} +%{?python_provide:%python_provide python2-{{ name }}} %endif # with_python2 %if 0%{with_python3} @@ -107,7 +107,7 @@ Suggests: python3-{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- endif %} %endif # with_dnf -%{?python_provide:%python_provide python3-%{srcname}} +%{?python_provide:%python_provide python3-{{ name }}} %endif # with_python3 %description From 7f201eb670c2ee56ae390fc8d72c8a18238790ef Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Sun, 21 Oct 2018 17:19:13 -0400 Subject: [PATCH 19/23] Snip version python-devel requirements for multiple versions until processing can be improved --- py2pack/templates/fedora.spec | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index 6b5cf3c..b191b33 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -40,7 +40,11 @@ BuildArch: noarch {%- endif %} BuildRoot: %{_tmppath}/%{name}-%{version}-build %if 0%{with_python2} -BuildRequires: python2-devel {%- if requires_python %} = {{ requires_python }} {% endif %} +BuildRequires: python2-devel +{%- if requires_python %} +# Skip version specific python nandling until py2pack supports multiple version dependendies +#BuildRequires: python3-devel {{ requires_python }} +{% endif %} BuildRequires: python2-setuptools {%- for req in requires %} BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} @@ -50,7 +54,11 @@ BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} {%- endfor %} %endif # with_python2 %if 0%{with_python3} -BuildRequires: python3-devel {%- if requires_python %} = {{ requires_python }} {% endif %} +BuildRequires: python3-devel +{%- if requires_python %} +# Skip version specific python nandling until py2pack supports multiple version dependendies +#BuildRequires: python3-devel {{ requires_python }} +{% endif %} BuildRequires: python3-setuptools {%- for req in requires %} BuildRequires: python3-{{ req|replace('(','')|replace(')','') }} From a2bc5583ad79e62253ee8a25d3df346455bfb7fe Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Mon, 22 Oct 2018 08:04:52 -0400 Subject: [PATCH 20/23] Add ?dist to release for fedora.spec --- py2pack/templates/fedora.spec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index b191b33..d205b5b 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -29,7 +29,7 @@ # Common SRPM package Name: python-{{ name }} Version: {{ version }} -Release: 0 +Release: 0%{?dist} Url: {{ home_page }} Summary: {{ summary }} License: {{ license }} @@ -71,7 +71,7 @@ BuildRequires: python3-{{ req|replace('(','')|replace(')','') }} %if 0%{with_python2} %package -n python2-{{ name }} Version: {{ version }} -Release: 0 +Release: 0%{?dist} Url: {{ home_page }} Summary: {{ summary }} License: {{ license }} @@ -96,7 +96,7 @@ Suggests: python20{{ req|replace('(','')|replace(')','') }} %if 0%{with_python3} %package -n python3-{{ name }} Version: {{ version }} -Release: 0 +Release: 0%{?dist} Url: {{ home_page }} Summary: {{ summary }} License: {{ license }} From b2170f76d42962b05a327f19bd7631d57db778dc Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Sat, 10 Nov 2018 19:37:03 +0000 Subject: [PATCH 21/23] Use python-, not python2-, for RHEL in fedora.spec --- py2pack/templates/fedora.spec | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index d205b5b..8020824 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -40,12 +40,14 @@ BuildArch: noarch {%- endif %} BuildRoot: %{_tmppath}/%{name}-%{version}-build %if 0%{with_python2} +%if 0%{?rhel} +# Use non-specific names for RHEL +BuildRequires: python-devel +BuildRequires: python-setuptools +%else BuildRequires: python2-devel -{%- if requires_python %} -# Skip version specific python nandling until py2pack supports multiple version dependendies -#BuildRequires: python3-devel {{ requires_python }} -{% endif %} BuildRequires: python2-setuptools +%endif # rhel {%- for req in requires %} BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} {%- endfor %} @@ -55,10 +57,6 @@ BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} %endif # with_python2 %if 0%{with_python3} BuildRequires: python3-devel -{%- if requires_python %} -# Skip version specific python nandling until py2pack supports multiple version dependendies -#BuildRequires: python3-devel {{ requires_python }} -{% endif %} BuildRequires: python3-setuptools {%- for req in requires %} BuildRequires: python3-{{ req|replace('(','')|replace(')','') }} From 3cb8e325b651be58e55aa6d31c4dad7464df982e Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Wed, 3 Jul 2019 17:06:14 -0400 Subject: [PATCH 22/23] Activate with_python2 settings --- py2pack/templates/fedora.spec | 90 +++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index af2cce9..ff21478 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -4,6 +4,15 @@ # Copyright (c) {{ year }} {{ user_name }}. # +# Single python3 version in Fedora, python36 or python34 for RHEL +%{!?python3_pkgversion:%global python3_pkgversion 3} + +%global with_python3 1 +%if 0%{?fedora} > 30 +%global with_python2 1 +%else +%global with_python2 0 + Name: python-{{ name }} Version: {{ version }} Release: 0 @@ -13,25 +22,75 @@ 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 %} +%if %{with_python2} +BuildRequires: python2-devel {%- if requires_python %} = {{ requires_python }} {% endif %} {%- 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 %} +%endif +%if %{with_python3} +BuildRequires: python%{python3_pkgversion}-devel {%- if requires_python %} = {{ requires_python }} {% endif %} +{%- for req in requires %} +BuildRequires: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }} +Requires: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +%endif + +%description +{{ description }} + +%if %{with_python2} +%package -n python2-{{ name }} +Version: {{ version }} +Release: 0 +Url: {{ home_page }} +Summary: {{ summary }} +License: {{ license }} +Group: Development/Languages/Python {%- 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 extras_require %} +%if 0%{fedora} > 0 {%- for reqlist in extras_require.values() %} {%- for req in reqlist %} -Suggests: python-{{ req|replace('(','')|replace(')','') }} +Suggests: python2-{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- endfor %} +%endif {%- endif %} -%description +%description -n python2-{{ name }} {{ description }} +%endif # with_python2 + +%if %{with_python3} +%package -n python%{python3-pkgveraion}-{{ name }} +Version: {{ version }} +Release: 0 +Url: {{ home_page }} +Summary: {{ summary }} +License: {{ license }} +Group: Development/Languages/Python +{%- for req in install_requires %} +BuildRequires: python%{python3-pkgversion}-{{ req|replace('(','')|replace(')','') }} +Requires: python%{python3-pkgversion}-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +{%- if extras_require %} +%if 0%{fedora} > 0 +{%- for reqlist in extras_require.values() %} +{%- for req in reqlist %} +Suggests: python%{python3-pkgversion}-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +{%- endfor %} +%endif +{%- endif %} + +%description -n python%{pyton3-pkgversion}-{{ name }} +{{ description }} +%endif # with_python2 %prep %setup -q -n {{ name }}-%{version} @@ -40,10 +99,23 @@ Suggests: python-{{ req|replace('(','')|replace(')','') }} {%- if is_extension %} export CFLAGS="%{optflags}" {%- endif %} -python setup.py build + +%if %{with_python2} +%{__python2} setup.py build +%endif + +%if %{with_python3} +%{__python3} setup.py build +%endif %install -python setup.py install --prefix=%{_prefix} --root=%{buildroot} +%if %{with_python2} +%{__python2} setup.py install --prefix=%{_prefix} --root=%{buildroot} +%endif + +%if %{with_python3} +%{__python3} setup.py install --prefix=%{_prefix} --root=%{buildroot} +%endif %clean rm -rf %{buildroot} From 9b4c8f8bf46d3bee61e69597792a94ce8b9e65ff Mon Sep 17 00:00:00 2001 From: Nico Kadel-Garcia Date: Fri, 5 Jul 2019 14:45:13 -0400 Subject: [PATCH 23/23] Update python2 and python3 split to only Require components for specific python builds --- py2pack/templates/fedora.spec | 174 ++++++++++++++++++++++++---------- 1 file changed, 124 insertions(+), 50 deletions(-) diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index ff21478..dacf57a 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -4,131 +4,205 @@ # Copyright (c) {{ year }} {{ user_name }}. # -# Single python3 version in Fedora, python36 or python34 for RHEL +# 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 -%if 0%{?fedora} > 30 + +# 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_python2 0 +%global with_dnf 0 +%endif + +%global pypi_name {{ name }} + +# Descriptions can get long and clutter .spec file +%global common_description %{expand: +{{ description }} +} -Name: python-{{ name }} +# 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 -%if %{with_python2} -BuildRequires: python2-devel {%- if requires_python %} = {{ requires_python }} {% endif %} -{%- for req in requires %} -BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} -Requires: python2-{{ req|replace('(','')|replace(')','') }} -{%- endfor %} -%endif -%if %{with_python3} -BuildRequires: python%{python3_pkgversion}-devel {%- if requires_python %} = {{ requires_python }} {% endif %} -{%- for req in requires %} -BuildRequires: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }} -Requires: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }} -{%- endfor %} -%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-{{ name }} +%package -n python2-%{pypi_name} Version: {{ version }} -Release: 0 +Release: 0%{?dist} Url: {{ home_page }} Summary: {{ summary }} License: {{ license }} -Group: Development/Languages/Python + +BuildRequires: python2-devel +BuildRequires: python2-setuptools +# requires stanza of py2pack +{%- for req in requires %} +BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} +Requires: python2-{{ req|replace('(','')|replace(')','') }} +{%- endfor %} +# install_requires stanza of py2pack {%- for req in install_requires %} BuildRequires: python2-{{ req|replace('(','')|replace(')','') }} Requires: python2-{{ req|replace('(','')|replace(')','') }} {%- endfor %} +%if %{with_dnf} {%- if extras_require %} -%if 0%{fedora} > 0 {%- for reqlist in extras_require.values() %} {%- for req in reqlist %} Suggests: python2-{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- endfor %} -%endif {%- endif %} +%endif # with_dnf +%{?python_provide:%python_provide python2-%{pypi_name}} -%description -n python2-{{ name }} +%description -n python2-%{pypi_name} {{ description }} + %endif # with_python2 %if %{with_python3} -%package -n python%{python3-pkgveraion}-{{ name }} +%package -n python%{python3_pkgversion}-%{pypi_name} Version: {{ version }} -Release: 0 +Release: 0%{?dist} Url: {{ home_page }} Summary: {{ summary }} License: {{ license }} -Group: Development/Languages/Python + +# 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(')','') }} +BuildRequires: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }} +Requires: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }} {%- endfor %} +%if %{with_dnf} {%- if extras_require %} -%if 0%{fedora} > 0 {%- for reqlist in extras_require.values() %} {%- for req in reqlist %} -Suggests: python%{python3-pkgversion}-{{ req|replace('(','')|replace(')','') }} +Suggests: python%{python3_pkgversion}-{{ req|replace('(','')|replace(')','') }} {%- endfor %} {%- endfor %} -%endif {%- endif %} +%endif # with_dnf +%{?python_provide:%python_provide python%{python3_pkgversion}-%{pypi_name}} -%description -n python%{pyton3-pkgversion}-{{ name }} +%description -n python%{python3_pkgversion}-%{pypi_name} {{ description }} -%endif # with_python2 + +%endif # with_python3 %prep -%setup -q -n {{ name }}-%{version} +%setup -q -n %{pypi_name}-%{version} %build {%- if is_extension %} export CFLAGS="%{optflags}" {%- endif %} - %if %{with_python2} -%{__python2} setup.py build -%endif +%py2_build +%endif # with_python2 %if %{with_python3} -%{__python3} setup.py build -%endif +%py3_build +%endif # with_python3 %install %if %{with_python2} -%{__python2} setup.py install --prefix=%{_prefix} --root=%{buildroot} -%endif +%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} -%{__python3} setup.py install --prefix=%{_prefix} --root=%{buildroot} -%endif +%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 -