Skip to content

Commit 4966590

Browse files
authored
Added eachdist.py format command (#487)
This just runs black and isort of the entire repository.
1 parent 9199e3c commit 4966590

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

scripts/eachdist.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,16 @@ def setup_instparser(instparser):
237237
"releaseargs", nargs=argparse.REMAINDER, help=extraargs_help("pytest")
238238
)
239239

240+
fmtparser = subparsers.add_parser(
241+
"format", help="Formats all source code with black and isort.",
242+
)
243+
fmtparser.set_defaults(func=format_args)
244+
fmtparser.add_argument(
245+
"--path",
246+
required=False,
247+
help="Format only this path instead of entire repository",
248+
)
249+
240250
return parser.parse_args(args)
241251

242252

@@ -644,6 +654,22 @@ def test_args(args):
644654
)
645655

646656

657+
def format_args(args):
658+
format_dir = str(find_projectroot())
659+
if args.path:
660+
format_dir = os.path.join(format_dir, args.path)
661+
662+
runsubprocess(
663+
args.dry_run, ("black", "."), cwd=format_dir, check=True,
664+
)
665+
runsubprocess(
666+
args.dry_run,
667+
("isort", "--profile", "black", "."),
668+
cwd=format_dir,
669+
check=True,
670+
)
671+
672+
647673
def main():
648674
args = parse_args()
649675
args.func(args)

0 commit comments

Comments
 (0)