Skip to content

Commit

Permalink
Merge pull request #76 from adfinis/jlf/build-build-venv-based-python…
Browse files Browse the repository at this point in the history
…-for-el9

build: build venv based python for el9
  • Loading branch information
Jean-Louis Fuchs authored Mar 5, 2024
2 parents d73c1a2 + cd37105 commit 9864334
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ build-packages: poetry-install ## build source package, wheel and srpm

.PHONY: rebuild-packages
rebuild-packages: ## build binary rpms
@docker run -v ./:/source rockylinux:9 /source/tools/venv-rpm
@docker run -v ./:/source fedora:39 /source/tools/rebuild-rpm
@docker run -v ./:/source fedora:40 /source/tools/rebuild-rpm
#@docker run -v ./:/source rockylinux:9 /source/tools/rebuild-rpm
73 changes: 73 additions & 0 deletions tools/venv-rpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
import os
import shutil
from datetime import datetime
from pathlib import Path
from subprocess import PIPE, run

SPEC = """
Name: python3-pyaptly
Version: 2.0.0^{revision}
Release: 1%{{?dist}}
Summary: Automates the creation and managment of aptly mirrors and snapshots based on yml input files
License: AGPL-3.0-or-later
BuildArch: noarch
Requires: python3.11
%description
Automates the creation and managment of aptly mirrors and snapshots based on yml input files
%install
rm -rf /opt/pyaptly
python3.11 -m venv /opt/pyaptly
(source /opt/pyaptly/bin/activate
pip install -r /root/requirements.txt)
mkdir -p ${{RPM_BUILD_ROOT}}/opt
cp -r --preserve=links /opt/pyaptly/ ${{RPM_BUILD_ROOT}}/opt/pyaptly/
mkdir -p ${{RPM_BUILD_ROOT}}/usr/bin
ln -s /opt/pyaptly/bin/pyaptly ${{RPM_BUILD_ROOT}}/usr/bin/pyaptly
rm -rf /opt/pyaptly
%files
/usr/bin/pyaptly
/opt/pyaptly
%changelog
* {date} Package Robot <package@robot.nowhere> - 2.0.0^alpha
- Automatic build of revision {revision}
"""


def main():
os.chdir("/source")
macros = Path("/root/.rpmmacros")
with macros.open("w", encoding="UTF-8") as f:
f.write("%_binaries_in_noarch_packages_terminate_build 0")
f.write("\n")
run(["dnf", "install", "-y", "rpm-build", "python3.11", "git"], check=True)
date = datetime.now().strftime("%a %b %d %Y")
build_id = run(
["git", "rev-parse", "--short", "HEAD"],
stdout=PIPE,
check=True,
encoding="UTF-8",
).stdout.strip()
dist = Path("/source/dist")
package = str(list(dist.glob("pyaptly-*-py3-none-any.whl"))[0])
req = Path("/root/requirements.txt")
with req.open("w", encoding="UTF-8") as f:
f.write(package)
f.write("\n")
spec = Path("/root/venv.spec")
with spec.open("w", encoding="UTF-8") as f:
f.write(SPEC.format(revision=build_id, date=date))
shutil.rmtree("/root/rpmbuild", ignore_errors=True)
run(["rpmbuild", "--bb", spec], check=True)
rpms = Path("/root/rpmbuild/RPMS/noarch")
file = Path(list(rpms.glob("python3-pyaptly-*.noarch.rpm"))[0])
shutil.copy2(file, dist)


if __name__ == "__main__":
main()

0 comments on commit 9864334

Please sign in to comment.