diff --git a/pkgs/development/python-modules/tyro/default.nix b/pkgs/development/python-modules/tyro/default.nix index 44a0d6cc1ded..4bd2fd815bbe 100644 --- a/pkgs/development/python-modules/tyro/default.nix +++ b/pkgs/development/python-modules/tyro/default.nix @@ -35,6 +35,10 @@ buildPythonPackage (finalAttrs: { hash = "sha256-mnYVinyys21BjHRhwOLjc3n8mShH2+krEK0dK0VBWp4="; }; + patches = [ + ./fix-shtab-1.9.patch # reduced version of https://github.com/brentyi/tyro/pull/488 + ]; + build-system = [ hatchling ]; dependencies = [ diff --git a/pkgs/development/python-modules/tyro/fix-shtab-1.9.patch b/pkgs/development/python-modules/tyro/fix-shtab-1.9.patch new file mode 100644 index 000000000000..2fadd46b9900 --- /dev/null +++ b/pkgs/development/python-modules/tyro/fix-shtab-1.9.patch @@ -0,0 +1,160 @@ +diff --git a/tests/test_completion_bash.py b/tests/test_completion_bash.py +index bacccc0646f331eb7f75163ba88a65ca42db3fff..163d44f1c6a3a6fc0816982ebbd0ed2030635507 100644 +--- a/tests/test_completion_bash.py ++++ b/tests/test_completion_bash.py +@@ -143,7 +143,11 @@ def test_bash(backend: str) -> None: + output = target.getvalue() + # Check for appropriate signature based on backend. + if backend == "argparse": +- assert "# AUTOMATICALLY GENERATED by `shtab`" in output ++ # The banner changed from "by `shtab`" to a URL in shtab 1.9.x. ++ assert ( ++ "# AUTOMATICALLY GENERATED by `shtab`" in output ++ or "# AUTOMATICALLY GENERATED by https://github.com/tqdm/shtab" in output ++ ) + else: # tyro backend. + assert "# AUTOMATICALLY GENERATED by tyro" in output + +@@ -411,9 +415,14 @@ class Config: + main_subparsers_content = main_subparsers_match.group(2) + + # Argparse backend: Nested structure - only shows dataset subcommands initially. +- # Should have 2 subcommands in main array (just datasets). ++ # Should have 2 subcommands in main array (just datasets). Subcommand ++ # names are quoted by shtab <1.9.x and unquoted afterwards. + subcommand_count = len( +- re.findall(r"'[^']*(?:mnist|image|adam|sgd)[^']*'", main_subparsers_content) ++ [ ++ token ++ for token in re.findall(r"'[^']+'|\S+", main_subparsers_content) ++ if re.search(r"mnist|image|adam|sgd", token) ++ ] + ) + assert subcommand_count == 2, ( + f"Argparse backend should show 2 dataset subcommands in main array, " +diff --git a/tests/test_completion_zsh.py b/tests/test_completion_zsh.py +index d236bd2e9c45c743a35d45811d8893aee74f6835..f91da4fda99e6ec03945e029090b6d81ca1088ca 100644 +--- a/tests/test_completion_zsh.py ++++ b/tests/test_completion_zsh.py +@@ -45,7 +45,11 @@ def test_zsh(backend: str) -> None: + output = target.getvalue() + # Check for appropriate signature based on backend. + if backend == "argparse": +- assert "# AUTOMATICALLY GENERATED by `shtab`" in output ++ # The banner changed from "by `shtab`" to a URL in shtab 1.9.x. ++ assert ( ++ "# AUTOMATICALLY GENERATED by `shtab`" in output ++ or "# AUTOMATICALLY GENERATED by https://github.com/tqdm/shtab" in output ++ ) + else: # tyro backend. + assert "# AUTOMATICALLY GENERATED by tyro" in output + # Check that zsh-specific syntax is present. +@@ -84,7 +88,12 @@ def start_device( + + # Check for appropriate signature based on backend. + if backend == "argparse": +- assert "# AUTOMATICALLY GENERATED by `shtab`" in completion_script ++ # The banner changed from "by `shtab`" to a URL in shtab 1.9.x. ++ assert ( ++ "# AUTOMATICALLY GENERATED by `shtab`" in completion_script ++ or "# AUTOMATICALLY GENERATED by https://github.com/tqdm/shtab" ++ in completion_script ++ ) + else: # tyro backend. + assert "# AUTOMATICALLY GENERATED by tyro" in completion_script + +diff --git a/tests/test_py311_generated/test_completion_bash_generated.py b/tests/test_py311_generated/test_completion_bash_generated.py +index f66543f7884ecb83d7ade90b23f596e1beb59aab..a39f07bde56c2f587ed39615e0b7c01774ec12fb 100644 +--- a/tests/test_py311_generated/test_completion_bash_generated.py ++++ b/tests/test_py311_generated/test_completion_bash_generated.py +@@ -142,7 +142,11 @@ def test_bash(backend: str) -> None: + output = target.getvalue() + # Check for appropriate signature based on backend. + if backend == "argparse": +- assert "# AUTOMATICALLY GENERATED by `shtab`" in output ++ # The banner changed from "by `shtab`" to a URL in shtab 1.9.x. ++ assert ( ++ "# AUTOMATICALLY GENERATED by `shtab`" in output ++ or "# AUTOMATICALLY GENERATED by https://github.com/tqdm/shtab" in output ++ ) + else: # tyro backend. + assert "# AUTOMATICALLY GENERATED by tyro" in output + +@@ -410,9 +414,14 @@ class Config: + main_subparsers_content = main_subparsers_match.group(2) + + # Argparse backend: Nested structure - only shows dataset subcommands initially. +- # Should have 2 subcommands in main array (just datasets). ++ # Should have 2 subcommands in main array (just datasets). Subcommand ++ # names are quoted by shtab <1.9.x and unquoted afterwards. + subcommand_count = len( +- re.findall(r"'[^']*(?:mnist|image|adam|sgd)[^']*'", main_subparsers_content) ++ [ ++ token ++ for token in re.findall(r"'[^']+'|\S+", main_subparsers_content) ++ if re.search(r"mnist|image|adam|sgd", token) ++ ] + ) + assert subcommand_count == 2, ( + f"Argparse backend should show 2 dataset subcommands in main array, " +diff --git a/tests/test_py311_generated/test_completion_zsh_generated.py b/tests/test_py311_generated/test_completion_zsh_generated.py +index d662f1cc6b91b9241fcdb48ba8f9f13e3136cd89..6b717494e329168dd95f97b5ac241341347b1c15 100644 +--- a/tests/test_py311_generated/test_completion_zsh_generated.py ++++ b/tests/test_py311_generated/test_completion_zsh_generated.py +@@ -44,7 +44,11 @@ def test_zsh(backend: str) -> None: + output = target.getvalue() + # Check for appropriate signature based on backend. + if backend == "argparse": +- assert "# AUTOMATICALLY GENERATED by `shtab`" in output ++ # The banner changed from "by `shtab`" to a URL in shtab 1.9.x. ++ assert ( ++ "# AUTOMATICALLY GENERATED by `shtab`" in output ++ or "# AUTOMATICALLY GENERATED by https://github.com/tqdm/shtab" in output ++ ) + else: # tyro backend. + assert "# AUTOMATICALLY GENERATED by tyro" in output + # Check that zsh-specific syntax is present. +@@ -83,7 +87,12 @@ def start_device( + + # Check for appropriate signature based on backend. + if backend == "argparse": +- assert "# AUTOMATICALLY GENERATED by `shtab`" in completion_script ++ # The banner changed from "by `shtab`" to a URL in shtab 1.9.x. ++ assert ( ++ "# AUTOMATICALLY GENERATED by `shtab`" in completion_script ++ or "# AUTOMATICALLY GENERATED by https://github.com/tqdm/shtab" ++ in completion_script ++ ) + else: # tyro backend. + assert "# AUTOMATICALLY GENERATED by tyro" in completion_script + +diff --git a/tests/test_py311_generated/test_subcommand_aliases_and_default_generated.py b/tests/test_py311_generated/test_subcommand_aliases_and_default_generated.py +index 732aa4a398199fd2364139df019c93985978431f..052344dd089a7cd2e83376e0c66613d6f88b7973 100644 +--- a/tests/test_py311_generated/test_subcommand_aliases_and_default_generated.py ++++ b/tests/test_py311_generated/test_subcommand_aliases_and_default_generated.py +@@ -497,8 +497,8 @@ def test_completion_includes_nested_aliases(): + script = target.getvalue() + assert "one" in script and "two" in script + # Aliases should also be listed. +- assert "'1'" in script or " 1 " in script +- assert "'2'" in script or " 2 " in script ++ assert "'1'" in script or " 1 " in script or " 1)" in script ++ assert "'2'" in script or " 2 " in script or " 2)" in script + + + def test_alias_help_shows_canonical(capsys): +diff --git a/tests/test_subcommand_aliases_and_default.py b/tests/test_subcommand_aliases_and_default.py +index 93b9f6e332e29fbbaa6deedda6e1aad2471decc3..b63c81bf0ea1f5617bf4b23de1b9507906d8f559 100644 +--- a/tests/test_subcommand_aliases_and_default.py ++++ b/tests/test_subcommand_aliases_and_default.py +@@ -516,8 +516,8 @@ def test_completion_includes_nested_aliases(): + script = target.getvalue() + assert "one" in script and "two" in script + # Aliases should also be listed. +- assert "'1'" in script or " 1 " in script +- assert "'2'" in script or " 2 " in script ++ assert "'1'" in script or " 1 " in script or " 1)" in script ++ assert "'2'" in script or " 2 " in script or " 2)" in script + + + def test_alias_help_shows_canonical(capsys):