Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
u committed Jan 12, 2025
1 parent 288c2c1 commit fbd9c83
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 287 deletions.
3 changes: 1 addition & 2 deletions py2pack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ 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')
if member.isfile():
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:
Expand Down
2 changes: 1 addition & 1 deletion test/examples/poetry-opensuse-augmented.spec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/examples/poetry-opensuse-legacy.spec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/examples/poetry-opensuse.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/examples/poetry-opensuse.spec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
135 changes: 1 addition & 134 deletions test/examples/py2pack-fedora-augmented.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
154 changes: 20 additions & 134 deletions test/examples/py2pack-opensuse-augmented.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/examples/py2pack-opensuse-legacy.spec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/examples/py2pack-opensuse.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit fbd9c83

Please sign in to comment.