Skip to content

Commit

Permalink
Add support for specify new project overrides from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Nov 22, 2023
1 parent 1687c5e commit b1b1c7e
Show file tree
Hide file tree
Showing 16 changed files with 661 additions and 128 deletions.
2 changes: 1 addition & 1 deletion src/briefcase/commands/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def add_options(self, parser):
dest="run_app",
action="store_false",
default=True,
help="Do not run the app, just install requirements.",
help="Do not run the app, just install requirements",
)
parser.add_argument(
"--test",
Expand Down
325 changes: 237 additions & 88 deletions src/briefcase/commands/new.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/briefcase/commands/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class PackageCommand(BaseCommand):
command = "package"
description = "Package an app for distribution."

ADHOC_SIGN_HELP = "Ignored; signing is not supported."
IDENTITY_HELP = "Ignored; signing is not supported."
ADHOC_SIGN_HELP = "Ignored; signing is not supported"
IDENTITY_HELP = "Ignored; signing is not supported"

@property
def packaging_formats(self):
Expand Down Expand Up @@ -107,13 +107,13 @@ def add_options(self, parser):
"-u",
"--update",
action="store_true",
help="Update the app before building.",
help="Update the app before building",
)
parser.add_argument(
"-p",
"--packaging-format",
dest="packaging_format",
help="Packaging format to use.",
help="Packaging format to use",
default=self.default_packaging_format,
choices=self.packaging_formats,
)
Expand Down
4 changes: 2 additions & 2 deletions src/briefcase/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def add_options(self, parser):
"--list",
dest="list_tools",
action="store_true",
help="List the Briefcase-managed tools that are currently installed.",
help="List the Briefcase-managed tools that are currently installed",
)
parser.add_argument(
"tool_list",
metavar="tool",
nargs="*",
help="The Briefcase-managed tool to upgrade. If no tool is named, all tools will be upgraded.",
help="The Briefcase-managed tool to upgrade. If no tool is named, all tools will be upgraded",
)

def get_tools_to_upgrade(self, tool_list: set[str]) -> list[ManagedTool]:
Expand Down
8 changes: 5 additions & 3 deletions src/briefcase/platforms/android/gradle.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ def add_options(self, parser):
"-d",
"--device",
dest="device_or_avd",
help="The device to target; either a device ID for a physical device, "
" or an AVD name ('@emulatorName') ",
help=(
"The device to target; either a device ID for a physical device, "
" or an AVD name ('@emulatorName') "
),
required=False,
)
parser.add_argument(
Expand All @@ -253,7 +255,7 @@ def add_options(self, parser):
parser.add_argument(
"--shutdown-on-exit",
action="store_true",
help="Shutdown the emulator on exit.",
help="Shutdown the emulator on exit",
required=False,
)

Expand Down
4 changes: 2 additions & 2 deletions src/briefcase/platforms/macOS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ def sign_app(self, app, identity):
class macOSPackageMixin(macOSSigningMixin):
ADHOC_SIGN_HELP = (
"Perform ad-hoc signing on the app. "
"The app will only run on this machine; it cannot be redistributed to others."
"The app will only run on this machine; it cannot be redistributed to others"
)
IDENTITY_HELP = (
"The code signing identity to use; either the 40-digit hex "
"checksum, or the full name of the identity."
"checksum, or the full name of the identity"
)

@property
Expand Down
2 changes: 1 addition & 1 deletion src/briefcase/platforms/web/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def add_options(self, parser):
"--no-browser",
action="store_false",
dest="open_browser",
help="Don't open a web browser on the newly opened server.",
help="Don't open a web browser on the newly opened server",
required=False,
)

Expand Down
12 changes: 6 additions & 6 deletions src/briefcase/platforms/windows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class WindowsPackageCommand(PackageCommand):
"Your app will be reported as coming from an unverified publisher."
)

IDENTITY_HELP = "The 40-digit hex checksum of the code signing identity to use."
IDENTITY_HELP = "The 40-digit hex checksum of the code signing identity to use"

@property
def packaging_formats(self):
Expand All @@ -185,15 +185,15 @@ def add_options(self, parser):
super().add_options(parser)
parser.add_argument(
"--file-digest",
help="File digest algorithm to use for code signing; defaults to sha256.",
help="File digest algorithm to use for code signing; defaults to sha256",
default="sha256",
required=False,
)
parser.add_argument(
"--use-local-machine-stores",
help=(
"Specifies the code signing certificate is stored in the Local Machine's "
"stores instead of the Current User's."
"stores instead of the Current User's"
),
action="store_true",
dest="use_local_machine",
Expand All @@ -203,7 +203,7 @@ def add_options(self, parser):
"--cert-store",
help=(
"The internal Windows name for the certificate store containing the certificate "
"for code signing; defaults to 'My' for the Personal store."
"for code signing; defaults to 'My' for the Personal store"
),
default="My",
required=False,
Expand All @@ -212,7 +212,7 @@ def add_options(self, parser):
"--timestamp-url",
help=(
"URL for the Timestamp Authority server to timestamp the code signing; "
"defaults to timestamp.digicert.com."
"defaults to timestamp.digicert.com"
),
default="http://timestamp.digicert.com",
required=False,
Expand All @@ -221,7 +221,7 @@ def add_options(self, parser):
"--timestamp-digest",
help=(
"Digest algorithm to request the Timestamp Authority server uses "
"for the timestamp for code signing; defaults to sha256."
"for the timestamp for code signing; defaults to sha256"
),
default="sha256",
required=False,
Expand Down
80 changes: 80 additions & 0 deletions tests/commands/new/test_build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_question_sequence_toga(new_command):
template_source="https://example.com/beeware/briefcase-template",
template_branch="my-branch",
briefcase_version=Version("1.1.1.post1"),
project_overrides={},
)

assert context == dict(
Expand Down Expand Up @@ -268,6 +269,7 @@ def test_question_sequence_pyside6(new_command):
template_source="https://example.com/beeware/briefcase-template",
template_branch="my-branch",
briefcase_version=Version("1.1.1.post1"),
project_overrides={},
)

assert context == dict(
Expand Down Expand Up @@ -458,6 +460,7 @@ def test_question_sequence_pursuedpybear(new_command):
template_source="https://example.com/beeware/briefcase-template",
template_branch="my-branch",
briefcase_version=Version("1.1.1.post1"),
project_overrides={},
)

assert context == dict(
Expand Down Expand Up @@ -625,6 +628,7 @@ def test_question_sequence_pygame(new_command):
template_source="https://example.com/beeware/briefcase-template",
template_branch="my-branch",
briefcase_version=Version("1.1.1.post1"),
project_overrides={},
)

assert context == dict(
Expand Down Expand Up @@ -793,6 +797,7 @@ def test_question_sequence_none(new_command):
template_source="https://example.com/beeware/briefcase-template",
template_branch="my-branch",
briefcase_version=Version("1.1.1.post1"),
project_overrides={},
)

assert context == dict(
Expand All @@ -813,6 +818,78 @@ def test_question_sequence_none(new_command):
)


def test_question_sequence_with_overrides(
new_command, mock_builtin_bootstraps, monkeypatch
):
"""Questions are asked, a context is constructed."""

# Prime answers for all the questions.
new_command.input.values = [
"My Application", # formal name
"", # app name - accept the default
"org.beeware", # bundle ID
"My Project", # project name
"Cool stuff", # description
"Grace Hopper", # author
"grace@navy.mil", # author email
"https://navy.mil/myapplication", # URL
"4", # license
"5", # None
]

class GuiBootstrap:
fields = []

def __init__(self, context):
pass

monkeypatch.setattr(
briefcase.commands.new,
"get_gui_bootstraps",
MagicMock(
return_value=dict(
**mock_builtin_bootstraps,
**{"Custom GUI": GuiBootstrap},
),
),
)

context = new_command.build_context(
template_source="https://example.com/beeware/briefcase-template",
template_branch="my-branch",
briefcase_version=Version("1.1.1.post1"),
project_overrides=dict(
formal_name="My Override App",
app_name="myoverrideapp",
bundle="net.example",
project_name="My Override Project",
description="My override description",
author="override, author",
author_email="author@override.tld",
url="https://override.example.com",
license="MIT license",
bootstrap="Custom GUI",
),
)

assert context == dict(
app_name="myoverrideapp",
author="override, author",
author_email="author@override.tld",
bundle="net.example",
class_name="MyOverrideApp",
description="My override description",
formal_name="My Override App",
license="MIT license",
module_name="myoverrideapp",
project_name="My Override Project",
url="https://override.example.com",
template_source="https://example.com/beeware/briefcase-template",
template_branch="my-branch",
briefcase_version="1.1.1.post1",
)


def test_question_sequence_with_no_user_input(new_command):
"""If no user input is provided, all user inputs are taken as default."""

Expand All @@ -822,6 +899,7 @@ def test_question_sequence_with_no_user_input(new_command):
template_source="https://example.com/beeware/briefcase-template",
template_branch="my-branch",
briefcase_version=Version("1.1.1.post1"),
project_overrides={},
)

assert context == dict(
Expand Down Expand Up @@ -1077,6 +1155,7 @@ def platform(self):
template_source="https://example.com/beeware/briefcase-template",
template_branch="my-branch",
briefcase_version=Version("1.1.1.post1"),
project_overrides={},
)

assert context == dict(
Expand Down Expand Up @@ -1148,6 +1227,7 @@ def platform(self):
template_source="https://example.com/beeware/briefcase-template",
template_branch="my-branch",
briefcase_version=Version("1.1.1.post1"),
project_overrides={},
)

assert context == dict(
Expand Down
20 changes: 17 additions & 3 deletions tests/commands/new/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@ def test_parse_config(new_command):
assert new_command.parse_config("some_file.toml", {}) is None


def test_new_app(new_command):
@pytest.mark.parametrize(
"cmdline, overrides",
[
([], {}),
(["-Q", "license=MIT"], {"license": "MIT"}),
(
["-Q", "license=MIT", "-Q", "bootstrap=Toga"],
{"license": "MIT", "bootstrap": "Toga"},
),
],
)
def test_new_app(new_command, cmdline, overrides):
"""A new application can be created."""

# Configure no command line options
options, _ = new_command.parse_options([])
options, _ = new_command.parse_options(cmdline)

# Run the run command
new_command(**options)
Expand All @@ -40,5 +51,8 @@ def test_new_app(new_command):
# Tools are verified
("verify-tools",),
# Run the first app
("new", {"template": None, "template_branch": None}),
(
"new",
{"template": None, "template_branch": None, "project_overrides": overrides},
),
]
Loading

0 comments on commit b1b1c7e

Please sign in to comment.