[projects/git-slug] Migracja build systemu z distutils na hatchling (PEP 517/621)

arekm arekm at pld-linux.org
Tue May 12 15:08:40 CEST 2026


commit 2544413ad151eca0f7723513b61cf5c149ac8713
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Mon Apr 6 23:50:23 2026 +0200

    Migracja build systemu z distutils na hatchling (PEP 517/621)
    
    distutils usunięty z Pythona 3.12. pyproject.toml zastępuje setup.py
    jako jedyne źródło metadanych pakietu. Wersja czytana z metadata
    przez importlib.metadata. Wheel zawiera tylko klienta (slug.py +
    git_slug/), pliki serwerowe w sdist dla RPM.

 .gitignore     |  3 +++
 Makefile       |  9 +++++++--
 pyproject.toml | 39 +++++++++++++++++++++++++++++++++++++++
 setup.py       | 26 --------------------------
 slug.py        |  7 ++++++-
 5 files changed, 55 insertions(+), 29 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 730a9d2..95e5369 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,6 @@ MANIFEST
 .pytest_cache/
 __pycache__/
 *.swp
+*.egg-info/
+dist/
+build/
diff --git a/Makefile b/Makefile
index ee99658..48bc5e0 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,11 @@ INSTALL = install
 MANDIR = /usr/share/man
 MANPAGES = doc/man/slug.1 doc/man/slug_watch.1
 
+all: dist
+
+dist:
+	$(PYTHON) -m build
+
 man: $(MANPAGES)
 
 man-install: $(MANPAGES)
@@ -25,6 +30,6 @@ test:
 	$(PYTHON) -m pytest
 
 clean:
-	rm -f doc/man/*.xml $(MANPAGES)
+	rm -rf dist doc/man/*.xml $(MANPAGES)
 
-.PHONY: man man-install clean test
+.PHONY: all dist man man-install clean test
diff --git a/pyproject.toml b/pyproject.toml
index 47743ce..eeff36f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,3 +1,42 @@
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
+[project]
+name = "git-core-slug"
+version = "0.2.0"
+description = "Scripts to interact with PLD git repos"
+readme = "README.md"
+license = "GPL-2.0-only"
+requires-python = ">= 3.9"
+authors = [
+    { name = "Kacper Kornet", email = "draenog at pld-linux.org" },
+]
+classifiers = [
+    "Programming Language :: Python :: 3",
+]
+
+[project.scripts]
+git-pld = "slug:main"
+
+[project.optional-dependencies]
+test = ["pytest >= 8.0", "pytest-cov", "pytest-benchmark"]
+
+[tool.hatch.build.targets.wheel]
+include = ["slug.py", "git_slug/"]
+
+[tool.hatch.build.targets.sdist]
+include = [
+    "slug.py",
+    "git_slug/",
+    "server/",
+    "doc/",
+    "tests/",
+    "Makefile",
+    "COPYING",
+    "README.md",
+]
+
 [tool.pytest.ini_options]
 minversion = "8.0"
 testpaths = ["tests"]
diff --git a/setup.py b/setup.py
deleted file mode 100644
index e3ad592..0000000
--- a/setup.py
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/python3
-
-from distutils.core import setup
-from distutils.command.install_data import install_data
-import os
-
-class post_install(install_data):
-    def run(self):
-        super().run()
-        dirfd =os.open(os.path.join(self.install_dir, self.data_files[0][0]), os.O_RDONLY)
-        os.symlink('move', 'copy', dir_fd=dirfd)
-        os.close(dirfd)
-
-
-setup(name='git-core-slug',
-      version='0.15.2',
-      description='Scripts to interact with PLD git repos',
-      author='Kacper Kornet',
-      author_email='draenog at pld-linux.org',
-      url='https://github.com/draenog/slug',
-      classifiers=['Programming Language :: Python :: 3'],
-      packages=['git_slug'],
-      data_files=[('adc/bin', ['server/adc/trash', 'server/adc/move'])],
-      scripts=['slug.py', 'server/slug_watch/slug_watch'],
-      cmdclass={"install_data": post_install}
-     )
diff --git a/slug.py b/slug.py
index 7454710..35b6489 100755
--- a/slug.py
+++ b/slug.py
@@ -12,7 +12,12 @@
 # command) positionally, just like 'git -C dir pull -q' separates git-core
 # options from git-pull options.
 
-__version__ = '0.15.1'
+# Version is defined in pyproject.toml; read it from installed package metadata.
+from importlib.metadata import version as _metadata_version, PackageNotFoundError
+try:
+    __version__ = _metadata_version('git-core-slug')
+except PackageNotFoundError:
+    __version__ = 'dev'
 
 import copy
 import glob
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/git-slug.git/commitdiff/4a7e426b8f1a3571094b5dc89412bc49b8f29666



More information about the pld-cvs-commit mailing list