34 lines
1.5 KiB
Python
34 lines
1.5 KiB
Python
"""Build two FreeBSD Python zipapps; use grpcio-tools 1.76.0 + protobuf 6.33.5."""
|
|
import importlib.metadata as metadata
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import zipapp
|
|
|
|
here = Path(__file__).resolve().parent
|
|
out = Path(sys.argv[1])
|
|
out.mkdir(exist_ok=True, parents=True)
|
|
if metadata.version('protobuf') != '6.33.5' or metadata.version('grpcio-tools') != '1.76.0':
|
|
sys.exit('Unexpected protocol builder dependencies')
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
work = Path(tmp)
|
|
proto = here.parents[1]/'proto'
|
|
subprocess.run([sys.executable,'-m','grpc_tools.protoc','-I'+str(proto),'--python_out='+tmp,
|
|
str(proto/'agent.proto')],check=True)
|
|
dist = metadata.distribution('protobuf')
|
|
for f in dist.files:
|
|
if str(f).startswith('google/protobuf/') and f.suffix == '.py':
|
|
dst = work/f
|
|
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(dist.locate_file(f), dst)
|
|
(work/'google/__init__.py').touch()
|
|
license_file = next(f for f in dist.files if f.name=='LICENSE' and '.dist-info/' in str(f))
|
|
shutil.copyfile(dist.locate_file(license_file),work/'LICENSE-protobuf')
|
|
shutil.copyfile(here/'agent.py',work/'__main__.py')
|
|
zipapp.create_archive(work,out/'agent.pyz',compressed=True)
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
shutil.copyfile(here/'collect.py',Path(tmp)/'__main__.py')
|
|
zipapp.create_archive(tmp,out/'collect.pyz',compressed=True)
|