Skip to content

Commit 96eba77

Browse files
authored
Allow passing in individual files to the conversion script (#269)
1 parent 0ef9335 commit 96eba77

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

packages/gapic-generator/gapic/templates/scripts/fixup_%service_keywords.py.j2

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import argparse
44
import os
55
import libcst as cst
6+
from itertools import chain
67
from typing import (Any, Callable, Dict, List, Sequence, Tuple)
78

89

@@ -79,13 +80,16 @@ class {{ service.client_name }}CallTransformer(cst.CSTTransformer):
7980

8081
def fix_files(
8182
dirs: Sequence[str],
83+
files: Sequence[str],
8284
*,
8385
transformer={{ service.client_name }}CallTransformer(),
8486
):
85-
pyfile_gen = (os.path.join(root, f)
86-
for d in dirs
87-
for root, _, files in os.walk(d)
88-
for f in files if os.path.splitext(f)[1] == ".py")
87+
pyfile_gen = chain(
88+
(os.path.join(root, f)
89+
for d in dirs
90+
for root, _, files in os.walk(d)
91+
for f in files if os.path.splitext(f)[1] == ".py"),
92+
files)
8993

9094
for fpath in pyfile_gen:
9195
with open(fpath, 'r+') as f:
@@ -113,13 +117,21 @@ Note: This tool operates at a best-effort level at converting positional
113117

114118
Be sure to back up your source files before running this tool and to compare the diffs.
115119
""")
116-
parser.add_argument(
120+
group = parser.add_mutually_exclusive_group(required=True)
121+
group.add_argument(
117122
'-d',
118123
metavar='dir',
119124
dest='dirs',
120125
action='append',
121-
help='a directory to walk for python files to fix up'
126+
help='a directory to walk for python files to fix up',
127+
)
128+
group.add_argument(
129+
'-f',
130+
metavar='file',
131+
dest='files',
132+
action='append',
133+
help='a file to fix up via un-flattening',
122134
)
123135
args = parser.parse_args()
124-
fix_files(args.dirs or ['.'])
136+
fix_files(args.dirs or [], args.files or [])
125137
{% endblock %}

0 commit comments

Comments
 (0)