From fbd9c83d40fa15b30b0fe7894e6ad58a6649b5f9 Mon Sep 17 00:00:00 2001 From: u Date: Sun, 12 Jan 2025 21:50:54 +0300 Subject: [PATCH] update --- py2pack/__init__.py | 3 +- test/examples/poetry-opensuse-augmented.spec | 2 +- test/examples/poetry-opensuse-legacy.spec | 2 +- test/examples/poetry-opensuse.dsc | 2 +- test/examples/poetry-opensuse.spec | 2 +- test/examples/py2pack-fedora-augmented.spec | 135 +-------------- test/examples/py2pack-opensuse-augmented.spec | 154 +++--------------- test/examples/py2pack-opensuse-legacy.spec | 2 +- test/examples/py2pack-opensuse.dsc | 2 +- test/examples/py2pack-opensuse.spec | 2 +- .../sampleproject-opensuse-augmented.spec | 2 +- .../sampleproject-opensuse-legacy.spec | 2 +- test/examples/sampleproject-opensuse.dsc | 2 +- test/examples/sampleproject-opensuse.spec | 2 +- test/test_template.py | 20 ++- 15 files changed, 47 insertions(+), 287 deletions(-) diff --git a/py2pack/__init__.py b/py2pack/__init__.py index d02324d..5e14dfa 100755 --- a/py2pack/__init__.py +++ b/py2pack/__init__.py @@ -113,7 +113,6 @@ def pypi_json_stream(json_stream): def pypi_archive_file(file_path): - is_tar = True try: archive = tarfile.open(file_path) member = archive.getmember('PKG-INFO') @@ -121,7 +120,7 @@ def pypi_archive_file(file_path): return pypi_text_stream(archive.extractfile(member)) except tarfile.ReadError: archive = zipfile.ZipFile(file_path) - member = arcihve.getinfo('PKG-INFO') + member = archive.getinfo('PKG-INFO') if not member.is_dir(): return pypi_text_stream(archive.open(member)) except Exception: diff --git a/test/examples/poetry-opensuse-augmented.spec b/test/examples/poetry-opensuse-augmented.spec index 09dd022..ff912cb 100644 --- a/test/examples/poetry-opensuse-augmented.spec +++ b/test/examples/poetry-opensuse-augmented.spec @@ -1,7 +1,7 @@ # # spec file for package python-poetry # -# Copyright (c) 2025 SUSE LLC +# Copyright (c) __YEAR__ SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed diff --git a/test/examples/poetry-opensuse-legacy.spec b/test/examples/poetry-opensuse-legacy.spec index 377b78a..a3e91d8 100644 --- a/test/examples/poetry-opensuse-legacy.spec +++ b/test/examples/poetry-opensuse-legacy.spec @@ -1,7 +1,7 @@ # # spec file for package python-poetry # -# Copyright (c) 2025 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) __YEAR__ SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed diff --git a/test/examples/poetry-opensuse.dsc b/test/examples/poetry-opensuse.dsc index 2d42e2b..68e4287 100644 --- a/test/examples/poetry-opensuse.dsc +++ b/test/examples/poetry-opensuse.dsc @@ -2,7 +2,7 @@ Format: 1.0 Source: poetry Version: 1.5.1 Binary: python-poetry -Maintainer: +Maintainer: __USER__ Architecture: any Standards-Version: 3.7.1 Build-Depends: debhelper (>= 4.0.0), python-dev diff --git a/test/examples/poetry-opensuse.spec b/test/examples/poetry-opensuse.spec index ba28973..cd593d4 100644 --- a/test/examples/poetry-opensuse.spec +++ b/test/examples/poetry-opensuse.spec @@ -1,7 +1,7 @@ # # spec file for package python-poetry # -# Copyright (c) 2025 SUSE LLC +# Copyright (c) __YEAR__ SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed diff --git a/test/examples/py2pack-fedora-augmented.spec b/test/examples/py2pack-fedora-augmented.spec index 4f74a96..7037923 100644 --- a/test/examples/py2pack-fedora-augmented.spec +++ b/test/examples/py2pack-fedora-augmented.spec @@ -18,140 +18,7 @@ BuildArch: noarch # Fill in the actual package description to submit package to Fedora %global _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 `pytest`_ directly: - -.. code-block:: bash - - $ pytest - -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.org/ -.. _`Open Build Service`: https://build.opensuse.org/package/show/devel:languages:python/python-py2pack -.. _`the repository`: https://github.com/openSUSE/py2pack -.. _`pytest`: https://github.com/pytest-dev/pytest -.. _`tox`: http://testrun.org/tox} +Generate distribution packages from PyPI} %description %_description diff --git a/test/examples/py2pack-opensuse-augmented.spec b/test/examples/py2pack-opensuse-augmented.spec index c8d8068..0f28129 100644 --- a/test/examples/py2pack-opensuse-augmented.spec +++ b/test/examples/py2pack-opensuse-augmented.spec @@ -24,148 +24,26 @@ License: Apache-2.0 URL: http://github.com/openSUSE/py2pack Source: https://files.pythonhosted.org/packages/source/p/py2pack/py2pack-%{version}.tar.gz BuildRequires: python-rpm-macros +BuildRequires: %{python_module pbr >= 1.8} BuildRequires: %{python_module pip} BuildRequires: %{python_module setuptools} BuildRequires: %{python_module wheel} +# SECTION test requirements +BuildRequires: %{python_module Jinja2} +BuildRequires: %{python_module metaextract} +BuildRequires: %{python_module six} +# /SECTION BuildRequires: fdupes +Requires: python-Jinja2 +Requires: python-metaextract +Requires: python-setuptools +Requires: python-six +Suggests: python-typing BuildArch: noarch %python_subpackages %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 `pytest`_ directly: - -.. code-block:: bash - - $ pytest - -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.org/ -.. _`Open Build Service`: https://build.opensuse.org/package/show/devel:languages:python/python-py2pack -.. _`the repository`: https://github.com/openSUSE/py2pack -.. _`pytest`: https://github.com/pytest-dev/pytest -.. _`tox`: http://testrun.org/tox +Generate distribution packages from PyPI %prep %autosetup -p1 -n py2pack-%{version} @@ -175,14 +53,22 @@ on your system. %install %pyproject_install +%python_clone -a %{buildroot}%{_bindir}/py2pack %python_expand %fdupes %{buildroot}%{$python_sitelib} %check CHOOSE: %pytest OR %pyunittest -v OR CUSTOM +%post +%python_install_alternative py2pack + +%postun +%python_uninstall_alternative py2pack + %files %{python_files} %doc AUTHORS ChangeLog README.rst %license LICENSE +%python_alternative %{_bindir}/py2pack %{python_sitelib}/py2pack %{python_sitelib}/py2pack-%{version}.dist-info diff --git a/test/examples/py2pack-opensuse-legacy.spec b/test/examples/py2pack-opensuse-legacy.spec index f2253e6..1db7df9 100644 --- a/test/examples/py2pack-opensuse-legacy.spec +++ b/test/examples/py2pack-opensuse-legacy.spec @@ -1,7 +1,7 @@ # # spec file for package python-py2pack # -# Copyright (c) 2025 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) __YEAR__ SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed diff --git a/test/examples/py2pack-opensuse.dsc b/test/examples/py2pack-opensuse.dsc index 5dcdb51..b8f48f4 100644 --- a/test/examples/py2pack-opensuse.dsc +++ b/test/examples/py2pack-opensuse.dsc @@ -2,7 +2,7 @@ Format: 1.0 Source: py2pack Version: 0.8.5 Binary: python-py2pack -Maintainer: +Maintainer: __USER__ Architecture: any Standards-Version: 3.7.1 Build-Depends: debhelper (>= 4.0.0), python-dev diff --git a/test/examples/py2pack-opensuse.spec b/test/examples/py2pack-opensuse.spec index 06bf0d8..e40af6b 100644 --- a/test/examples/py2pack-opensuse.spec +++ b/test/examples/py2pack-opensuse.spec @@ -1,7 +1,7 @@ # # spec file for package python-py2pack # -# Copyright (c) 2025 SUSE LLC +# Copyright (c) __YEAR__ SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed diff --git a/test/examples/sampleproject-opensuse-augmented.spec b/test/examples/sampleproject-opensuse-augmented.spec index e58324a..f8efaea 100644 --- a/test/examples/sampleproject-opensuse-augmented.spec +++ b/test/examples/sampleproject-opensuse-augmented.spec @@ -1,7 +1,7 @@ # # spec file for package python-sampleproject # -# Copyright (c) 2025 SUSE LLC +# Copyright (c) __YEAR__ SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed diff --git a/test/examples/sampleproject-opensuse-legacy.spec b/test/examples/sampleproject-opensuse-legacy.spec index 8579beb..407452b 100644 --- a/test/examples/sampleproject-opensuse-legacy.spec +++ b/test/examples/sampleproject-opensuse-legacy.spec @@ -1,7 +1,7 @@ # # spec file for package python-sampleproject # -# Copyright (c) 2025 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) __YEAR__ SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed diff --git a/test/examples/sampleproject-opensuse.dsc b/test/examples/sampleproject-opensuse.dsc index 7af22f6..c967d4e 100644 --- a/test/examples/sampleproject-opensuse.dsc +++ b/test/examples/sampleproject-opensuse.dsc @@ -2,7 +2,7 @@ Format: 1.0 Source: sampleproject Version: 3.0.0 Binary: python-sampleproject -Maintainer: +Maintainer: __USER__ Architecture: any Standards-Version: 3.7.1 Build-Depends: debhelper (>= 4.0.0), python-dev diff --git a/test/examples/sampleproject-opensuse.spec b/test/examples/sampleproject-opensuse.spec index 5f5bb6c..84fa2cb 100644 --- a/test/examples/sampleproject-opensuse.spec +++ b/test/examples/sampleproject-opensuse.spec @@ -1,7 +1,7 @@ # # spec file for package python-sampleproject # -# Copyright (c) 2025 SUSE LLC +# Copyright (c) __YEAR__ SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed diff --git a/test/test_template.py b/test/test_template.py index 274c4d9..e78c1d6 100644 --- a/test/test_template.py +++ b/test/test_template.py @@ -67,10 +67,11 @@ def test_template(tmpdir, template, fetch_tarball, project, version): args.name = project args.version = version reference = os.path.join(compare_dir, f'{args.name}-{filename}') + no_ref = False if project == 'poetry' and sys.version_info < (3, 11): pytest.xfail("Different requirements for python < 3.11") if not os.path.exists(reference): - pytest.xfail("No reference template available") + no_ref = True with tmpdir.as_cwd(): if fetch_tarball: py2pack.fetch(args) @@ -80,8 +81,15 @@ def test_template(tmpdir, template, fetch_tarball, project, version): py2pack.generate(args) with open(filename) as filehandle: written_spec = filehandle.read() - with open(reference) as filehandle: - required = filehandle.read() - required = required.replace('__USER__', username, 1) - required = required.replace('__YEAR__', str(datetime.date.today().year), 1) - assert written_spec == required + if no_ref: + required = written_spec.replace(username, '__USER__', 1) + required = required.replace(str(datetime.date.today().year), '__YEAR__', 1) + with open(reference, 'w') as filehandle: + filehandle.write(written_spec) + pytest.xfail("No reference template available") + else: + with open(reference) as filehandle: + required = filehandle.read() + required = required.replace('__USER__', username, 1) + required = required.replace('__YEAR__', str(datetime.date.today().year), 1) + assert written_spec == required