Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console app on convert #2089

Merged
merged 20 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
)
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved

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
Loading