Skip to content

Commit

Permalink
Switch to Poetry and use pyproject.toml definitions
Browse files Browse the repository at this point in the history
This allows kiwi to be built, developed, tested, and installed
through Poetry. This also raises the minimum Python version to 3.9.
  • Loading branch information
Conan-Kudo committed Mar 5, 2024
1 parent 63c5e0f commit 8841907
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 262 deletions.
2 changes: 2 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ current_version = 10.0.0
commit = True
tag = True

[bumpversion:file:pyproject.toml]

[bumpversion:file:kiwi/version.py]

[bumpversion:file:doc/source/conf.py]
2 changes: 1 addition & 1 deletion .github/workflows/ci-units-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ var/
.installed.cfg
*.egg

# Poetry
poetry.lock

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
4 changes: 2 additions & 2 deletions .virtualenv.dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

-r .virtualenv.requirements.txt

# setuptools for pypi upload
setuptools
# poetry for building/installing/upload
poetry

# virtualenv-based automation of test activities
tox
Expand Down
13 changes: 9 additions & 4 deletions .virtualenv.requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ PyYAML
# TOML file parsing
toml

# Python wrapper for extended filesystem attributes
xattr==0.9.3

# Network request/response library
requests

# markup support
anymarkup-core
xmltodict

# provides pkg_resources
setuptools

# json support that also knows about tuples
simplejson

typing_extensions; python_version < '3.8'
# TOML file parsing
toml

# markup support
anymarkup-core
xmltodict
47 changes: 0 additions & 47 deletions MANIFEST.in

This file was deleted.

15 changes: 5 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,8 @@ clean_git_attributes:
git checkout kiwi/version.py

build: clean tox
# create setup.py variant for rpm build.
# delete module versions from setup.py for building an rpm
# the dependencies to the python module rpm packages is
# managed in the spec file
sed -ie "s@>=[0-9.]*'@'@g" setup.py
# build the sdist source tarball
$(python) setup.py sdist
# restore original setup.py backed up from sed
mv setup.pye setup.py
poetry build --format=sdist
# provide rpm source tarball
mv dist/kiwi-${version}.tar.gz dist/python-kiwi.tar.gz
# update rpm changelog using reference file
Expand All @@ -118,9 +111,11 @@ build: clean tox
cp package/python-kiwi-rpmlintrc dist

pypi: clean tox
$(python) setup.py sdist upload
poetry build --format=sdist
poetry publish --repository=pypi


clean: clean_git_attributes
$(python) setup.py clean
rm -rf dist
rm -rf doc/build
rm -rf doc/dist
40 changes: 5 additions & 35 deletions doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,49 +69,19 @@ environment for Python 3:
{kiwi} uses tox to create a devel environment and to run
tests, linters and other tasks in the tox generated environment.
A tox version >= 3.3 is required for this setup process. On your
host a python version >= 3.7 is required for tox to work.
host a python version >= 3.9 is required for tox to work.

.. code:: shell-session
$ tox -e devel
$ source .tox/devel/bin/activate
$ poetry install
The commands above automatically creates the application script
The command above automatically creates the application script
called :command:`kiwi-ng`, which allows you to run {kiwi} from the
Python sources inside the virtual environment:
Python sources inside the virtual environment using Poetry:

.. code:: shell-session
$ kiwi-ng --help
.. warning::

The virtualenv's `$PATH` will not be taken into account when calling
{kiwi} via :command:`sudo`! Use the absolute path to the {kiwi} executable
to run an actual build using your local changes:

.. code:: shell-session
$ sudo $PWD/.tox/devel/bin/kiwi-ng system build ...
To leave the development mode, run:

.. code:: shell-session
$ deactivate
To resume your work, :command:`cd` into your local Git repository and call:

.. code:: shell-session
$ source .tox/devel/bin/activate
Alternatively, you can launch single commands inside the virtualenv without
sourcing it directly:

.. code:: shell-session
$ tox -e devel -- kiwi-ng --version
$ poetry run kiwi-ng --help
Running the Unit Tests
Expand Down
9 changes: 6 additions & 3 deletions package/python-kiwi-pkgbuild-template
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ pkgrel=0
pkgdesc="KIWI - Appliance Builder Next Generation"
url="https://github.com/SUSE/kiwi/tarball/master"
license=('GPL3')
makedepends=(python-setuptools gcc shadow grep)
makedepends=(make gcc python-build python-docopt python-installer python-lxml python-poetry-core python-requests python-setuptools python-simplejson python-sphinx python-sphinx_rtd_theme python-wheel python-yaml shadow grep)
provides=(kiwi-ng kiwi)
source=("${pkgname}.tar.gz")
changelog="${pkgname}.changes"
md5sums=('%%MD5SUM')


build() {
export LANG=C.UTF-8
export LC_ALL=C.UTF-8
cd kiwi-${pkgver}
python setup.py build
make -C doc man
python3 -m build --no-isolation --wheel
}

package_python-kiwi(){
depends=(python-docopt python-simplejson python-lxml python-requests python-setuptools python-yaml grub qemu squashfs-tools gptfdisk pacman e2fsprogs xfsprogs btrfs-progs libisoburn lvm2 mtools parted multipath-tools rsync tar shadow screen kiwi-man-pages)
optdepends=('gnupg: keyring creation for APT package manager')
cd kiwi-${pkgver}
python setup.py install --root="${pkgdir}/" --optimize=1 --skip-build
python3 -m installer --destdir "${pkgdir}/" dist/*.whl
ln -sr "${pkgdir}/usr/bin/kiwi-ng" "${pkgdir}/usr/bin/kiwi"
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
Expand Down
80 changes: 53 additions & 27 deletions package/python-kiwi-spec-template
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@

# If they aren't provided by a system installed macro, define them
%{!?_defaultdocdir: %global _defaultdocdir %{_datadir}/doc}

%if 0%{?suse_version} && 0%{?suse_version} < 1600
%global __python3 /usr/bin/python3.11
%global python3_pkgversion 311
%else
%{!?__python3: %global __python3 /usr/bin/python3}
%{!?python3_pkgversion:%global python3_pkgversion 3}
%endif

%if %{undefined python3_sitelib}
%global python3_sitelib %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
%endif

%if 0%{?el7}
%global python3_pkgversion 36
%else
%{!?python3_pkgversion:%global python3_pkgversion 3}
%endif

%if 0%{?debian} || 0%{?ubuntu}
%global is_deb 1
%global pygroup python
Expand All @@ -57,9 +58,6 @@ Group: %{pygroup}
Source: %{name}.tar.gz
Source1: %{name}-rpmlintrc
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: gcc
BuildRequires: python%{python3_pkgversion}-%{develsuffix} >= 3.6
BuildRequires: python%{python3_pkgversion}-setuptools
%if 0%{?fedora} || 0%{?suse_version}
BuildRequires: fdupes
%endif
Expand All @@ -69,6 +67,32 @@ BuildRequires: shadow
%if 0%{?debian} || 0%{?ubuntu}
BuildRequires: passwd
%endif
# Main build requirements
BuildRequires: gcc
BuildRequires: make
BuildRequires: python%{python3_pkgversion}-%{develsuffix} >= 3.9
BuildRequires: python%{python3_pkgversion}-build
BuildRequires: python%{python3_pkgversion}-installer
BuildRequires: python%{python3_pkgversion}-poetry-core >= 1.2.0
BuildRequires: python%{python3_pkgversion}-wheel
# doc build requirements
BuildRequires: python%{python3_pkgversion}-docopt >= 0.6.2
BuildRequires: python%{python3_pkgversion}-lxml
BuildRequires: python%{python3_pkgversion}-requests
BuildRequires: python%{python3_pkgversion}-setuptools
BuildRequires: python%{python3_pkgversion}-simplejson
%if 0%{?suse_version}
BuildRequires: python%{python3_pkgversion}-Sphinx
%else
BuildRequires: python%{python3_pkgversion}-sphinx
%endif
%if 0%{?debian} || 0%{?ubuntu}
BuildRequires: python%{python3_pkgversion}-sphinx-rtd-theme
BuildRequires: python%{python3_pkgversion}-yaml
%else
BuildRequires: python%{python3_pkgversion}-sphinx_rtd_theme
BuildRequires: python%{python3_pkgversion}-PyYAML
%endif

%description
The KIWI Image System provides an operating system image builder
Expand Down Expand Up @@ -359,10 +383,9 @@ Obsoletes: python2-kiwi
Conflicts: python2-kiwi
Conflicts: kiwi-man-pages < %{version}
Requires: screen
Requires: python%{python3_pkgversion} >= 3.6
Requires: python%{python3_pkgversion} >= 3.9
%if 0%{?ubuntu} || 0%{?debian}
Requires: python%{python3_pkgversion}-yaml
Requires: python%{python3_pkgversion}-typing-extensions
%else
Requires: python%{python3_pkgversion}-PyYAML
%endif
Expand All @@ -372,12 +395,6 @@ Requires: python%{python3_pkgversion}-lxml
Requires: python%{python3_pkgversion}-requests
Requires: python%{python3_pkgversion}-setuptools
Requires: python%{python3_pkgversion}-xmltodict
%if 0%{?rhel} || 0%{?fedora}
Requires: (python%{python3_pkgversion}-typing-extensions if python%{python3_pkgversion} < 3.8)
%endif
%if 0%{?suse_version}
Requires: (python%{python3_pkgversion}-typing_extensions if python%{python3_pkgversion} < 3.8)
%endif
%if ! (0%{?rhel} && 0%{?rhel} < 8)
Recommends: kiwi-man-pages
%endif
Expand Down Expand Up @@ -601,29 +618,40 @@ Group: %{sysgroup}
Provides manual pages to describe the kiwi commands

%prep
%setup -q -n kiwi-%{version}
%autosetup -n kiwi-%{version}

# Drop shebang for kiwi/xml_parse.py, as we don't intend to use it
# as an independent script
sed -e "s|#!/usr/bin/env python||" -i kiwi/xml_parse.py

# Build documentation
make -C doc man

# Build application wheel
%{__python3} -m build --no-isolation --wheel

%install
# Install Python 3 version
python3 setup.py install --prefix=%{_prefix} --root=%{buildroot} %{?is_deb:--install-layout=deb}
# Install application
%{__python3} -m installer --destdir %{buildroot} %{?is_deb:--no-compile-bytecode} dist/*.whl

%if 0%{?is_deb}
# Fix where files were installed
mv %{buildroot}%{_prefix}/local/* %{buildroot}%{_prefix}
mv %{buildroot}%{_prefix}/lib/python3* %{buildroot}%{_prefix}/lib/python3
%endif

# Install C-Tools, man-pages, completion and kiwi default configuration
make buildroot=%{buildroot}/ install
# Install man-pages, completion and kiwi default configuration
make buildroot=%{buildroot}/ python=%{__python3} install

# Install dracut modules
make buildroot=%{buildroot}/ install_dracut
make buildroot=%{buildroot}/ python=%{__python3} install_dracut

# Install documentation README / LICENSE
make buildroot=%{buildroot}/ docdir=%{_defaultdocdir}/ install_package_docs
make buildroot=%{buildroot}/ docdir=%{_defaultdocdir}/ python=%{__python3} install_package_docs

# Create symlinks for correct binaries
ln -sr %{buildroot}%{_bindir}/kiwi-ng %{buildroot}%{_bindir}/kiwi
ln -sr %{buildroot}%{_bindir}/kiwi-ng %{buildroot}%{_bindir}/kiwi-ng-3
ln -sr %{buildroot}%{_bindir}/kiwicompat %{buildroot}%{_bindir}/kiwicompat-3

%if "%{_vendor}" != "debbuild"
# kiwi pxeboot directory structure to be packed in kiwi-pxeboot
Expand Down Expand Up @@ -684,9 +712,7 @@ fi
%dir %{_defaultdocdir}/python-kiwi
%{_bindir}/kiwi
%{_bindir}/kiwi-ng
%{_bindir}/kiwicompat
%{_bindir}/kiwi-ng-3*
%{_bindir}/kiwicompat-3*
%{python3_sitelib}/kiwi*
%{_usr}/share/bash-completion/completions/kiwi-ng
%{_defaultdocdir}/python-kiwi/LICENSE
Expand Down
Loading

0 comments on commit 8841907

Please sign in to comment.