def pack(ctx, remove_lib=True):
    """Build a isolated runnable package.
    """
    OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
    with ROOT.joinpath('Pipfile.lock').open() as f:
        lockfile = plette.Lockfile.load(f)

    libdir = OUTPUT_DIR.joinpath('lib')

    paths = {'purelib': libdir, 'platlib': libdir}
    sources = lockfile.meta.sources._data
    maker = distlib.scripts.ScriptMaker(None, None)

    # Install packages from Pipfile.lock.
    for name, package in lockfile.default._data.items():
        if name in DONT_PACKAGE:
            continue
        print(f'[pack] Installing {name}')
        package.pop('editable', None)   # Don't install things as editable.
        package.pop('markers', None)    # Always install everything.
        r = requirementslib.Requirement.from_pipfile(name, package)
        wheel = passa.internals._pip.build_wheel(
            r.as_ireq(), sources, r.hashes or None,
        )
        wheel.install(paths, maker, lib_only=True)

    for pattern in IGNORE_LIB_PATTERNS:
        for path in libdir.rglob(pattern):
            print(f'[pack] Removing {path}')
            path.unlink()

    # Pack everything into ZIP.
    zipname = OUTPUT_DIR.joinpath('passa.zip')
    with zipfile.ZipFile(zipname, 'w') as zf:
        _recursive_write_to_zip(zf, OUTPUT_DIR)
        _recursive_write_to_zip(zf, STUBFILES_DIR)
    print(f'[pack] Written archive {zipname}')

    if remove_lib and libdir.exists():
        print(f'[pack] Removing {libdir}')
        shutil.rmtree(str(libdir))
Build a isolated runnable package.