Skip to content
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/2327.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed `test_mode` to an app property
13 changes: 5 additions & 8 deletions src/briefcase/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(
self,
console: Console,
tools: ToolCache = None,
apps: dict = None,
apps: dict[str, AppConfig] = None,
base_path: Path = None,
data_path: Path = None,
is_clone: bool = False,
Expand Down Expand Up @@ -631,7 +631,7 @@ def finalize_app_config(self, app: AppConfig):
:param app: The app configuration to finalize.
"""

def finalize(self, app: AppConfig | None = None):
def finalize(self, app: AppConfig | None = None, test_mode: bool = False):
"""Finalize Briefcase configuration.

This will:
Expand All @@ -648,13 +648,10 @@ def finalize(self, app: AppConfig | None = None):
self.verify_host()
self.verify_tools()

if app is None:
for app in self.apps.values():
if hasattr(app, "__draft__"):
self.finalize_app_config(app)
delattr(app, "__draft__")
else:
apps = self.apps.values() if app is None else [app]
for app in apps:
if hasattr(app, "__draft__"):
app.test_mode = test_mode
self.finalize_app_config(app)
delattr(app, "__draft__")

Expand Down
14 changes: 5 additions & 9 deletions src/briefcase/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def _build_app(
update_support: bool,
update_stub: bool,
no_update: bool,
test_mode: bool,
**options,
) -> dict | None:
"""Internal method to invoke a build on a single app. Ensures the app exists,
Expand All @@ -56,18 +55,17 @@ def _build_app(
:param update_support: Should the application support be updated?
:param update_stub: Should the stub binary be updated?
:param no_update: Should automated updates be disabled?
:param test_mode: Is the app being build in test mode?
"""
if not self.bundle_path(app).exists():
state = self.create_command(app, test_mode=test_mode, **options)
state = self.create_command(app, **options)
elif (
update # An explicit update has been requested
or update_requirements # An explicit update of requirements has been requested
or update_resources # An explicit update of resources has been requested
or update_support # An explicit update of app support has been requested
or update_stub # An explicit update of the stub binary has been requested
or (
test_mode and not no_update
app.test_mode and not no_update
) # Test mode, but updates have not been disabled
):
state = self.update_command(
Expand All @@ -76,17 +74,16 @@ def _build_app(
update_resources=update_resources,
update_support=update_support,
update_stub=update_stub,
test_mode=test_mode,
**options,
)
else:
state = None

self.verify_app(app)

state = self.build_app(app, test_mode=test_mode, **full_options(state, options))
state = self.build_app(app, **full_options(state, options))

qualifier = " (test mode)" if test_mode else ""
qualifier = " (test mode)" if app.test_mode else ""
self.console.info(
f"Built {self.binary_path(app).relative_to(self.base_path)}{qualifier}",
prefix=app.app_name,
Expand Down Expand Up @@ -132,7 +129,7 @@ def __call__(

# Confirm host compatibility, that all required tools are available,
# and that the app configuration is finalized.
self.finalize(app)
self.finalize(app, test_mode)

if app_name:
try:
Expand All @@ -156,7 +153,6 @@ def __call__(
update_support=update_support,
update_stub=update_stub,
no_update=no_update,
test_mode=test_mode,
**full_options(state, options),
)

Expand Down
19 changes: 7 additions & 12 deletions src/briefcase/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def _install_app_requirements(
else:
self.console.info("No application requirements.")

def install_app_requirements(self, app: AppConfig, test_mode: bool):
def install_app_requirements(self, app: AppConfig):
"""Handle requirements for the app.

This will result in either (in preferential order):
Expand All @@ -679,16 +679,13 @@ def install_app_requirements(self, app: AppConfig, test_mode: bool):
* requirements being installed with pip into the location specified
by the ``app_packages_path`` in the template path index.

If ``test_mode`` is True, the test requirements will also be installed.

If the path index doesn't specify either of the path index entries,
an error is raised.

:param app: The config object for the app
:param test_mode: Should the test requirements be installed?
"""
requires = app.requires.copy() if app.requires else []
if test_mode and app.test_requires:
if app.test_mode and app.test_requires:
requires.extend(app.test_requires)

try:
Expand Down Expand Up @@ -717,11 +714,10 @@ def install_app_requirements(self, app: AppConfig, test_mode: bool):
"`app_requirements_path` or `app_packages_path`"
) from e

def install_app_code(self, app: AppConfig, test_mode: bool):
def install_app_code(self, app: AppConfig):
"""Install the application code into the bundle.

:param app: The config object for the app
:param test_mode: Should the application test code also be installed?
"""
# Remove existing app folder if it exists
app_path = self.app_path(app)
Expand All @@ -730,7 +726,7 @@ def install_app_code(self, app: AppConfig, test_mode: bool):
self.tools.os.mkdir(app_path)

sources = app.sources.copy() if app.sources else []
if test_mode and app.test_sources:
if app.test_mode and app.test_sources:
sources.extend(app.test_sources)

# Install app code.
Expand Down Expand Up @@ -912,11 +908,10 @@ def cleanup_app_content(self, app: AppConfig):
self.console.verbose(f"Removing {relative_path}")
path.unlink()

def create_app(self, app: AppConfig, test_mode: bool = False, **options):
def create_app(self, app: AppConfig, **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)
"""
if not app.supported:
raise UnsupportedPlatform(self.platform)
Expand Down Expand Up @@ -957,10 +952,10 @@ def create_app(self, app: AppConfig, test_mode: bool = False, **options):
self.verify_app(app)

self.console.info("Installing application code...", prefix=app.app_name)
self.install_app_code(app=app, test_mode=test_mode)
self.install_app_code(app=app)

self.console.info("Installing requirements...", prefix=app.app_name)
self.install_app_requirements(app=app, test_mode=test_mode)
self.install_app_requirements(app=app)

self.console.info("Installing application resources...", prefix=app.app_name)
self.install_app_resources(app=app)
Expand Down
18 changes: 7 additions & 11 deletions src/briefcase/commands/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,16 @@ def run_dev_app(
self,
app: AppConfig,
env: dict,
test_mode: bool,
passthrough: list[str],
**options,
):
"""Run the app in the dev environment.

:param app: The config object for the app
:param env: environment dictionary for sub command
:param test_mode: Run the test suite, rather than the app?
:param passthrough: A list of arguments to pass to the app
"""
main_module = app.main_module(test_mode)
main_module = app.main_module()

# Add in the environment settings to get Python in the state we want.
env.update(self.DEV_ENVIRONMENT)
Expand All @@ -145,7 +143,7 @@ def run_dev_app(
# Console apps must operate in non-streaming mode so that console input can
# be handled correctly. However, if we're in test mode, we *must* stream so
# that we can see the test exit sentinel
if app.console_app and not test_mode:
if app.console_app and not app.test_mode:
self.console.info("=" * 75)
self.tools.subprocess.run(
cmdline,
Expand All @@ -170,16 +168,15 @@ def run_dev_app(
self._stream_app_logs(
app,
popen=app_popen,
test_mode=test_mode,
clean_output=False,
)

def get_environment(self, app, test_mode: bool):
def get_environment(self, app: AppConfig):
# Create a shell environment where PYTHONPATH points to the source
# directories described by the app config.
env = {
"PYTHONPATH": os.pathsep.join(
os.fsdecode(Path.cwd() / path) for path in app.PYTHONPATH(test_mode)
os.fsdecode(Path.cwd() / path) for path in app.PYTHONPATH()
)
}

Expand Down Expand Up @@ -223,7 +220,7 @@ def __call__(
)
# Confirm host compatibility, that all required tools are available,
# and that the app configuration is finalized.
self.finalize(app)
self.finalize(app, test_mode)

self.verify_app(app)

Expand All @@ -243,17 +240,16 @@ def __call__(
write_dist_info(app, dist_info_path)

if run_app:
if test_mode:
if app.test_mode:
self.console.info(
"Running test suite in dev environment...", prefix=app.app_name
)
else:
self.console.info("Starting in dev mode...", prefix=app.app_name)
env = self.get_environment(app, test_mode=test_mode)
env = self.get_environment(app)
return self.run_dev_app(
app,
env,
test_mode=test_mode,
passthrough=[] if passthrough is None else passthrough,
**options,
)
17 changes: 6 additions & 11 deletions src/briefcase/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def _stream_app_logs(
self,
app: AppConfig,
popen,
test_mode=False,
clean_filter=None,
clean_output=False,
stop_func=lambda: False,
Expand All @@ -143,7 +142,6 @@ def _stream_app_logs(
:param app: The app to be launched
:param popen: The Popen object for the stream we are monitoring; this Popen
process will be closed after log streaming completes.
:param test_mode: Are we launching in test mode?
:param clean_filter: The log cleaning filter to use; see ``LogFilter``
for details.
:param clean_output: Should the cleaned output be presented to the user?
Expand Down Expand Up @@ -179,7 +177,7 @@ def _stream_app_logs(

# If we're in test mode, and log streaming ends,
# check for the status of the test suite.
if test_mode:
if app.test_mode:
if log_filter.returncode == 0:
self.console.info("Test suite passed!", prefix=app.app_name)
else:
Expand Down Expand Up @@ -220,14 +218,13 @@ def add_options(self, parser):
self._add_update_options(parser, context_label=" before running")
self._add_test_options(parser, context_label="Run")

def _prepare_app_kwargs(self, app: AppConfig, test_mode: bool):
def _prepare_app_kwargs(self, app: AppConfig):
"""Prepare the kwargs for running an app as a log stream.

This won't be used by every backend; but it's a sufficiently common default that
it's been factored out.

:param app: The app to be launched
:param test_mode: Are we launching in test mode?
:returns: A dictionary of additional arguments to pass to the Popen
"""
args = {}
Expand All @@ -237,10 +234,10 @@ def _prepare_app_kwargs(self, app: AppConfig, test_mode: bool):
if self.console.is_debug:
env["BRIEFCASE_DEBUG"] = "1"

if test_mode:
if app.test_mode:
# In test mode, set a BRIEFCASE_MAIN_MODULE environment variable
# to override the module at startup
env["BRIEFCASE_MAIN_MODULE"] = app.main_module(test_mode)
env["BRIEFCASE_MAIN_MODULE"] = app.main_module()
self.console.info("Starting test_suite...", prefix=app.app_name)
else:
self.console.info("Starting app...", prefix=app.app_name)
Expand Down Expand Up @@ -290,7 +287,7 @@ def __call__(

# Confirm host compatibility, that all required tools are available,
# and that the app configuration is finalized.
self.finalize(app)
self.finalize(app, test_mode)

template_file = self.bundle_path(app)
exec_file = self.binary_executable_path(app)
Expand All @@ -303,7 +300,7 @@ def __call__(
or update_stub # An explicit update of the stub binary has been requested
or (not exec_file.exists()) # Executable binary doesn't exist yet
or (
test_mode and not no_update
app.test_mode and not no_update
) # Test mode, but updates have not been disabled
):
state = self.build_command(
Expand All @@ -314,7 +311,6 @@ def __call__(
update_support=update_support,
update_stub=update_stub,
no_update=no_update,
test_mode=test_mode,
**options,
)
else:
Expand All @@ -324,7 +320,6 @@ def __call__(

state = self.run_app(
app,
test_mode=test_mode,
passthrough=[] if passthrough is None else passthrough,
**full_options(state, options),
)
Expand Down
9 changes: 3 additions & 6 deletions src/briefcase/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def update_app(
update_resources: bool,
update_support: bool,
update_stub: bool,
test_mode: bool,
**options,
) -> dict | None:
"""Update an existing application bundle.
Expand All @@ -42,7 +41,6 @@ def update_app(
:param update_resources: Should extra resources be updated?
:param update_support: Should app support be updated?
:param update_stub: Should stub binary be updated?
:param test_mode: Should the app be updated in test mode?
"""

if not self.bundle_path(app).exists():
Expand All @@ -54,11 +52,11 @@ def update_app(
self.verify_app(app)

self.console.info("Updating application code...", prefix=app.app_name)
self.install_app_code(app=app, test_mode=test_mode)
self.install_app_code(app=app)

if update_requirements:
self.console.info("Updating requirements...", prefix=app.app_name)
self.install_app_requirements(app=app, test_mode=test_mode)
self.install_app_requirements(app=app)

if update_resources:
self.console.info("Updating application resources...", prefix=app.app_name)
Expand Down Expand Up @@ -100,7 +98,7 @@ def __call__(
) -> dict | None:
# Confirm host compatibility, that all required tools are available,
# and that the app configuration is finalized.
self.finalize(app)
self.finalize(app, test_mode)

if app_name:
try:
Expand All @@ -122,7 +120,6 @@ def __call__(
update_resources=update_resources,
update_support=update_support,
update_stub=update_stub,
test_mode=test_mode,
**full_options(state, options),
)

Expand Down
Loading