usrbinenv python 2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license write first n lines of each file f in srcdir to destdirf srcdir pathsrcdir destdir pathdestdir destdir mkdirexistoktrue for path in srcdir iterdir new x rstrip for x in listpath open readlines n destpath destdir joinpathpath name printdestpath destpath openw writen joinnew if name main fire fireminify usr bin env python 2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license write first n lines of each file f in src_dir to dest_dir f
from pathlib import Path

import fire


def minify(src_dir: str, dest_dir: str, n: int):
    
    src_dir = Path(src_dir)
    dest_dir = Path(dest_dir)
    dest_dir.mkdir(exist_ok=True)
    for path in src_dir.iterdir():
        new = [x.rstrip() for x in list(path.open().readlines())][:n]
        dest_path = dest_dir.joinpath(path.name)
        print(dest_path)
        dest_path.open("w").write("\n".join(new))


if __name__ == "__main__":
    fire.Fire(minify)