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, Optional
14 from black_primer import lib
16 # If our environment has uvloop installed lets use it
25 DEFAULT_CONFIG = Path(__file__).parent / "primer.json"
26 _timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
27 DEFAULT_WORKDIR = Path(gettempdir()) / f"primer.{_timestamp}"
28 LOG = logging.getLogger(__name__)
32 ctx: Optional[click.core.Context],
33 param: Optional[Union[click.core.Option, click.core.Parameter]],
34 debug: Union[bool, int, str],
35 ) -> Union[bool, int, str]:
36 """Turn on debugging if asked otherwise INFO default"""
37 log_level = logging.DEBUG if debug else logging.INFO
39 format="[%(asctime)s] %(levelname)s: %(message)s (%(filename)s:%(lineno)d)",
55 work_path = Path(workdir)
56 if not work_path.exists():
57 LOG.debug(f"Creating {work_path}")
60 if not which("black"):
61 LOG.error("Can not find 'black' executable in PATH. No point in running")
65 ret_val = await lib.process_queue(
76 if not keep and work_path.exists():
77 LOG.debug(f"Removing {work_path}")
78 rmtree(work_path, onerror=lib.handle_PermissionError)
83 @click.command(context_settings={"help_option_names": ["-h", "--help"]})
87 default=str(DEFAULT_CONFIG),
88 type=click.Path(exists=True),
90 help="JSON config file path",
95 callback=_handle_debug,
97 help="Turn on debug logging",
104 help="Keep workdir + repos post run",
111 help="Pull big projects to test",
117 help="Disable showing source file changes in black output",
124 help="Rebase project if already checked out",
129 default=str(DEFAULT_WORKDIR),
130 type=click.Path(exists=False),
132 help="Directory path for repo checkouts",
140 help="Number of parallel worker coroutines",
143 def main(ctx: click.core.Context, **kwargs: Any) -> None:
144 """primer - prime projects for blackening... 🏴"""
145 LOG.debug(f"Starting {sys.argv[0]}")
146 # TODO: Change to asyncio.run when Black >= 3.7 only
147 loop = asyncio.get_event_loop()
149 ctx.exit(loop.run_until_complete(async_main(**kwargs)))
154 if __name__ == "__main__": # pragma: nocover