Skip to content

Commit 4fd4681

Browse files
authored
Added eachdist.py format command (open-telemetry#1812)
1 parent cc51928 commit 4fd4681

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

scripts/eachdist.py

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

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

243254

@@ -649,6 +660,25 @@ def test_args(args):
649660
)
650661

651662

663+
def format_args(args):
664+
format_dir = str(find_projectroot())
665+
if args.path:
666+
format_dir = os.path.join(format_dir, args.path)
667+
668+
runsubprocess(
669+
args.dry_run,
670+
("black", "."),
671+
cwd=format_dir,
672+
check=True,
673+
)
674+
runsubprocess(
675+
args.dry_run,
676+
("isort", "--profile", "black", "."),
677+
cwd=format_dir,
678+
check=True,
679+
)
680+
681+
652682
def main():
653683
args = parse_args()
654684
args.func(args)

0 commit comments

Comments
 (0)