Cotton code
31 lines · 1.1 KB · PythonRaw
#!/usr/bin/env python3"""Run the pinned holiday generator in an isolated Python process."""from pathlib import Pathimport sysimport tempfileimport zipfilesys.path.insert(0, str(Path(__file__).resolve().parent))import buildsource, destination, digest = sys.argv[1:]source = Path(source)build.verify(source, digest)with tempfile.TemporaryDirectory(dir=source.parent) as work:    wheels = [source]    for pin in build.PINS["holidays"]["dependencies"]:        wheel = source.parent / pin["filename"]        build.verify(wheel, pin["sha256"])        wheels.append(wheel)    for wheel in wheels:        with zipfile.ZipFile(wheel) as archive:            for member in archive.infolist():                target = Path(work) / member.filename                if not target.resolve().is_relative_to(Path(work).resolve()):                    raise ValueError("wheel member escapes build directory")            archive.extractall(work)    sys.path.insert(0, work)    import holidays    db = build.connect(destination, "holidays", digest)    build.populate_holidays(db, holidays, build.PINS["holidays"]["years"])    build.finish(db, "holidays")