diff --git a/.gitignore b/.gitignore index 80f52ec..57f3221 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ nosetests.xml *.egg-info .venv* .tox -.eggs \ No newline at end of file +.eggs +*.orig + diff --git a/py2pack/templates/fedora.spec b/py2pack/templates/fedora.spec index af2cce9..dacf57a 100644 --- a/py2pack/templates/fedora.spec +++ b/py2pack/templates/fedora.spec @@ -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 - diff --git a/test/examples/py2pack-fedora.spec b/test/examples/py2pack-fedora.spec index 73a93e3..cc85917 100644 --- a/test/examples/py2pack-fedora.spec +++ b/test/examples/py2pack-fedora.spec @@ -1,19 +1,186 @@ # # spec file for package python-py2pack # -# Copyright (c) 2018 __USER__. +# Copyright (c) 2019 __USER__ # -Name: python-py2pack -Version: 0.8.0 -Release: 0 +# 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 py2pack + +# Descriptions can get long and clutter .spec file +%global common_description %{expand: +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 +} + +# Common SRPM package +Name: python-%{pypi_name} +Version: 0.8.4 +Release: 0%{?dist} 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 +# 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 +BuildArch: noarch +# requires stanza of py2pack +# install_requires stanza of py2pack + +%if %{with_dnf} +%endif # with_dnf %description Py2pack: Generate distribution packages from PyPI @@ -151,20 +318,345 @@ on your system. .. _`nose`: https://nose.readthedocs.org .. _`tox`: http://testrun.org/tox +%if %{with_python2} +%package -n python2-%{pypi_name} +Version: 0.8.4 +Release: 0%{?dist} +Url: http://github.com/openSUSE/py2pack +Summary: Generate distribution packages from PyPI +License: Apache-2.0 + +BuildRequires: python2-devel +BuildRequires: python2-setuptools +# requires stanza of py2pack +# install_requires stanza of py2pack +%if %{with_dnf} +%endif # with_dnf +%{?python_provide:%python_provide python2-%{pypi_name}} + +%description -n python2-%{pypi_name} +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 %{with_python3} +%package -n python%{python3_pkgversion}-%{pypi_name} +Version: 0.8.4 +Release: 0%{?dist} +Url: http://github.com/openSUSE/py2pack +Summary: Generate distribution packages from PyPI +License: Apache-2.0 + +# requires stanza of py2pack +# install_requires stanza of py2pack +%if %{with_dnf} +%endif # with_dnf +%{?python_provide:%python_provide python%{python3_pkgversion}-%{pypi_name}} + +%description -n python%{python3_pkgversion}-%{pypi_name} +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} +%setup -q -n %{pypi_name}-%{version} %build -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 +%endif # with_python2 + +%if %{with_python3} +%py3_install +%endif # with_python3 %clean rm -rf %{buildroot} -%files +%if %{with_python2} +%files -n python2-%{pypi_name} +%defattr(-,root,root,-) +%{python2_sitelib}/* +%endif # with_python2 + +%if %{with_python3} +%files -n python%{python3_pkgversion}-%{pypi_name} %defattr(-,root,root,-) -%{python_sitelib}/* +%{python3_sitelib}/* +%endif # with_python3 %changelog