pthbs_genpkgpy

Template engine for producing packages for pthbs written using Python and Jinja
git clone https://ccx.te2000.cz/git/pthbs_genpkgpy
Log | Files | Refs | Submodules | README

commit b15529ebde7867aaf9779ecfcd2fbbace7472edb
parent c527d99c579b78f51dea4243ce9bed701fab8d47
Author: ccx <ccx@te2000.cz>
Date:   Thu, 17 Oct 2024 03:58:30 +0000

Adapt to inherited variables, separate Makefile entry point for formatting

Diffstat:
AMakefile | 2++
Mgenpkg.py | 19++++++++++++++-----
Mgenpkgpy.mk | 26++++++++++++++------------
Mmake_vars.py | 19++++++++++++++++---
Apy-cp312-cp312-musllinux_1_2_x86_64-requirements.txt | 38++++++++++++++++++++++++++++++++++++++
5 files changed, 84 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile @@ -0,0 +1,2 @@ +default: pycodestyle +include genpkgpy.mk diff --git a/genpkg.py b/genpkg.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import argparse import hashlib import os.path import subprocess @@ -11,7 +12,7 @@ import yaml class SubmoduleInfo: def __init__(self): self._current_commits = None - self._by_commit = Path('./sources/by-commit') + self._by_commit = Path('./sources/by-commit') # TODO: configurable @property def current(self): @@ -40,10 +41,11 @@ class SubmoduleInfo: ).decode('utf8') return out + class DownloadsInfo: def __init__(self): self._basenames = {} - with open('downloadlist.sha256', 'rt') as f: + with open('downloadlist.sha256', 'rt') as f: # TODO: configurable for line in f: if line[0] in '#\n': continue @@ -68,7 +70,7 @@ class DownloadsInfo: class FileInfo: def __init__(self): self._sha256_cache = {} - self._files_dir = Path('./files') + self._files_dir = Path('./files') # TODO: configurable def __getitem__(self, key): if key in self._sha256_cache: @@ -112,7 +114,9 @@ class Main: else: self.deps[current].add(name) self._pkg_sha256(name) - envlist = ''.join(sorted('%s.%s\n' % (d, self.package_hashes[d]) for d in self.deps[name])) + envlist = ''.join( + sorted('%s.%s\n' % (d, self.package_hashes[d]) for d in self.deps[name]) + ) return hashlib.sha256(envlist.encode()).hexdigest() def pkg_sha256(self, name): @@ -182,10 +186,15 @@ class Main: ) +argument_parser = argparse.ArgumentParser() +argument_parser.add_argument('-P', '--package-dir', default='packages') +argument_parser.add_argument('-T', '--template-dir', default='templates') + if __name__ == '__main__': from pprint import pprint as pp - m = Main() + args = argument_parser.parse_args() + m = Main(out_dir=args.package_dir, template_dir=args.template_dir) m.load_vars_yaml() pp(m.env.list_templates(filter_func=lambda name: "/." not in name)) m.render_all() diff --git a/genpkgpy.mk b/genpkgpy.mk @@ -1,19 +1,21 @@ -PYTHONPATH:=$(abspath .) -PYTHON_EXE:=python3 +PYTHON_EXE?=python3 +pthbs_genpkgpy:=. +cache?=../cache + # re-evaluate each time because there's no sensible way to check # whether the python interpreter changed -$(eval $(shell $(PYTHON_EXE) $(PTHBS_GENPKGPY)/make_vars.py)) +$(eval $(shell $(PYTHON_EXE) $(pthbs_genpkgpy)/make_vars.py '$(cache)/make')) -PY_SRC:=$(wildcard $(PTHBS_GENPKGPY)/*.py) -PY_REQ:=$(PTHBS_GENPKGPY)/py-$(PYTHON_IMPL)-requirements.txt -PY_WHL:=work/wheels/$(PYTHON_IMPL) -VENV:=work/virtualenvs/$(PYTHON_IMPL) +PY_SRC:=$(wildcard $(pthbs_genpkgpy)/*.py) +PY_REQ:=$(pthbs_genpkgpy)/py-$(PYTHON_IMPL)-requirements.txt +PY_WHL:=$(cache)/wheels/$(PYTHON_IMPL) +VENV:=$(cache)/virtualenvs/$(PYTHON_IMPL) PYTHON_VENV_INSTALL=pip-tools wheel -pycodestyle: $(patsubst %.py,.%.pyfmt,$(PY_SRC)) $(VENV)/.done +pycodestyle: $(patsubst $(pthbs_genpkgpy)/%.py,$(pthbs_genpkgpy)/.%.pyfmt,$(PY_SRC)) $(VENV)/.done '$(VENV)/bin/pylama' -l 88 $(PY_SRC) || true -$(PTHBS_GENPKGPY)/.%.pyfmt: $(PTHBS_GENPKGPY)/%.py $(VENV)/.done +$(pthbs_genpkgpy)/.%.pyfmt: $(pthbs_genpkgpy)/%.py $(VENV)/.done '$(VENV)/bin/isort' - <'$<' >'$<.tmp1' cp -a '$<' '$<.tmp2' '$(VENV)/bin/black' -S - <'$<.tmp1' >'$<.tmp2' @@ -31,11 +33,11 @@ py-venv: $(VENV)/.done py-virtualenv: py-venv py-genpkg: $(VENV)/.done - '$(VENV)/bin/python' genpkg.py + '$(VENV)/bin/python' genpkg.py --package-dir='$(packages)' --template-dir='$(templates)' # -- requirement file rules -$(PY_REQ): $(PTHBS_GENPKGPY)/py-requirements.in $(VENV)/bin/pip-compile +$(PY_REQ): $(pthbs_genpkgpy)/py-requirements.in $(VENV)/bin/pip-compile '$(VENV)/bin/pip-compile' -v --annotate -o '$@.new' py-requirements.in mv '$@.new' '$@' @@ -56,5 +58,5 @@ $(VENV)/bin/pip-compile $(VENV)/bin/pip-sync: $(VENV)/.done: $(PY_REQ) $(VENV)/bin/pip-sync $(PY_WHL)/.done $(VENV)/bin/pip-sync --no-index -f '$(PY_WHL)' '$(PY_REQ)' - ln -sf 'virtualenvs/$(PYTHON_IMPL)' work/venv + ln -sf 'virtualenvs/$(PYTHON_IMPL)' '$(cache)/venv' touch '$@' diff --git a/make_vars.py b/make_vars.py @@ -8,6 +8,7 @@ from __future__ import ( with_statement, ) +import os import sys try: @@ -40,9 +41,10 @@ except ImportError: PY2 = sys.version_info[0] == 2 -def main(): +def main(mk_dir): tag = '%s-%s-%s' % get_tag() - mk_filename = 'make/python_vars_%s.mk' % tag + mk_filename = '%s/python_vars_%s.mk' % (mk_dir, tag) + os.makedirs(mk_dir, exist_ok=True) with open(mk_filename, 'wt') as f: # TODO: add proper escaping whenever I feel like staring into the abyss f.write('PYTHON_IMPL:=%s\n' % tag) @@ -63,8 +65,19 @@ def main(): print("include %s" % mk_filename) +def usage(exitcode=100): + sys.stderr.write('usage: make_vars.py directory\n') + sys.exit(exitcode) + + if __name__ == '__main__': - main() + if len(sys.argv) < 2: + sys.stderr.write('make_vars.py: fatal: too few arguments\n') + usage() + if len(sys.argv) > 2: + sys.stderr.write('make_vars.py: fatal: too many arguments\n') + usage() + main(sys.argv[1]) # pylama:linters=pycodestyle,pyflakes:ignore=D212,D203,D100,D101,D102,D107 # vim: fileencoding=utf-8 ft=python et sw=4 ts=4 sts=4 tw=79 diff --git a/py-cp312-cp312-musllinux_1_2_x86_64-requirements.txt b/py-cp312-cp312-musllinux_1_2_x86_64-requirements.txt @@ -0,0 +1,38 @@ +# +# This file is autogenerated by pip-compile with Python 3.12 +# by the following command: +# +# pip-compile --output-file=py-cp312-cp312-musllinux_1_2_x86_64-requirements.txt.new py-requirements.in +# +black==24.10.0 + # via -r py-requirements.in +click==8.1.7 + # via black +isort==5.13.2 + # via -r py-requirements.in +jinja2==3.1.4 + # via -r py-requirements.in +markupsafe==3.0.1 + # via jinja2 +mccabe==0.7.0 + # via pylama +mypy-extensions==1.0.0 + # via black +packaging==24.1 + # via black +pathspec==0.12.1 + # via black +platformdirs==4.3.6 + # via black +pycodestyle==2.12.1 + # via pylama +pydocstyle==6.3.0 + # via pylama +pyflakes==3.2.0 + # via pylama +pylama==8.4.1 + # via -r py-requirements.in +pyyaml==6.0.2 + # via -r py-requirements.in +snowballstemmer==2.2.0 + # via pydocstyle