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.
8 from datetime import datetime
9 from pathlib import Path
10 from shutil import rmtree, which
11 from tempfile import gettempdir
12 from typing import Any, Union
16 from black_primer import lib
19 DEFAULT_CONFIG = Path(__file__).parent / "primer.json"
20 _timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
21 DEFAULT_WORKDIR = Path(gettempdir()) / f"primer.{_timestamp}"
22 LOG = logging.getLogger(__name__)
26 ctx: click.core.Context,
27 param: Union[click.core.Option, click.core.Parameter],
28 debug: Union[bool, int, str],
29 ) -> Union[bool, int, str]:
30 """Turn on debugging if asked otherwise INFO default"""
31 log_level = logging.DEBUG if debug else logging.INFO
33 format="[%(asctime)s] %(levelname)s: %(message)s (%(filename)s:%(lineno)d)",
48 work_path = Path(workdir)
49 if not work_path.exists():
50 LOG.debug(f"Creating {work_path}")
53 if not which("black"):
54 LOG.error("Can not find 'black' executable in PATH. No point in running")
58 ret_val = await lib.process_queue(
59 config, work_path, workers, keep, long_checkouts, rebase
63 if not keep and work_path.exists():
64 LOG.debug(f"Removing {work_path}")
65 rmtree(work_path, onerror=lib.handle_PermissionError)
70 @click.command(context_settings={"help_option_names": ["-h", "--help"]})
74 default=str(DEFAULT_CONFIG),
75 type=click.Path(exists=True),
77 help="JSON config file path",
82 callback=_handle_debug,
84 help="Turn on debug logging",
91 help="Keep workdir + repos post run",
98 help="Pull big projects to test",
105 help="Rebase project if already checked out",
110 default=str(DEFAULT_WORKDIR),
111 type=click.Path(exists=False),
113 help="Directory path for repo checkouts",
121 help="Number of parallel worker coroutines",
124 def main(ctx: click.core.Context, **kwargs: Any) -> None:
125 """primer - prime projects for blackening... 🏴"""
126 LOG.debug(f"Starting {sys.argv[0]}")
127 # TODO: Change to asyncio.run when Black >= 3.7 only
128 loop = asyncio.get_event_loop()
130 ctx.exit(loop.run_until_complete(async_main(**kwargs)))
135 if __name__ == "__main__": # pragma: nocover