Skip to content

Commit

Permalink
Console app on convert (#2089)
Browse files Browse the repository at this point in the history
When using the convert wizard, the user is now prompted to confirm if the app is a console app or a GUI app.

Co-authored-by: logan keede <logan@logan.logan>
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
  • Loading branch information
3 people authored Dec 31, 2024
1 parent 93b3520 commit aa1f5d9
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
1 change: 1 addition & 0 deletions changes/1900.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The "briefcase convert" command can now be used to configure a console-based applications.
10 changes: 9 additions & 1 deletion src/briefcase/bootstraps/console.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from __future__ import annotations

from typing import Any

from briefcase.bootstraps.base import BaseGuiBootstrap


class ConsoleBootstrap(BaseGuiBootstrap):
display_name_annotation = "does not support iOS/Android/Web deployment"

def extra_context(self) -> dict[str, Any] | None:
return {
"console_app": True,
}

def app_source(self):
return """\
Expand All @@ -22,7 +31,6 @@ def app_start_source(self):

def pyproject_table_briefcase_app_extra_content(self):
return """
console_app = true
requires = [
]
test_requires = [
Expand Down
26 changes: 25 additions & 1 deletion src/briefcase/commands/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,23 @@ def input_url(self, app_name, override_value: str | None) -> str:

return url

def input_console_app(self, override_value: str | None) -> bool:
"""Ask about whether the app is a console application.
:returns: console_app
"""
options = ["GUI", "Console"]
return (
self.select_option(
intro="Is this a GUI application or a console application?",
variable="interface style",
default=None,
options=options,
override_value=override_value,
)
== "Console"
)

def input_bundle(self, url, app_name, override_value: str | None) -> str:
default = ".".join(reversed(urlparse(url).netloc.split(".")))
return self.input_text(
Expand Down Expand Up @@ -603,7 +620,14 @@ def build_gui_context(
# already is set up for a GUI-framework, then those dependencies should already be listed.
# To prevent the same dependency being listed twice (once in the PEP621-section and once in the
# briefcase-section), possibly with different versions, we set the GUI-framework to None here.
return {"gui_framework": "None"}

console_app = self.input_console_app(
override_value=project_overrides.pop("console_app", None)
)
return {
"gui_framework": "None",
"console_app": console_app,
}

def merge_or_copy_pyproject(self, briefcase_config_file: Path) -> None:
"""Merge pyproject.toml file made by the cookiecutter with the one in the
Expand Down
6 changes: 3 additions & 3 deletions tests/commands/convert/test_build_gui_context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def test_overrides_are_not_used(convert_command):
overrides = {"gui_framework": "Toga"}
def test_overrides_are_used(convert_command):
overrides = {"gui_framework": "Toga", "console_app": "Console"}
out = convert_command.build_gui_context({}, overrides)
assert out == {"gui_framework": "None"}
assert out == {"gui_framework": "None", "console_app": True}
assert overrides == {"gui_framework": "Toga"}
33 changes: 33 additions & 0 deletions tests/commands/convert/test_input_console_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest


def test_overrides_are_used_for_console(convert_command):
overrides = {"console_app": "Console"}
out = convert_command.build_gui_context({}, overrides)
assert out == {"console_app": True, "gui_framework": "None"}


def test_overrides_are_used_for_GUI(convert_command):
overrides = {"console_app": "GUI"}
out = convert_command.build_gui_context({}, overrides)
assert out == {"console_app": False, "gui_framework": "None"}


@pytest.mark.parametrize(
"input, result",
[
# A GUI app
(["1"], False),
# A console app
(["2"], True),
# Default value is False (GUI app)
([""], False),
# Invalid values are rejected until a valid value is provided.
(["x", "y", "2"], True),
],
)
def test_app_type(convert_command, input, result):
"""The user can be asked for the app type."""
convert_command.input.values = input
out = convert_command.input_console_app(None)
assert out == result
2 changes: 1 addition & 1 deletion tests/commands/new/test_build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def test_question_sequence_console(new_command):
test_source_dir="tests",
project_name="My Project",
url="https://navy.mil/myapplication",
console_app=True,
app_source="""\
def main():
Expand All @@ -363,7 +364,6 @@ def main():
main()
""",
pyproject_table_briefcase_app_extra_content="""
console_app = true
requires = [
]
test_requires = [
Expand Down

0 comments on commit aa1f5d9

Please sign in to comment.