Skip to content

Commit

Permalink
Throw exceptions by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Feb 4, 2024
1 parent 5a35588 commit 012eb9f
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 32 deletions.
8 changes: 3 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,9 @@ CLI Usage
::

usage: musescore-manager [-h] [--print-completion {bash,zsh,tcsh}]
[-C <file-path>] [-b] [-d] [--bail] [--catch-errors]
[-m] [-e FILE_PATH] [-V] [-v] [-k] [--diff]
[--print-xml] [-E <extension>] [--compress]
[-c META_CLEAN] [-D]
[-C <file-path>] [-b] [-d] [--catch-errors] [-m]
[-e FILE_PATH] [-V] [-v] [-k] [--diff] [--print-xml]
[-E <extension>] [--compress] [-c META_CLEAN] [-D]
[-i <source-fields> <format-string>] [-j]
[-l <log-file> <format-string>] [-y]
[-S <field> <format-string>]
Expand Down Expand Up @@ -388,7 +387,6 @@ CLI Usage
Specify a configuration file in the INI format.
-b, --backup Create a backup file.
-d, --dry-run Simulate the actions.
--bail Stop execution when an exception occurs.
--catch-errors Print error messages instead stop execution in a batch run.
-m, --mscore, --save-in-mscore
Open and save the XML file in MuseScore after manipulating
Expand Down
3 changes: 1 addition & 2 deletions autocomplete.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@



_shtab_musescore_manager_option_strings=('-h' '--help' '--print-completion' '-C' '--config-file' '-b' '--backup' '-d' '--dry-run' '--bail' '--catch-errors' '-m' '--mscore' '--save-in-mscore' '-e' '--executable' '-V' '--version' '-v' '--verbose' '-k' '--colorize' '--diff' '--print-xml' '-E' '--export' '--compress' '-c' '--clean-meta' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--title' '--subtitle' '--composer' '--lyricist' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-t' '--target' '--only-filename' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '--clean' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--a4' '--din-a4' '--letter' '--margin' '--show-header' '--no-show-header' '--header-first-page' '--no-header-first-page' '--different-odd-even-header' '--no-different-odd-even-header' '--header' '--header-odd-even' '--show-footer' '--no-show-footer' '--footer-first-page' '--no-footer-first-page' '--different-odd-even-footer' '--no-different-odd-even-footer' '--footer' '--footer-odd-even' '--reset-small-staffs')
_shtab_musescore_manager_option_strings=('-h' '--help' '--print-completion' '-C' '--config-file' '-b' '--backup' '-d' '--dry-run' '--catch-errors' '-m' '--mscore' '--save-in-mscore' '-e' '--executable' '-V' '--version' '-v' '--verbose' '-k' '--colorize' '--diff' '--print-xml' '-E' '--export' '--compress' '-c' '--clean-meta' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--title' '--subtitle' '--composer' '--lyricist' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-t' '--target' '--only-filename' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '--clean' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--a4' '--din-a4' '--letter' '--margin' '--show-header' '--no-show-header' '--header-first-page' '--no-header-first-page' '--different-odd-even-header' '--no-different-odd-even-header' '--header' '--header-odd-even' '--show-footer' '--no-show-footer' '--footer-first-page' '--no-footer-first-page' '--different-odd-even-footer' '--no-different-odd-even-footer' '--footer' '--footer-odd-even' '--reset-small-staffs')

_shtab_musescore_manager_pos_0_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager__C_COMPGEN=_shtab_compgen_files
Expand All @@ -25,7 +25,6 @@ _shtab_musescore_manager__b_nargs=0
_shtab_musescore_manager___backup_nargs=0
_shtab_musescore_manager__d_nargs=0
_shtab_musescore_manager___dry_run_nargs=0
_shtab_musescore_manager___bail_nargs=0
_shtab_musescore_manager___catch_errors_nargs=0
_shtab_musescore_manager__m_nargs=0
_shtab_musescore_manager___mscore_nargs=0
Expand Down
2 changes: 1 addition & 1 deletion autocomplete.tcsh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


complete musescore-manager \
'c/--/(a4 alphanum ascii backup bail catch-errors clean clean-meta colorize composer compress config-file delete-duplicates diff different-odd-even-footer different-odd-even-header din-a4 distribute-fields dry-run executable export extract extract-lyrics fix fix-lyrics footer footer-first-page footer-odd-even glob header header-first-page header-odd-even help json letter list-files list-fonts log lyricist margin metatag metatag-meta mscore mscx mscz musical-symbol-font musical-text-font no-different-odd-even-footer no-different-odd-even-header no-footer-first-page no-header-first-page no-show-footer no-show-header no-whitespace only-filename page-size print-completion print-xml remap remap-lyrics rename reset-small-staffs s3 s4 save-in-mscore set-field show-footer show-header skip-if-empty staff-space style style-file styles-v3 styles-v4 subtitle synchronize target text-font title title-font vbox vbox-meta verbose version)/' \
'c/--/(a4 alphanum ascii backup catch-errors clean clean-meta colorize composer compress config-file delete-duplicates diff different-odd-even-footer different-odd-even-header din-a4 distribute-fields dry-run executable export extract extract-lyrics fix fix-lyrics footer footer-first-page footer-odd-even glob header header-first-page header-odd-even help json letter list-files list-fonts log lyricist margin metatag metatag-meta mscore mscx mscz musical-symbol-font musical-text-font no-different-odd-even-footer no-different-odd-even-header no-footer-first-page no-header-first-page no-show-footer no-show-header no-whitespace only-filename page-size print-completion print-xml remap remap-lyrics rename reset-small-staffs s3 s4 save-in-mscore set-field show-footer show-header skip-if-empty staff-space style style-file styles-v3 styles-v4 subtitle synchronize target text-font title title-font vbox vbox-meta verbose version)/' \
'c/-/(- A C D E F K L S V Y a b c d e g h i j k l m n r s t v x y)/' \
'n/--print-completion/(bash zsh tcsh)/' \
'n/-C/f/' \
Expand Down
1 change: 0 additions & 1 deletion autocomplete.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ _shtab_musescore_manager_options=(
{-C,--config-file}"[Specify a configuration file in the INI format.]:general_config_file:_files"
{-b,--backup}"[Create a backup file.]"
{-d,--dry-run}"[Simulate the actions.]"
"--bail[Stop execution when an exception occurs.]"
"--catch-errors[Print error messages instead stop execution in a batch run.]"
{-m,--mscore,--save-in-mscore}"[Open and save the XML file in MuseScore after manipulating the XML with lxml to avoid differences in the XML structure.]"
{-e,--executable}"[Path of the musescore executable.]:general_executable:_files"
Expand Down
8 changes: 3 additions & 5 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ Comande line interface
::

usage: musescore-manager [-h] [--print-completion {bash,zsh,tcsh}]
[-C <file-path>] [-b] [-d] [--bail] [--catch-errors]
[-m] [-e FILE_PATH] [-V] [-v] [-k] [--diff]
[--print-xml] [-E <extension>] [--compress]
[-c META_CLEAN] [-D]
[-C <file-path>] [-b] [-d] [--catch-errors] [-m]
[-e FILE_PATH] [-V] [-v] [-k] [--diff] [--print-xml]
[-E <extension>] [--compress] [-c META_CLEAN] [-D]
[-i <source-fields> <format-string>] [-j]
[-l <log-file> <format-string>] [-y]
[-S <field> <format-string>]
Expand Down Expand Up @@ -55,7 +54,6 @@ Comande line interface
Specify a configuration file in the INI format.
-b, --backup Create a backup file.
-d, --dry-run Simulate the actions.
--bail Stop execution when an exception occurs.
--catch-errors Print error messages instead stop execution in a batch run.
-m, --mscore, --save-in-mscore
Open and save the XML file in MuseScore after manipulating
Expand Down
10 changes: 1 addition & 9 deletions mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]:
help="Simulate the actions.",
)

# TODO remove and use --catch-errors
parser.add_argument(
"--bail",
dest="general_bail",
action="store_true",
help="Stop execution when an exception occurs.",
)

parser.add_argument(
"--catch-errors",
dest="general_catch_errors",
Expand Down Expand Up @@ -1039,7 +1031,7 @@ def list_styles(version: int) -> None:
rename(score, args.rename_rename)

except Exception as e:
if args.general_bail:
if not args.general_catch_errors:
raise e
else:
__print_error(e)
2 changes: 1 addition & 1 deletion mscxyz/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DefaultArguments:
general_config_file: Optional[str] = None
general_backup: bool = False
general_dry_run: bool = False
general_bail: bool = False
general_catch_errors: bool = False
general_mscore: bool = False
general_executable: Optional[str] = None
general_verbose: int = 0
Expand Down
13 changes: 7 additions & 6 deletions tests/test_command_line_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ def test_size(self) -> None:
assert os.path.getsize(score.path) == os.path.getsize(score.backup_file)


class TestOptionBail:
def test_no_bail(self) -> None:
assert "XMLSyntaxError" in Cli(helper.get_file("broken.mscx")).stdout()

def test_bail(self) -> None:
class TestOptionCatchErrors:
def test_catch(self) -> None:
assert (
"XMLSyntaxError" in Cli("--bail", helper.get_file("broken.mscx")).sysexit()
"XMLSyntaxError"
in Cli("--catch-errors", helper.get_file("broken.mscx")).stdout()
)

def test_no_catch(self) -> None:
assert "XMLSyntaxError" in Cli(helper.get_file("broken.mscx")).sysexit()
2 changes: 1 addition & 1 deletion tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ def test_distribute_field_multiple_values(self) -> None:
def test_distribute_field_invalid_format_string(self) -> None:
with pytest.raises(meta.FormatStringNoFieldError):
Cli(
"--bail",
"--distribute-field",
"vbox_title",
"lol",
).append_score("meta-distribute-field.mscz").execute()

def test_distribute_field_exception_unmatched(self) -> None:
stdout = Cli(
"--catch-errors",
"--distribute-field",
"vbox_title",
"$metatag_work_title - $metatag_composer",
Expand Down
1 change: 0 additions & 1 deletion tests/test_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def test_rename_skips(self) -> None:

def test_rename_skip_pass(self, cwd_tmpdir: Path) -> None:
stdout: str = Cli(
"--bail",
"--rename",
"$title ($composer)",
"--skip-if-empty",
Expand Down

0 comments on commit 012eb9f

Please sign in to comment.