diff --git a/build-scripts/build-bindings.sh b/build-scripts/build-bindings.sh index 293ec74977..840caeaba3 100644 --- a/build-scripts/build-bindings.sh +++ b/build-scripts/build-bindings.sh @@ -14,10 +14,10 @@ function python() { ## Set version and release sed \ -e "s|@VERSION@|${VERSION}|g" \ - < $PYTHON_BINDINGS_DIR"pyproject.toml.in" \ - > $PYTHON_BINDINGS_DIR"pyproject.toml" + < $PYTHON_BINDINGS_DIR"setup.py.in" \ + > $PYTHON_BINDINGS_DIR"setup.py" - python3 -m build --sdist --wheel --outdir dist/ $PYTHON_BINDINGS_DIR + python3 $PYTHON_BINDINGS_DIR"setup.py" bdist_wheel --dist-dir=dist/ } echo "Building bindings $1" diff --git a/hirte.spec.in b/hirte.spec.in index aace6db213..74297f5e06 100644 --- a/hirte.spec.in +++ b/hirte.spec.in @@ -149,17 +149,38 @@ This package contains the service controller command line tool. %{_mandir}/man1/hirtectl.* +%package python3-pyhirte +Summary: Python bindings for Hirte +BuildRequires: python3-devel +BuildRequires: python3-setuptools +Requires: python3-dasbus + +%description python3-pyhirte +pyhirte is a python module to access the public D-Bus API of hirte. +It contains typed python code that is auto-generated from hirte's +API description and manually written code to simplify recurring tasks. + +%files python3-pyhirte +%license LICENSE +%doc README.md +%{python3_sitelib}/pyhirte-*.egg-info/ +%{python3_sitelib}/pyhirte/ + + %prep %autosetup +cp -r src/bindings/python/* ./ %build %meson -Dapi_bus=system %meson_build +%py3_build %install %meson_install +%py3_install %check diff --git a/src/bindings/python/pyhirte/ext.py b/src/bindings/python/pyhirte/ext.py index 9e8a45a363..53e6c0e50f 100644 --- a/src/bindings/python/pyhirte/ext.py +++ b/src/bindings/python/pyhirte/ext.py @@ -1,7 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later from dasbus.connection import MessageBus -from typing import Callable, List, NamedTuple +from typing import Callable, List, NamedTuple, Tuple from collections import namedtuple from dasbus.loop import EventLoop from dasbus.typing import UInt32, ObjPath @@ -35,10 +35,13 @@ ], ) +def unit_changes_from_tuples(tuples: List[Tuple[str, str, str]]) -> List[UnitChange]: + changes: List[UnitChange] = [] + for change in tuples: + changes.append(UnitChange(change[0], change[1], change[2])) + return changes -class EnableUnitsResponse(NamedTuple): - carries_install_info: bool - changes: List[UnitChange] +EnableUnitsResponse = NamedTuple("EnableUnits", carries_install_info=bool, changes=List[UnitChange]) class Unit: @@ -82,7 +85,8 @@ def reload_unit(self, unit: str) -> str: return self._wait_for_complete(self.node.reload_unit, unit) def enable_unit_files(self, files: List[str]) -> EnableUnitsResponse: - return self.node.enable_unit_files(files, False, False) + resp = self.node.enable_unit_files(files, False, False) + return EnableUnitsResponse(resp[0], unit_changes_from_tuples(resp[1])) def disable_unit_files(self, files: List[str]) -> List[UnitChange]: - return self.node.disable_unit_files(files, False) + return unit_changes_from_tuples(self.node.disable_unit_files(files, False)) diff --git a/src/bindings/python/pyproject.toml b/src/bindings/python/pyproject.toml deleted file mode 100644 index 3e85443b32..0000000000 --- a/src/bindings/python/pyproject.toml +++ /dev/null @@ -1,26 +0,0 @@ -[build-system] -requires = ["setuptools", "setuptools-scm"] -build-backend = "setuptools.build_meta" - -[project] -name = "pyhirte" -authors = [ - {name = "Hirte developers"} -] -description = "Python bindings for hirte's D-Bus API" -readme = "README.md" -version = "0.4.0" -license = { text = "GPL-2.0-or-later" } -dependencies = [ - "dasbus>=1.7", -] -keywords = ["hirte", "python", "D-Bus"] -classifiers = [ - "Programming Language :: Python", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", -] - -[tool.setuptools.packages.find] -include = ["pyhirte*"] diff --git a/src/bindings/python/pyproject.toml.in b/src/bindings/python/pyproject.toml.in deleted file mode 100644 index 9f352abc05..0000000000 --- a/src/bindings/python/pyproject.toml.in +++ /dev/null @@ -1,26 +0,0 @@ -[build-system] -requires = ["setuptools", "setuptools-scm"] -build-backend = "setuptools.build_meta" - -[project] -name = "pyhirte" -authors = [ - {name = "Hirte developers"} -] -description = "Python bindings for hirte's D-Bus API" -readme = "README.md" -version = "@VERSION@" -license = { text = "GPL-2.0-or-later" } -dependencies = [ - "dasbus>=1.7", -] -keywords = ["hirte", "python", "D-Bus"] -classifiers = [ - "Programming Language :: Python", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", -] - -[tool.setuptools.packages.find] -include = ["pyhirte*"] diff --git a/src/bindings/python/setup.py b/src/bindings/python/setup.py new file mode 100644 index 0000000000..0ab5e10634 --- /dev/null +++ b/src/bindings/python/setup.py @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +from setuptools import setup, find_packages + + +def readme(): + with open("README.md") as desc: + return desc.read() + + +setup( + name="pyhirte", + version="0.4.0", + description="Python bindings for hirte's D-Bus API", + long_description=readme(), + author="Hirte developers", + url="https://github.com/containers/hirte/", + license="LGPL-2.0-or-later", + install_requires=[ + "dasbus", + ], + packages=find_packages(), + include_package_data=True, + package_data={"hirte": ["py.typed"]}, + zip_safe=True, + keywords=['hirte', 'python', 'D-Bus', 'systemd'], + classifiers=[ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + ], + python_requires='>=3.9', +) \ No newline at end of file diff --git a/src/bindings/python/setup.py.in b/src/bindings/python/setup.py.in new file mode 100644 index 0000000000..4afc59cd4e --- /dev/null +++ b/src/bindings/python/setup.py.in @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +from setuptools import setup, find_packages + + +def readme(): + with open("README.md") as desc: + return desc.read() + + +setup( + name="pyhirte", + version="@VERSION@", + description="Python bindings for hirte's D-Bus API", + long_description=readme(), + author="Hirte developers", + url="https://github.com/containers/hirte/", + license="LGPL-2.0-or-later", + install_requires=[ + "dasbus", + ], + packages=find_packages(), + include_package_data=True, + package_data={"hirte": ["py.typed"]}, + zip_safe=True, + keywords=['hirte', 'python', 'D-Bus', 'systemd'], + classifiers=[ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + ], + python_requires='>=3.9', +) \ No newline at end of file