Commit 88a883db authored by Julien Muchembled's avatar Julien Muchembled

Switch to hatchling

Because of https://github.com/pypa/pip/issues/10978,
`make install` is currently unable to install the Python code
to a custom prefix (PREFIX).
parent e78e8762
Pipeline #37943 passed with stage
in 0 seconds
*.pyc
*.pyo
*.swp
*~
/build/
/dist/ /dist/
/re6stnet.egg-info/
*.log
*.pid
*.db
*.state
*.crt
*.pem
demo/mbox
*.sock
DESTDIR = / DESTDIR = /
# https://github.com/pypa/pip/issues/10978
PREFIX = /usr/local PREFIX = /usr/local
MANDIR = $(PREFIX)/share/man MANDIR = $(PREFIX)/share/man
UNITDIR = /lib/systemd/system UNITDIR = $(PREFIX)/lib/systemd/system
PYTHON = $(or $(shell command -v python2),python) PIP_INSTALL = python3 -m pip install
MANPAGELIST := $(patsubst %,docs/%,re6st-conf.1 re6st-registry.1 re6stnet.8) MANPAGELIST := $(patsubst %,docs/%,re6st-conf.1 re6st-registry.1 re6stnet.8)
...@@ -18,7 +19,7 @@ install: install-noinit ...@@ -18,7 +19,7 @@ install: install-noinit
install-noinit: install-man install-noinit: install-man
set -e $(DESTDIR)$(PREFIX) /bin/re6stnet; [ -x $$1$$2 ] || \ 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 -d $$1/sbin; mv $$1$$2 $$1/sbin
install -Dpm 0644 daemon/README.conf $(DESTDIR)/etc/re6stnet/README install -Dpm 0644 daemon/README.conf $(DESTDIR)/etc/re6stnet/README
install -Dpm 0644 daemon/logrotate.conf $(DESTDIR)/etc/logrotate.d/re6stnet install -Dpm 0644 daemon/logrotate.conf $(DESTDIR)/etc/logrotate.d/re6stnet
...@@ -29,5 +30,4 @@ install-man: $(MANPAGELIST) ...@@ -29,5 +30,4 @@ install-man: $(MANPAGELIST)
done done
clean: clean:
find -name '*.pyc' -delete find -name __pycache__ -print0 |xargs -0 rm -rf dist $(MANPAGELIST)
rm -rf build dist re6stnet.egg-info $(MANPAGELIST)
...@@ -15,10 +15,4 @@ debian/changelog: ...@@ -15,10 +15,4 @@ debian/changelog:
echo "$$CHANGELOG" >$@ echo "$$CHANGELOG" >$@
endif endif
override_dh_install: override_dh_auto_test:
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
...@@ -2,15 +2,15 @@ Source: re6stnet ...@@ -2,15 +2,15 @@ Source: re6stnet
Maintainer: Julien Muchembled <jm@nexedi.com> Maintainer: Julien Muchembled <jm@nexedi.com>
Section: net Section: net
Priority: optional Priority: optional
Build-Depends: debhelper (>= 9.20120909), debhelper (>= 10) | dh-systemd, python (>= 2.7), python-setuptools, python-docutils | python3-docutils Build-Depends: debhelper-compat (= 13), pybuild-plugin-pyproject, python3, python3-hatchling, python3-docutils
Standards-Version: 3.9.1 Standards-Version: 4.7.0
X-Python-Version: >= 2.7 X-Python3-Version: >= 3.11
Package: re6stnet Package: re6stnet
Architecture: all 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 Depends: ${misc:Depends}, ${python3:Depends}, python3-openssl (>= 0.13), openvpn (>= 2.4), openpvn (<< 2.5~), babeld (= 1.12.1+nxd3), iproute2, openssl
Recommends: ${python:Recommends}, logrotate Recommends: ${python3:Recommends}, logrotate
Suggests: ${python:Suggests}, ndisc6 Suggests: ${python3:Suggests}, ndisc6
Conflicts: re6st-node Conflicts: re6st-node
Replaces: re6st-node Replaces: re6st-node
Description: resilient, scalable, IPv6 network application Description: resilient, scalable, IPv6 network application
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# -*- makefile -*- # -*- makefile -*-
#export DH_VERBOSE=1 #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 # In order to build DEB snapshot package whose version is derived from current
# Git revision, the `debian/changelog` file must be generated automatically, # Git revision, the `debian/changelog` file must be generated automatically,
...@@ -13,15 +13,18 @@ build-package: debian/changelog ...@@ -13,15 +13,18 @@ build-package: debian/changelog
include debian/common.mk include debian/common.mk
override_dh_python2: override_dh_python3:
sed -i /^miniupnpc$$/d `find $(TMP)/usr -name requires.txt` dh_python3 --no-guessing-deps --recommends=miniupnpc --suggests=geoip2
dh_python2 --recommends=miniupnpc --suggests=geoip2
override_dh_auto_clean: override_dh_auto_clean:
dh_auto_clean
make clean make clean
# Do not build twice ('setup.py install' builds automatically) override_dh_auto_install:
override_dh_auto_build: 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
dnsmasq.leases
*.log
*.pid
*.db
*.state
*.crt
*.pem
/mbox
*.sock
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()
[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
"""Resilient, Scalable, IPv6 Network
"""
import os, stat
from distutils.command.build_scripts import first_line_re
from setuptools import setup, find_packages
from setuptools.command import sdist as _sdist, build_py as _build_py
from distutils import log
version = {"__file__": "re6st/version.py"}
with open(version["__file__"]) as f:
code = compile(f.read(), version["__file__"], 'exec')
exec(code, version)
def copy_file(self, infile, outfile, *args, **kw):
if infile == version["__file__"]:
if not self.dry_run:
log.info("generating %s -> %s", infile, outfile)
with open(outfile, "w") as f:
for x in sorted(version.items()):
if not x[0].startswith("_"):
f.write("%s = %r\n" % x)
return outfile, 1
elif isinstance(self, build_py) and \
os.stat(infile).st_mode & stat.S_IEXEC:
if os.path.isdir(infile) and os.path.isdir(outfile):
return outfile, 0
# Adjust interpreter of OpenVPN hooks.
with open(infile) as src:
first_line = src.readline()
m = first_line_re.match(first_line)
if m and not self.dry_run:
log.info("copying and adjusting %s -> %s", infile, outfile)
executable = self.distribution.command_obj['build'].executable
patched = "#!%s%s\n" % (executable, m.group(1) or '')
patched += src.read()
dst = os.open(outfile, os.O_CREAT | os.O_WRONLY | os.O_TRUNC)
try:
os.write(dst, patched.encode())
finally:
os.close(dst)
return outfile, 1
cls, = self.__class__.__bases__
return cls.copy_file(self, infile, outfile, *args, **kw)
class build_py(_build_py.build_py):
copy_file = copy_file
class sdist(_sdist.sdist):
copy_file = copy_file
classifiers = """\
Environment :: Console
License :: OSI Approved :: GNU General Public License (GPL)
Natural Language :: English
Operating System :: POSIX :: Linux
Programming Language :: Python :: 3
Programming Language :: Python :: 3.11
Topic :: Internet
Topic :: System :: Networking
"""
egg_version = "0.%(revision)s" % version
git_rev = """
Git Revision: %s == %s
""" % (egg_version, version["short"])
setup(
name = 're6stnet',
version = egg_version,
description = __doc__.strip(),
author = 'Nexedi',
author_email = 're6stnet@erp5.org',
url = 'http://re6st.net',
license = 'GPL 2+',
platforms = ["any"],
classifiers=classifiers.splitlines(),
python_requires = '>=3.11',
long_description = ".. contents::\n\n" + open('README.rst').read()
+ "\n" + open('CHANGES.rst').read() + git_rev,
packages = find_packages(),
entry_points = {
'console_scripts': [
're6st-conf=re6st.cli.conf:main',
're6stnet=re6st.cli.node:main',
're6st-registry=re6st.cli.registry:main',
],
},
package_data = {
're6st': [
'ovpn-server',
'ovpn-client',
],
},
# BBB: use MANIFEST.in only so that egg_info works with very old setuptools
include_package_data = True,
install_requires = ['pyOpenSSL >= 0.13', 'miniupnpc'],
extras_require = {
'geoip': ['geoip2'],
'multicast': ['PyYAML'],
'test': ['mock', 'nemu3', 'unshare', 'multiping']
},
#dependency_links = [
# "http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.7.20120714.tar.gz#egg=miniupnpc-1.7",
# ],
zip_safe = False,
cmdclass=dict(build_py=build_py, sdist=sdist),
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment