aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2022-11-16 14:35:05 +0200
committerArthur Zamarin <arthurzam@gentoo.org>2022-11-16 20:08:28 +0200
commit27dd5ec2b8ca977e0b9711eca0d6cba543743a4e (patch)
treec35b3f648ca6cdb1473f02a5b837a654e81b1f7f /py_build.py
parentcommit: mention `-e` as nice option (diff)
downloadpkgdev-27dd5ec2b8ca977e0b9711eca0d6cba543743a4e.tar.gz
pkgdev-27dd5ec2b8ca977e0b9711eca0d6cba543743a4e.tar.bz2
pkgdev-27dd5ec2b8ca977e0b9711eca0d6cba543743a4e.zip
build backend: use custom wrapper around flit
For pkgcore we need to run multiple preparations of generating files before creating sdist or wheel. Flit is a very simple and nice build backend, much more than setuptools. Also migrate to use snakeoil.dist sphinx extension for generating man and html, to remove various logic from `doc/conf.py`. Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'py_build.py')
-rw-r--r--py_build.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/py_build.py b/py_build.py
new file mode 100644
index 0000000..f224a1b
--- /dev/null
+++ b/py_build.py
@@ -0,0 +1,44 @@
+from functools import partial
+from pathlib import Path
+
+from flit_core import buildapi
+
+
+def write_verinfo(cleanup_files):
+ cleanup_files.append(path := Path.cwd() / "src/pkgdev/_verinfo.py")
+ path.parent.mkdir(parents=True, exist_ok=True)
+ print(f"generating version info: {path}")
+ from snakeoil.version import get_git_version
+ path.write_text(f"version_info={get_git_version(Path.cwd())!r}")
+
+
+def prepare_pkgcore(callback):
+ cleanup_files = []
+ try:
+ write_verinfo(cleanup_files)
+
+ return callback()
+ finally:
+ for path in cleanup_files:
+ try:
+ path.unlink()
+ except OSError:
+ pass
+
+
+def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
+ """Builds a wheel, places it in wheel_directory"""
+ callback = partial(buildapi.build_wheel, wheel_directory, config_settings, metadata_directory)
+ return prepare_pkgcore(callback)
+
+
+def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
+ """Builds an "editable" wheel, places it in wheel_directory"""
+ callback = partial(buildapi.build_editable, wheel_directory, config_settings, metadata_directory)
+ return prepare_pkgcore(callback)
+
+
+def build_sdist(sdist_directory, config_settings=None):
+ """Builds an sdist, places it in sdist_directory"""
+ callback = partial(buildapi.build_sdist, sdist_directory, config_settings)
+ return prepare_pkgcore(callback)