package.py (2091B)
1 import asyncio 2 import tempfile 3 import venv 4 5 import make 6 7 8 @make.rule_no_cache 9 async def tmp_venv(_): 10 dir = tempfile.TemporaryDirectory() 11 venv.create(dir.name) 12 packages = ( 13 "build", 14 "hatchling", 15 "pyBake", 16 "aiofiles", 17 ) 18 await make.exec( 19 "pip", 20 "install", 21 "--prefix", 22 dir.name, 23 "--force-reinstall", 24 *packages, 25 echo=make.EchoAll, 26 ) 27 return dir 28 29 30 @make.rule_no_cache 31 async def build(f): 32 dir = (await f(tmp_venv())).name 33 await make.exec( 34 f"{dir}/bin/python", "-m", "build", "--no-isolation", echo=make.EchoAll 35 ) 36 37 38 @make.rule_no_cache 39 async def bake(f): 40 dir = (await f(tmp_venv())).name 41 await make.exec( 42 f"{dir}/bin/python", 43 "-c", 44 """\ 45 #!/usr/bin/env python3 46 from pybake import PyBake 47 48 HEADER = \"""\ 49 ## make.py - Single file version ## 50 \""" 51 52 FOOTER = \"""\ 53 from make import * ## 54 import aiofiles ## 55 \""" 56 57 pb = PyBake(HEADER, FOOTER) 58 import make 59 import aiofiles 60 61 pb.add_module(make) 62 pb.add_module(aiofiles) 63 64 import os 65 66 os.makedirs("dist", exist_ok=True) 67 pb.write_bake("dist/make.py") 68 os.chmod("dist/make.py", 0o644) 69 """, 70 echo=make.EchoAll, 71 ) 72 73 74 @make.rule_no_cache 75 async def tag_release(f, *tasks): 76 if (await make.exec("git", "status", "--porcelain")).stdout: 77 raise RuntimeError("Working directory not clean") 78 branch, *_ = await asyncio.gather( 79 make.exec("git", "branch", "--show-current"), 80 *(f(t) for t in tasks), 81 ) 82 await make.shell( 83 f"""\ 84 git switch --detach 85 git add --force dist 86 git commit -m 'Build packages' 87 git tag --force nightly 88 git switch '{branch.utf8stdout.strip()}' 89 """, 90 echo=make.EchoAll, 91 ) 92 93 94 @make.rule_no_cache 95 def all(f): 96 return asyncio.gather(f(build()), f(bake())) 97 98 99 if __name__ == "__main__": 100 exit(make.main(globals()))