From 84733ae44843dce81c5f80151a03ba79b13cccdf Mon Sep 17 00:00:00 2001 From: svdgoor Date: Sun, 9 Jun 2024 18:24:00 +0200 Subject: [PATCH 1/7] Add auto overwrite parameter to create --- docs/reference/commands/create.rst | 7 ++++++- src/briefcase/commands/create.py | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/reference/commands/create.rst b/docs/reference/commands/create.rst index bd61d73d6..f0d11e7e9 100644 --- a/docs/reference/commands/create.rst +++ b/docs/reference/commands/create.rst @@ -32,4 +32,9 @@ to delete and regenerate the app. Options ======= -There are no additional command line options. +The following options can be provided at the command line. + +``--auto-overwrite`` +--------------------------------------- + +Automatically overwrite any existing scaffold for the nominated platform instead of asking for confirmation. diff --git a/src/briefcase/commands/create.py b/src/briefcase/commands/create.py index 936759945..f3e56e2a4 100644 --- a/src/briefcase/commands/create.py +++ b/src/briefcase/commands/create.py @@ -89,6 +89,13 @@ class CreateCommand(BaseCommand): def app_template_url(self): """The URL for a cookiecutter repository to use when creating apps.""" return f"https://github.com/beeware/briefcase-{self.platform}-{self.output_format}-template.git" + + def add_options(self, parser): + parser.add_argument( + "--auto-overwrite", + action="store_true", + help="Automatically confirm overwriting existing scaffold", + ) def support_package_filename(self, support_revision): """The query arguments to use in a support package query request.""" @@ -859,11 +866,12 @@ def cleanup_app_content(self, app: AppConfig): self.logger.verbose(f"Removing {relative_path}") path.unlink() - def create_app(self, app: AppConfig, test_mode: bool = False, **options): + def create_app(self, app: AppConfig, test_mode: bool = False, auto_confirm: bool = False, **options): """Create an application bundle. :param app: The config object for the app :param test_mode: Should the app be updated in test mode? (default: False) + :param auto_confirm: Should any existing scaffold be automatically overwritten? (default: False) """ if not app.supported: raise UnsupportedPlatform(self.platform) @@ -871,7 +879,7 @@ def create_app(self, app: AppConfig, test_mode: bool = False, **options): bundle_path = self.bundle_path(app) if bundle_path.exists(): self.logger.info() - confirm = self.input.boolean_input( + confirm = auto_confirm or self.input.boolean_input( f"Application {app.app_name!r} already exists; overwrite", default=False ) if not confirm: @@ -936,6 +944,7 @@ def verify_app_tools(self, app: AppConfig): def __call__( self, app: AppConfig | None = None, + auto_overwrite: bool = False, **options, ) -> dict | None: # Confirm host compatibility, that all required tools are available, @@ -943,11 +952,11 @@ def __call__( self.finalize(app) if app: - state = self.create_app(app, **options) + state = self.create_app(app, auto_overwrite, **options) else: state = None for app_name, app in sorted(self.apps.items()): - state = self.create_app(app, **full_options(state, options)) + state = self.create_app(app, auto_overwrite, **full_options(state, options)) return state From 940ba4f57732c7bff51e300f48406ed4fcf2684e Mon Sep 17 00:00:00 2001 From: svdgoor Date: Tue, 18 Jun 2024 16:46:22 +0200 Subject: [PATCH 2/7] Solve formatting issues --- docs/reference/commands/create.rst | 2 +- src/briefcase/commands/create.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/reference/commands/create.rst b/docs/reference/commands/create.rst index f0d11e7e9..24fa1b19e 100644 --- a/docs/reference/commands/create.rst +++ b/docs/reference/commands/create.rst @@ -34,7 +34,7 @@ Options The following options can be provided at the command line. -``--auto-overwrite`` +``--force`` --------------------------------------- Automatically overwrite any existing scaffold for the nominated platform instead of asking for confirmation. diff --git a/src/briefcase/commands/create.py b/src/briefcase/commands/create.py index f3e56e2a4..3012fbed3 100644 --- a/src/briefcase/commands/create.py +++ b/src/briefcase/commands/create.py @@ -89,10 +89,10 @@ class CreateCommand(BaseCommand): def app_template_url(self): """The URL for a cookiecutter repository to use when creating apps.""" return f"https://github.com/beeware/briefcase-{self.platform}-{self.output_format}-template.git" - + def add_options(self, parser): parser.add_argument( - "--auto-overwrite", + "--force", action="store_true", help="Automatically confirm overwriting existing scaffold", ) @@ -866,12 +866,19 @@ def cleanup_app_content(self, app: AppConfig): self.logger.verbose(f"Removing {relative_path}") path.unlink() - def create_app(self, app: AppConfig, test_mode: bool = False, auto_confirm: bool = False, **options): + def create_app( + self, + app: AppConfig, + test_mode: bool = False, + auto_confirm: bool = False, + **options, + ): """Create an application bundle. :param app: The config object for the app :param test_mode: Should the app be updated in test mode? (default: False) - :param auto_confirm: Should any existing scaffold be automatically overwritten? (default: False) + :param auto_confirm: Should any existing scaffold be automatically overwritten? + (default: False) """ if not app.supported: raise UnsupportedPlatform(self.platform) @@ -956,7 +963,9 @@ def __call__( else: state = None for app_name, app in sorted(self.apps.items()): - state = self.create_app(app, auto_overwrite, **full_options(state, options)) + state = self.create_app( + app, auto_overwrite, **full_options(state, options) + ) return state From b3bf8346e17496a4b2d02fee45bf4d98764779ae Mon Sep 17 00:00:00 2001 From: svdgoor Date: Tue, 18 Jun 2024 16:53:00 +0200 Subject: [PATCH 3/7] changelog --- changes/1870.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1870.feature.rst diff --git a/changes/1870.feature.rst b/changes/1870.feature.rst new file mode 100644 index 000000000..477513456 --- /dev/null +++ b/changes/1870.feature.rst @@ -0,0 +1 @@ +Added force flag to create command to overwrite existing scaffolds From 20f5bd7a15ad288fc0f1ce88ebd30dcb57d27c3c Mon Sep 17 00:00:00 2001 From: svdgoor Date: Fri, 21 Jun 2024 13:58:04 +0200 Subject: [PATCH 4/7] Consistently use force --- src/briefcase/commands/create.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/briefcase/commands/create.py b/src/briefcase/commands/create.py index cd102c075..37e136716 100644 --- a/src/briefcase/commands/create.py +++ b/src/briefcase/commands/create.py @@ -869,14 +869,14 @@ def create_app( self, app: AppConfig, test_mode: bool = False, - auto_confirm: bool = False, + force: bool = False, **options, ): """Create an application bundle. :param app: The config object for the app :param test_mode: Should the app be updated in test mode? (default: False) - :param auto_confirm: Should any existing scaffold be automatically overwritten? + :param force: Should any existing scaffold be automatically overwritten? (default: False) """ if not app.supported: @@ -885,7 +885,7 @@ def create_app( bundle_path = self.bundle_path(app) if bundle_path.exists(): self.logger.info() - confirm = auto_confirm or self.input.boolean_input( + confirm = force or self.input.boolean_input( f"Application {app.app_name!r} already exists; overwrite", default=False ) if not confirm: @@ -950,7 +950,7 @@ def verify_app_tools(self, app: AppConfig): def __call__( self, app: AppConfig | None = None, - auto_overwrite: bool = False, + force: bool = False, **options, ) -> dict | None: # Confirm host compatibility, that all required tools are available, @@ -958,13 +958,11 @@ def __call__( self.finalize(app) if app: - state = self.create_app(app, auto_overwrite, **options) + state = self.create_app(app, force, **options) else: state = None for app_name, app in sorted(self.apps.items()): - state = self.create_app( - app, auto_overwrite, **full_options(state, options) - ) + state = self.create_app(app, force, **full_options(state, options)) return state From 53850f846407d4036758152d60dbc473ffb6dc12 Mon Sep 17 00:00:00 2001 From: svdgoor Date: Fri, 21 Jun 2024 14:11:47 +0200 Subject: [PATCH 5/7] Test force parameter --- tests/commands/create/test_create_app.py | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/commands/create/test_create_app.py b/tests/commands/create/test_create_app.py index 8c39074bc..5fb59683b 100644 --- a/tests/commands/create/test_create_app.py +++ b/tests/commands/create/test_create_app.py @@ -29,6 +29,41 @@ def test_create_app(tracking_create_command, tmp_path): assert not (tmp_path / "base_path/build/first/tester/dummy/Stub.bin").exists() +def test_create_existing_app_force(tracking_create_command, tmp_path): + """An existing app is overwritten if --force parameter is added.""" + + # Generate an app in the location. + bundle_path = tmp_path / "base_path/build/first/tester/dummy" + bundle_path.mkdir(parents=True) + with (bundle_path / "original").open("w", encoding="utf-8") as f: + f.write("original template!") + + options, _ = tracking_create_command.parse_options(["--force"]) + + tracking_create_command.create_app(tracking_create_command.apps["first"], **options) + + # Input was not required by the user + assert tracking_create_command.input.prompts == [] + + # The right sequence of things will be done + assert tracking_create_command.actions == [ + ("generate", "first"), + ("support", "first"), + ("verify-app-template", "first"), + ("verify-app-tools", "first"), + ("code", "first", False), + ("requirements", "first", False), + ("resources", "first"), + ("cleanup", "first"), + ] + + # Original content has been deleted + assert not (bundle_path / "original").exists() + + # New app content has been created + assert (bundle_path / "new").exists() + + def test_create_existing_app_overwrite(tracking_create_command, tmp_path): """An existing app can be overwritten if requested.""" # Answer yes when asked From 90ffecd1db4ddb20a67e9609280670ed77bc44d7 Mon Sep 17 00:00:00 2001 From: svdgoor Date: Fri, 21 Jun 2024 14:31:02 +0200 Subject: [PATCH 6/7] Add todo statements to the tests that failed on windows --- tests/test_cmdline.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 3f6dcc349..3477d54df 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -351,6 +351,7 @@ def test_upgrade_command( assert overrides == expected_overrides +# TODO: Find another command to use here since create now has a parameter. def test_bare_command(monkeypatch, logger, console): """``briefcase create`` returns the macOS create app command.""" # Pretend we're on macOS, regardless of where the tests run. @@ -369,6 +370,7 @@ def test_bare_command(monkeypatch, logger, console): assert overrides == {} +# TODO: Find another command to use here since create now has a parameter. @pytest.mark.skipif(sys.platform != "linux", reason="requires Linux") def test_linux_default(logger, console): """``briefcase create`` returns the linux create system command on Linux.""" @@ -402,6 +404,7 @@ def test_macOS_default(logger, console): assert overrides == {} +# TODO: Find another command to use here since create now has a parameter. @pytest.mark.skipif(sys.platform != "win32", reason="requires Windows") def test_windows_default(logger, console): """``briefcase create`` returns the Windows create app command on Windows.""" @@ -419,6 +422,7 @@ def test_windows_default(logger, console): assert overrides == {} +# TODO: Find another command to use here since create now has a parameter. def test_bare_command_help(monkeypatch, capsys, logger, console): """``briefcase create -h`` returns the macOS create app command help.""" # Pretend we're on macOS, regardless of where the tests run. @@ -466,6 +470,7 @@ def test_command_unknown_platform(monkeypatch, logger, console): ) +# TODO: Find another command to use here since create now has a parameter. def test_command_explicit_platform(monkeypatch, logger, console): """``briefcase create linux`` returns linux create app command.""" # Pretend we're on macOS, regardless of where the tests run. @@ -484,6 +489,7 @@ def test_command_explicit_platform(monkeypatch, logger, console): assert overrides == {} +# TODO: Find another command to use here since create now has a parameter. def test_command_explicit_platform_case_handling(monkeypatch, logger, console): """``briefcase create macOS`` returns macOS create app command.""" # Pretend we're on macOS, regardless of where the tests run. @@ -503,6 +509,7 @@ def test_command_explicit_platform_case_handling(monkeypatch, logger, console): assert overrides == {} +# TODO: Find another command to use here since create now has a parameter. def test_command_explicit_platform_help(monkeypatch, capsys, logger, console): """``briefcase create macOS -h`` returns the macOS create app command help.""" # Pretend we're on macOS, regardless of where the tests run. @@ -523,6 +530,7 @@ def test_command_explicit_platform_help(monkeypatch, capsys, logger, console): ) +# TODO: Find another command to use here since create now has a parameter. def test_command_explicit_format(monkeypatch, logger, console): """``briefcase create macOS app`` returns the macOS create app command.""" # Pretend we're on macOS, regardless of where the tests run. @@ -573,6 +581,7 @@ def test_command_explicit_unsupported_format(monkeypatch, logger, console): do_cmdline_parse("create macOS homebrew".split(), logger, console) +# TODO: Find another command to use here since create now has a parameter. def test_command_explicit_format_help(monkeypatch, capsys, logger, console): """``briefcase create macOS app -h`` returns the macOS create app help.""" # Pretend we're on macOS, regardless of where the tests run. @@ -593,6 +602,7 @@ def test_command_explicit_format_help(monkeypatch, capsys, logger, console): ) +# TODO: Find another command to use here since create now has a parameter. def test_command_disable_input(monkeypatch, logger, console): """``briefcase create --no-input`` disables console input.""" # Pretend we're on macOS, regardless of where the tests run. From 426351837859d18a3f70d756ee11bf1c223b0a32 Mon Sep 17 00:00:00 2001 From: svdgoor Date: Fri, 21 Jun 2024 14:32:37 +0200 Subject: [PATCH 7/7] Update test cases for parameter addition --- tests/platforms/linux/appimage/test_create.py | 4 ++-- tests/platforms/linux/system/test_create.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/platforms/linux/appimage/test_create.py b/tests/platforms/linux/appimage/test_create.py index 95d0c0203..236adbf67 100644 --- a/tests/platforms/linux/appimage/test_create.py +++ b/tests/platforms/linux/appimage/test_create.py @@ -23,7 +23,7 @@ def test_default_options(create_command): """The default options are as expected.""" options, overrides = create_command.parse_options([]) - assert options == {} + assert options == {"force": False} assert overrides == {} assert create_command.use_docker @@ -33,7 +33,7 @@ def test_options(create_command): """The extra options can be parsed.""" options, overrides = create_command.parse_options(["--no-docker"]) - assert options == {} + assert options == {"force": False} assert overrides == {} assert not create_command.use_docker diff --git a/tests/platforms/linux/system/test_create.py b/tests/platforms/linux/system/test_create.py index 68498ecf9..71325dd40 100644 --- a/tests/platforms/linux/system/test_create.py +++ b/tests/platforms/linux/system/test_create.py @@ -9,7 +9,7 @@ def test_default_options(create_command): """The default options are as expected.""" options, overrides = create_command.parse_options([]) - assert options == {} + assert options == {"force": False} assert overrides == {} assert create_command.target_image is None @@ -26,7 +26,7 @@ def test_options(create_command): ] ) - assert options == {} + assert options == {"force": False} assert overrides == {} assert create_command.target_image == "somevendor:surprising"