Added `eachdist.py format` command
@@ -238,6 +238,17 @@ def parse_args(args=None):
"releaseargs", nargs=argparse.REMAINDER, help=extraargs_help("pytest")
)
+ fmtparser = subparsers.add_parser(
+ "format",
+ help="Formats all source code with black and isort.",
+ )
+ fmtparser.set_defaults(func=format_args)
+ fmtparser.add_argument(
+ "--path",
+ required=False,
+ help="Format only this path instead of entire repository",
+ )
+
return parser.parse_args(args)
@@ -649,6 +660,25 @@ def test_args(args):
)
+def format_args(args):
+ format_dir = str(find_projectroot())
+ if args.path:
+ format_dir = os.path.join(format_dir, args.path)
+
+ runsubprocess(
+ args.dry_run,
+ ("black", "."),
+ cwd=format_dir,
+ check=True,
+ )
+ runsubprocess(
+ args.dry_run,
+ ("isort", "--profile", "black", "."),
+ cwd=format_dir,
+ check=True,
+ )
+
+
def main():
args = parse_args()
args.func(args)
