Skip to content

Commit

Permalink
Switch to pysrpm instead of bdist_rpm
Browse files Browse the repository at this point in the history
setup.py bdist_rpm is being (slowly?) deprecated, see pypa/setuptools#1988
Also call rpmlint
  • Loading branch information
Cimbali committed Nov 9, 2021
1 parent 8d889fb commit a440f68
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 108 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/draft_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools wheel twine babel
python3 -m pip install setuptools wheel twine babel pysrpm rpmlint
- name: Update translations
env:
Expand All @@ -54,7 +54,7 @@ jobs:
run: |
mkdir srpm
build=${{ github.event.inputs.build }}
python3 setup.py bdist_rpm --dist-dir=srpm/ --source-only --release ${build:-1}
pysrpm --dest-dir=srpm/ --source-only --release ${build:-1} .
- name: Make tag name
id: name
Expand All @@ -73,6 +73,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }}

- name: Check built RPM with rpmlint
run: rpmlint srpm/*.src.rpm



windows-build:
name: Windows Binaries
Expand Down
1 change: 0 additions & 1 deletion scripts/rpm_build

This file was deleted.

7 changes: 0 additions & 7 deletions scripts/rpm_install

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/rpm_post_install

This file was deleted.

44 changes: 21 additions & 23 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ packages =
python_requires = >=3.4
install_requires =
watchdog
build_requires =
setuptools
babel

[options.extras_require]
build_sphinx =
Expand Down Expand Up @@ -115,30 +118,25 @@ directory = pympress/share/locale/
use-fuzzy = false
statistics = true

[bdist_rpm]
bdist_base = build
license = LICENSE.txt
install_script = scripts/rpm_install
build_script = scripts/rpm_build
post_install = scripts/rpm_post_install
# Do not fix the interpreter path
python = python3
# NB: py3_dist and typelib_deps are defined in the spec
[pysrpm]
flavour = pympress
requires =
python(abi) = %%{python3_version}
%%{py3_dist watchdog}
%%{!?typelib_deps:gtk3 gdk-pixbuf2 poppler-glib gobject-introspection}
%%{?typelib_deps:typelib(cairo) typelib(GLib) typelib(DBus) typelib(DBusGLib) typelib(GObject) typelib(Gdk) typelib(GdkPixbuf) typelib(Gio) typelib(Gtk) typelib(Poppler)}
%%{!?suse_version:python%%{python3_version}dist(pygobject)}
%%{!?suse_version:python%%%%{python3_version}dist(pygobject)}
%%{!?mga_version:python3-gobject}
build_requires =
python3-devel
python3-setuptools
findutils
gettext
recommends =
%%{py3_dist watchdog}
suggests =
(vlc and %%{py3_dist python-vlc}) or (
%%{?typelib_deps:typelib(Gst) and typelib(GstPlayer)}
%%{!?typelib_deps:gstreamer1 and gstreamer1-plugins-bad-free}
)

[pysrpm.pympress]
preamble =
%%define normalize() %%(echo %%* | tr "[:upper:]_ " "[:lower:]--")
%%{?!py3_dist:%%define py3_dist() (python%%{{python3_version}}dist(%%{{normalize %%1}}) or python3-%%1)}
%%{?suse_version:%%define typelib_deps 1}
%%{?mga_version:%%define typelib_deps 1}
${base:preamble}

post = ${base:post}
if [ $$1 -gt 1 ]; then
# On update, check for directories left by previous versions
find `%%__python3 -c 'import site; print("\n".join(site.getsitepackages()))'` -maxdepth 1 -name 'pympress-1.5.*' -exec rm -rf {{}} + 2>/dev/null
fi
71 changes: 0 additions & 71 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

from distutils.cmd import Command
from setuptools.command.build_py import build_py
from setuptools.command.bdist_rpm import bdist_rpm


def find_index_startstring(haystack, needle, start=0, stop=sys.maxsize):
Expand All @@ -48,75 +47,6 @@ def find_index_startstring(haystack, needle, start=0, stop=sys.maxsize):
raise ValueError('No string starts with ' + needle)


class PatchedRpmDist(bdist_rpm):
""" Patched bdist rpm to avoid running seds and breaking up the build system
"""
user_options = bdist_rpm.user_options + [
('recommends=', None, "capabilities recommendd by this package"),
('suggests=', None, "capabilities suggestd by this package"),
('license=', None, "License file"),
]

def initialize_options(self):
""" Initialize the additional and inherited options
"""
bdist_rpm.initialize_options(self)
self.recommends = None
self.suggests = None
self.license = None

def finalize_package_data(self):
""" Add recommends/suggests option validation
"""
bdist_rpm.finalize_package_data(self)

self.ensure_string_list('recommends')
self.ensure_string_list('suggests')
self.ensure_filename('license')


def _make_spec_file(self):
# Make the package name python3-pympress instead of pympress
# NB: %{name} evaluates to the RPM package name
spec = [
line.replace('%{name}', '%{pythonname}')
.replace('define name ', 'define pythonname ')
.replace('Name: %{pythonname}', 'Name: python3-%{pythonname}')
for line in bdist_rpm._make_spec_file(self) if not line.startswith('Group:')
]

insert_pos = find_index_startstring(spec, 'Requires:') + 1
insert = [
# Define what this package provides in terms of capabilities
'Provides: python3dist(%{pythonname}) = %{version}',
'Provides: python%{python3_version}dist(%{pythonname}) = %{version}',

# For Fedora, this adds python-name to provides if python3 is the default
'%{?python_provide:%python_provide python3-%{pythonname}}',
]

insert.append('%if %{?!rhel:8}%{?rhel} >= 8')
if self.recommends:
insert.append('Recommends: ' + ' '.join(self.recommends))

if self.suggests:
insert.append('Suggests: ' + ' '.join(self.suggests))
insert.append('%endif')

if self.license:
# before %defattr
spec.insert(len(spec) - 1, '%license ' + self.license)

# Roll our own py3_dist if it doesn’t exist on this platform, only for requires.
# Also define typelib_deps if we are on suse or mageia, to specify dependencies using typelib capabilities.
return [
'%define normalize() %(echo %* | tr "[:upper:]_ " "[:lower:]--")',
'%{?!py3_dist:%define py3_dist() (python%{python3_version}dist(%{normalize %1}) or python3-%1)}',
'%{?suse_version:%define typelib_deps 1}', '%{?mga_version:%define typelib_deps 1}', ''
] + spec[:insert_pos] + insert + spec[insert_pos:]



class GettextBuildCatalog(Command):
""" Patched build command to generate translations .mo files using gettext’s msgfmt
Expand Down Expand Up @@ -288,7 +218,6 @@ def pympress_resources():

options = {'cmdclass': {
'build_py': BuildWithCatalogs,
'bdist_rpm': PatchedRpmDist,
'compile_catalog': compile_catalog,
}}

Expand Down

0 comments on commit a440f68

Please sign in to comment.