Skip to content

Install

Install files needed for building sites.

install(opt)

Install package files.

Source code in mccole/install.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def install(opt):
    """Install package files."""
    outdir = Path(opt.root)
    outdir.mkdir(parents=True, exist_ok=True)
    root = importlib.resources.files(__name__.split(".")[0])
    mapping = {
        root.joinpath(filename): outdir.joinpath(Path(filename))
        for filename in INSTALL_FILES
    }

    exists = {str(dst) for dst in mapping.values() if dst.exists()}
    if exists and (not opt.force):
        print(f'not overwriting {", ".join(sorted(exists))} (use --force)', file=sys.stderr)
        sys.exit(1)

    for src, dst in mapping.items():
        dst.parent.mkdir(parents=True, exist_ok=True)
        dst.write_bytes(src.read_bytes())

parse_args(parser)

Parse command-line arguments.

Source code in mccole/install.py
38
39
40
41
42
def parse_args(parser):
    """Parse command-line arguments."""
    parser.add_argument("--force", action="store_true", help="overwrite")
    parser.add_argument("--root", type=str, default=".", help="root directory")
    return parser