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 os import cpu_count
8 from pathlib import Path
9 from shutil import rmtree, which
10 from tempfile import gettempdir
11 from typing import Any, Union
15 from black_primer import lib
18 DEFAULT_CONFIG = Path(__file__).parent / "primer.json"
19 _timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
20 DEFAULT_WORKDIR = Path(gettempdir()) / f"primer.{_timestamp}"
21 LOG = logging.getLogger(__name__)
25 ctx: click.core.Context,
26 param: Union[click.core.Option, click.core.Parameter],
27 debug: Union[bool, int, str],
28 ) -> Union[bool, int, str]:
29 """Turn on debugging if asked otherwise INFO default"""
30 log_level = logging.DEBUG if debug else logging.INFO
32 format="[%(asctime)s] %(levelname)s: %(message)s (%(filename)s:%(lineno)d)",
47 work_path = Path(workdir)
48 if not work_path.exists():
49 LOG.debug(f"Creating {work_path}")
52 if not which("black"):
53 LOG.error("Can not find 'black' executable in PATH. No point in running")
57 ret_val = await lib.process_queue(
58 config, work_path, workers, keep, long_checkouts, rebase
62 if not keep and work_path.exists():
63 LOG.debug(f"Removing {work_path}")
69 @click.command(context_settings={"help_option_names": ["-h", "--help"]})
73 default=str(DEFAULT_CONFIG),
74 type=click.Path(exists=True),
76 help="JSON config file path",
81 callback=_handle_debug,
83 help="Turn on debug logging",
90 help="Keep workdir + repos post run",
97 help="Pull big projects to test",
104 help="Rebase project if already checked out",
109 default=str(DEFAULT_WORKDIR),
110 type=click.Path(exists=False),
112 help="Directory Path for repo checkouts",
117 default=int((cpu_count() or 4) / 2) or 1,
120 help="Number of parallel worker coroutines",
123 def main(ctx: click.core.Context, **kwargs: Any) -> None:
124 """primer - prime projects for blackening ... 🏴"""
125 LOG.debug(f"Starting {sys.argv[0]}")
126 # TODO: Change to asyncio.run when black >= 3.7 only
127 loop = asyncio.get_event_loop()
129 ctx.exit(loop.run_until_complete(async_main(**kwargs)))
134 if __name__ == "__main__":