Skip to content

Commit 5ca6045

Browse files
fineguyThe TensorFlow Datasets Authors
authored andcommitted
Update download_and_prepare to use build_croissant CLI command.
PiperOrigin-RevId: 621454738
1 parent 9f8065f commit 5ca6045

File tree

5 files changed

+8
-19
lines changed

5 files changed

+8
-19
lines changed

tensorflow_datasets/scripts/cli/build_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def mock_cwd(path: epath.PathLike) -> Iterator[None]:
8383
def _build(cmd_flags: str, mock_download_and_prepare: bool = True) -> List[str]:
8484
"""Executes `tfds build {cmd_flags}` and returns the list of generated ds."""
8585
# Execute the command
86-
args = main.parse_flags(f'tfds build {cmd_flags}'.split())
86+
args = main._parse_flags(f'tfds build {cmd_flags}'.split())
8787

8888
original_dl_and_prepare = tfds.core.DatasetBuilder.download_and_prepare
8989

@@ -325,7 +325,7 @@ def test_download_only():
325325
),
326326
)
327327
def test_make_download_config(args: str, download_config_kwargs):
328-
args = main.parse_flags(f'tfds build x {download_config_kwargs}'.split())
328+
args = main._parse_flags(f'tfds build x {download_config_kwargs}'.split())
329329
actual = build_lib._make_download_config(args, dataset_name='x')
330330
# Ignore the beam runner
331331
actual.replace(beam_runner=None)

tensorflow_datasets/scripts/cli/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
FLAGS = flags.FLAGS
4343

4444

45-
def parse_flags(argv: List[str]) -> argparse.Namespace:
45+
def _parse_flags(argv: List[str]) -> argparse.Namespace:
4646
"""Command lines flag parsing."""
4747
argv = flag_utils.normalize_flags(argv) # See b/174043007 for context.
4848

@@ -102,7 +102,7 @@ def main(args: argparse.Namespace) -> None:
102102

103103
def launch_cli() -> None:
104104
"""Parse arguments and launch the CLI main function."""
105-
app.run(main, flags_parser=parse_flags)
105+
app.run(main, flags_parser=_parse_flags)
106106

107107

108108
if __name__ == '__main__':

tensorflow_datasets/scripts/cli/main_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ def _check_exit(status=0, message=None):
2828
# Argparse call `sys.exit(0)` when `--version` is passed.
2929
with mock.patch('sys.exit', _check_exit):
3030
version_flag = '--version'
31-
main.main(main.parse_flags(['', version_flag]))
31+
main.main(main._parse_flags(['', version_flag]))

tensorflow_datasets/scripts/cli/new_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def _run_cli(cmd: str) -> None:
26-
main.main(main.parse_flags([''] + cmd.split()))
26+
main.main(main._parse_flags([''] + cmd.split()))
2727

2828

2929
def test_new_without_args(capsys):

tensorflow_datasets/scripts/download_and_prepare.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
r"""Wrapper around `tfds build` and `tfds build_croissant`."""
16+
r"""Wrapper around `tfds build`."""
1717

1818
import argparse
1919
from typing import List
@@ -35,18 +35,7 @@
3535

3636
def _parse_flags(argv: List[str]) -> argparse.Namespace:
3737
"""Command lines flag parsing."""
38-
parser = argparse.ArgumentParser(
39-
description='Runs either `tfds build` or `tfds build_croissant`.'
40-
)
41-
parser.add_argument('--croissant', action='store_true')
42-
args, other_argv = parser.parse_known_args(argv)
43-
44-
if args.croissant:
45-
build_cmd = 'build_croissant'
46-
else:
47-
build_cmd = 'build'
48-
49-
return main_cli.parse_flags([other_argv[0], build_cmd] + other_argv[1:])
38+
return main_cli._parse_flags([argv[0], 'build'] + argv[1:]) # pylint: disable=protected-access
5039

5140

5241
_display_warning = True

0 commit comments

Comments
 (0)