All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
6 from datetime import datetime
7 from pathlib import Path
8 from shutil import rmtree, which
9 from tempfile import gettempdir
10 from typing import Any, Union
14 from black_primer import lib
17 DEFAULT_CONFIG = Path(__file__).parent / "primer.json"
18 _timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
19 DEFAULT_WORKDIR = Path(gettempdir()) / f"primer.{_timestamp}"
20 LOG = logging.getLogger(__name__)
24 ctx: click.core.Context,
25 param: Union[click.core.Option, click.core.Parameter],
26 debug: Union[bool, int, str],
27 ) -> Union[bool, int, str]:
28 """Turn on debugging if asked otherwise INFO default"""
29 log_level = logging.DEBUG if debug else logging.INFO
31 format="[%(asctime)s] %(levelname)s: %(message)s (%(filename)s:%(lineno)d)",
46 work_path = Path(workdir)
47 if not work_path.exists():
48 LOG.debug(f"Creating {work_path}")
51 if not which("black"):
52 LOG.error("Can not find 'black' executable in PATH. No point in running")
56 ret_val = await lib.process_queue(
57 config, work_path, workers, keep, long_checkouts, rebase
61 if not keep and work_path.exists():
62 LOG.debug(f"Removing {work_path}")
63 rmtree(work_path, onerror=lib.handle_PermissionError)
68 @click.command(context_settings={"help_option_names": ["-h", "--help"]})
72 default=str(DEFAULT_CONFIG),
73 type=click.Path(exists=True),
75 help="JSON config file path",
80 callback=_handle_debug,
82 help="Turn on debug logging",
89 help="Keep workdir + repos post run",
96 help="Pull big projects to test",
103 help="Rebase project if already checked out",
108 default=str(DEFAULT_WORKDIR),
109 type=click.Path(exists=False),
111 help="Directory path for repo checkouts",
119 help="Number of parallel worker coroutines",
122 def main(ctx: click.core.Context, **kwargs: Any) -> None:
123 """primer - prime projects for blackening... 🏴"""
124 LOG.debug(f"Starting {sys.argv[0]}")
125 # TODO: Change to asyncio.run when Black >= 3.7 only
126 loop = asyncio.get_event_loop()
128 ctx.exit(loop.run_until_complete(async_main(**kwargs)))
133 if __name__ == "__main__": # pragma: nocover