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)",
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(
68 if not keep and work_path.exists():
69 LOG.debug(f"Removing {work_path}")
70 rmtree(work_path, onerror=lib.handle_PermissionError)
75 @click.command(context_settings={"help_option_names": ["-h", "--help"]})
79 default=str(DEFAULT_CONFIG),
80 type=click.Path(exists=True),
82 help="JSON config file path",
87 callback=_handle_debug,
89 help="Turn on debug logging",
96 help="Keep workdir + repos post run",
103 help="Pull big projects to test",
109 help="Disable showing source file changes in black output",
116 help="Rebase project if already checked out",
121 default=str(DEFAULT_WORKDIR),
122 type=click.Path(exists=False),
124 help="Directory path for repo checkouts",
132 help="Number of parallel worker coroutines",
135 def main(ctx: click.core.Context, **kwargs: Any) -> None:
136 """primer - prime projects for blackening... 🏴"""
137 LOG.debug(f"Starting {sys.argv[0]}")
138 # TODO: Change to asyncio.run when Black >= 3.7 only
139 loop = asyncio.get_event_loop()
141 ctx.exit(loop.run_until_complete(async_main(**kwargs)))
146 if __name__ == "__main__": # pragma: nocover