Skip to content

Commit

Permalink
Switch to hatchling
Browse files Browse the repository at this point in the history
Because of pypa/pip#10978,
`make install` is currently unable to install the Python code
to a custom prefix (PREFIX).
  • Loading branch information
jmuchemb committed Nov 2, 2024
1 parent e78e876 commit 88a883d
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 149 deletions.
14 changes: 0 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
*.pyc
*.pyo
*.swp
*~
/build/
/dist/
/re6stnet.egg-info/
*.log
*.pid
*.db
*.state
*.crt
*.pem
demo/mbox
*.sock
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
DESTDIR = /
# https://github.com/pypa/pip/issues/10978
PREFIX = /usr/local
MANDIR = $(PREFIX)/share/man
UNITDIR = /lib/systemd/system
PYTHON = $(or $(shell command -v python2),python)
UNITDIR = $(PREFIX)/lib/systemd/system
PIP_INSTALL = python3 -m pip install

MANPAGELIST := $(patsubst %,docs/%,re6st-conf.1 re6st-registry.1 re6stnet.8)

Expand All @@ -18,7 +19,7 @@ install: install-noinit

install-noinit: install-man
set -e $(DESTDIR)$(PREFIX) /bin/re6stnet; [ -x $$1$$2 ] || \
$(PYTHON) setup.py install --prefix=$(PREFIX) --root=$(DESTDIR); \
{ [ "$(PREFIX)" = /usr/local ]; $(PIP_INSTALL) --root=$(DESTDIR) .; }; \
install -d $$1/sbin; mv $$1$$2 $$1/sbin
install -Dpm 0644 daemon/README.conf $(DESTDIR)/etc/re6stnet/README
install -Dpm 0644 daemon/logrotate.conf $(DESTDIR)/etc/logrotate.d/re6stnet
Expand All @@ -29,5 +30,4 @@ install-man: $(MANPAGELIST)
done

clean:
find -name '*.pyc' -delete
rm -rf build dist re6stnet.egg-info $(MANPAGELIST)
find -name __pycache__ -print0 |xargs -0 rm -rf dist $(MANPAGELIST)
8 changes: 1 addition & 7 deletions debian/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ debian/changelog:
echo "$$CHANGELOG" >$@
endif

override_dh_install:
make DESTDIR=$(TMP) PREFIX=/usr install

# BBB: compat < 10 ; https://bugs.debian.org/879727
override_dh_systemd_start:
dh_systemd_start --restart-after-upgrade
sed -i 's/_dh_action=try-restart/_dh_action=restart; for x in re6stnet re6st-registry; do systemctl is-enabled --quiet $$x.service || &; done/' debian/$(PACKAGE).postinst.debhelper
override_dh_auto_test:
1 change: 0 additions & 1 deletion debian/compat

This file was deleted.

12 changes: 6 additions & 6 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ Source: re6stnet
Maintainer: Julien Muchembled <jm@nexedi.com>
Section: net
Priority: optional
Build-Depends: debhelper (>= 9.20120909), debhelper (>= 10) | dh-systemd, python (>= 2.7), python-setuptools, python-docutils | python3-docutils
Standards-Version: 3.9.1
X-Python-Version: >= 2.7
Build-Depends: debhelper-compat (= 13), pybuild-plugin-pyproject, python3, python3-hatchling, python3-docutils
Standards-Version: 4.7.0
X-Python3-Version: >= 3.11

Package: re6stnet
Architecture: all
Depends: ${misc:Depends}, ${python:Depends}, python-pkg-resources, python-openssl (>= 0.13), openvpn (>= 2.4), openpvn (<< 2.5~), babeld (= v1.12.1-nxd3), iproute2 | iproute, openssl
Recommends: ${python:Recommends}, logrotate
Suggests: ${python:Suggests}, ndisc6
Depends: ${misc:Depends}, ${python3:Depends}, python3-openssl (>= 0.13), openvpn (>= 2.4), openpvn (<< 2.5~), babeld (= 1.12.1+nxd3), iproute2, openssl
Recommends: ${python3:Recommends}, logrotate
Suggests: ${python3:Suggests}, ndisc6
Conflicts: re6st-node
Replaces: re6st-node
Description: resilient, scalable, IPv6 network application
17 changes: 10 additions & 7 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- makefile -*-
#export DH_VERBOSE=1

VERSION = $(shell python re6st/version.py)
VERSION = $(shell python3 re6st/version.py)

# In order to build DEB snapshot package whose version is derived from current
# Git revision, the `debian/changelog` file must be generated automatically,
Expand All @@ -13,15 +13,18 @@ build-package: debian/changelog

include debian/common.mk

override_dh_python2:
sed -i /^miniupnpc$$/d `find $(TMP)/usr -name requires.txt`
dh_python2 --recommends=miniupnpc --suggests=geoip2
override_dh_python3:
dh_python3 --no-guessing-deps --recommends=miniupnpc --suggests=geoip2

override_dh_auto_clean:
dh_auto_clean
make clean

# Do not build twice ('setup.py install' builds automatically)
override_dh_auto_build:
override_dh_auto_install:
dh_auto_install
make DESTDIR=$(TMP) PREFIX=/usr install
find $(TMP)/usr -name 'ovpn-*' -print0 | \
xargs -0 sed -i "1s,.*,#!/usr/bin/python3 -S,"

%:
dh $@ --with python2,systemd --buildsystem=python_distutils
dh $@ --with python3 --buildsystem=pybuild
9 changes: 9 additions & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dnsmasq.leases
*.log
*.pid
*.db
*.state
*.crt
*.pem
/mbox
*.sock
36 changes: 36 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import tempfile
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from hatchling.metadata.plugin.interface import MetadataHookInterface

version = {"__file__": "re6st/version.py"}
with open(version["__file__"]) as f:
code = compile(f.read(), version["__file__"], 'exec')
exec(code, version)


class CustomMetadataHook(MetadataHookInterface):

def update(self, metadata):
metadata['version'] = egg_version = "0.%(revision)s" % version
metadata['readme'] = {
'content-type': 'text/x-rst',
'text': ".. contents::\n\n" + open('README.rst').read()
+ "\n" + open('CHANGES.rst').read() + """
Git Revision: %s == %s
""" % (egg_version, version["short"]),
}


class CustomBuildHook(BuildHookInterface):

def initialize(self, _, build_data):
f = self.__version = tempfile.NamedTemporaryFile('w')
for x in sorted(version.items()):
if not x[0].startswith("_"):
f.write("%s = %r\n" % x)
f.flush()
build_data["force_include"][f.name] = version["__file__"]

def finalize(self, *_):
self.__version.close()
53 changes: 53 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "re6stnet"
description = "Resilient, Scalable, IPv6 Network"
authors = [
{ name = "Nexedi", email = "re6stnet@erp5.org" },
]
license = { text = "GPL-2.0-or-later" }
classifiers = [
"Environment :: Console",
"Operating System :: POSIX :: Linux",
"Topic :: Internet",
"Topic :: System :: Networking",
]
requires-python = ">= 3.11"
dependencies = [
"pyOpenSSL >= 0.13",
"miniupnpc",
]
dynamic = ["readme", "version"]

[project.optional-dependencies]
geoip = ["geoip2"]
multicast = ["PyYAML"]
test = ["mock", "nemu3", "unshare", "multiping"]

[project.scripts]
re6st-conf = "re6st.cli.conf:main"
re6stnet = "re6st.cli.node:main"
re6st-registry = "re6st.cli.registry:main"

[project.urls]
Homepage = "http://re6st.net"

[tool.hatch.metadata.hooks.custom]

[tool.hatch.build.hooks.custom]

[tool.hatch.build]
include = [
"/re6st",
"/docs",
"/*.rst",
]
exclude = [
"/re6st/tests",
]

[tool.hatch.build.targets.wheel]
only-packages = true
109 changes: 0 additions & 109 deletions setup.py

This file was deleted.

0 comments on commit 88a883d

Please sign in to comment.