From 66ce674afb59068d8197d75f5a8631c8f379a722 Mon Sep 17 00:00:00 2001 From: Russell Martin Date: Thu, 30 May 2024 12:07:14 -0400 Subject: [PATCH 1/4] Update warning for pyproject.toml license spec --- changes/1851.misc.rst | 1 + src/briefcase/config.py | 44 +++++++---- tests/config/test_parse_config.py | 119 ++++++++++++++++++++++++++++-- 3 files changed, 146 insertions(+), 18 deletions(-) create mode 100644 changes/1851.misc.rst diff --git a/changes/1851.misc.rst b/changes/1851.misc.rst new file mode 100644 index 000000000..55b6ae7fb --- /dev/null +++ b/changes/1851.misc.rst @@ -0,0 +1 @@ +The warning for specifying the license in pyproject.toml was updated to include additional information. diff --git a/src/briefcase/config.py b/src/briefcase/config.py index e100e93cd..c1d793642 100644 --- a/src/briefcase/config.py +++ b/src/briefcase/config.py @@ -478,6 +478,37 @@ def parse_config(config_file, platform, output_format, logger): except KeyError as e: raise BriefcaseConfigError("No Briefcase apps defined in pyproject.toml") from e + for name, config in [("project", global_config)] + list(all_apps.items()): + if isinstance(config.get("license"), str): + section_name = "the Project" if name == "project" else f"{name!r}" + logger.warning( + f""" +************************************************************************* +** {f"WARNING: License Definition for {section_name} is Deprecated":67} ** +************************************************************************* + + Briefcase now uses PEP 621 format for license definitions. + + Previously, the name of the license was assigned to the 'license' + field in pyproject.toml. For PEP 621, the name of the license is + assigned to 'license.text' or the name of the file containing the + license is assigned to 'license.file'. + + The current configuration for {section_name} has a 'license' field + that is specified as a string: + + license = "{config['license']}" + + To use the PEP 621 format (and to remove this warning), specify that + the LICENSE file contains the license for {section_name}: + + license.file = "LICENSE" + +************************************************************************* +""" + ) + config["license"] = {"file": "LICENSE"} + # Build the flat configuration for each app, # based on the requested platform and output format app_configs = {} @@ -550,17 +581,4 @@ def parse_config(config_file, platform, output_format, logger): # of configurations that are being handled. app_configs[app_name] = config - old_license_format = False - for config in [global_config, *app_configs.values()]: - if isinstance(config.get("license"), str): - config["license"] = {"file": "LICENSE"} - old_license_format = True - - if old_license_format: - logger.warning( - "Your app configuration has a `license` field that is specified as a string. " - "Briefcase now uses PEP 621 format for license definitions. To silence this " - 'warning, replace the `license` declaration with `license.file = "LICENSE".' - ) - return global_config, app_configs diff --git a/tests/config/test_parse_config.py b/tests/config/test_parse_config.py index 45b0bae9d..b48caee95 100644 --- a/tests/config/test_parse_config.py +++ b/tests/config/test_parse_config.py @@ -1,5 +1,5 @@ from io import BytesIO -from unittest.mock import Mock +from unittest.mock import Mock, call import pytest @@ -701,7 +701,8 @@ def test_pep621_defaults(): } -def test_license_is_string(): +def test_license_is_string_project(): + """The project definition contains a string definition for 'license'.""" config_file = BytesIO( b""" [tool.briefcase] @@ -729,7 +730,115 @@ def test_license_is_string(): "license": {"file": "LICENSE"}, } logger.warning.assert_called_once_with( - "Your app configuration has a `license` field that is specified as a string. " - "Briefcase now uses PEP 621 format for license definitions. To silence this " - 'warning, replace the `license` declaration with `license.file = "LICENSE".' + """ +************************************************************************* +** WARNING: License Definition for the Project is Deprecated ** +************************************************************************* + + Briefcase now uses PEP 621 format for license definitions. + + Previously, the name of the license was assigned to the 'license' + field in pyproject.toml. For PEP 621, the name of the license is + assigned to 'license.text' or the name of the file containing the + license is assigned to 'license.file'. + + The current configuration for the Project has a 'license' field + that is specified as a string: + + license = "Some license" + + To use the PEP 621 format (and to remove this warning), specify that + the LICENSE file contains the license for the Project: + + license.file = "LICENSE" + +************************************************************************* +""" + ) + + +def test_license_is_string_project_and_app(): + """The project and app definition contain a string definition for 'license'.""" + config_file = BytesIO( + b""" + [tool.briefcase] + value = 0 + license = "Some license" + + [tool.briefcase.app.my_app] + appvalue = "the app" + license = "Another license" + """ + ) + + logger = Mock() + global_options, apps = parse_config( + config_file, platform="macOS", output_format="app", logger=logger + ) + + assert global_options == { + "value": 0, + "license": {"file": "LICENSE"}, + } + assert apps["my_app"] == { + "app_name": "my_app", + "value": 0, + "appvalue": "the app", + "license": {"file": "LICENSE"}, + } + logger.warning.assert_has_calls( + [ + call( + """ +************************************************************************* +** WARNING: License Definition for the Project is Deprecated ** +************************************************************************* + + Briefcase now uses PEP 621 format for license definitions. + + Previously, the name of the license was assigned to the 'license' + field in pyproject.toml. For PEP 621, the name of the license is + assigned to 'license.text' or the name of the file containing the + license is assigned to 'license.file'. + + The current configuration for the Project has a 'license' field + that is specified as a string: + + license = "Some license" + + To use the PEP 621 format (and to remove this warning), specify that + the LICENSE file contains the license for the Project: + + license.file = "LICENSE" + +************************************************************************* +""" + ), + call( + """ +************************************************************************* +** WARNING: License Definition for 'my_app' is Deprecated ** +************************************************************************* + + Briefcase now uses PEP 621 format for license definitions. + + Previously, the name of the license was assigned to the 'license' + field in pyproject.toml. For PEP 621, the name of the license is + assigned to 'license.text' or the name of the file containing the + license is assigned to 'license.file'. + + The current configuration for 'my_app' has a 'license' field + that is specified as a string: + + license = "Another license" + + To use the PEP 621 format (and to remove this warning), specify that + the LICENSE file contains the license for 'my_app': + + license.file = "LICENSE" + +************************************************************************* +""" + ), + ] ) From 53e69586911d8acca362a6953ac1013b08e36e67 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 3 Jun 2024 11:06:54 +0800 Subject: [PATCH 2/4] Speculation... is xdist the problem? --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 47e37ac27..863696553 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,7 +102,6 @@ dev = [ "pre-commit == 3.5.0 ; python_version < '3.9'", "pre-commit == 3.7.1 ; python_version >= '3.9'", "pytest == 8.2.1", - "pytest-xdist == 3.6.1", "setuptools_scm == 8.1.0", "tox == 4.15.0", ] From 23810b0ee80a9aa548edbad5e4decf450492460f Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 3 Jun 2024 11:25:41 +0800 Subject: [PATCH 3/4] Revert to previous xdist release. --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 863696553..a58eb8acd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,6 +102,7 @@ dev = [ "pre-commit == 3.5.0 ; python_version < '3.9'", "pre-commit == 3.7.1 ; python_version >= '3.9'", "pytest == 8.2.1", + "pytest-xdist == 3.5.0", "setuptools_scm == 8.1.0", "tox == 4.15.0", ] From bb3ad799c0da80a7e84d69f83f058ae74da684be Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 3 Jun 2024 12:12:28 +0800 Subject: [PATCH 4/4] Only disable pytest for Python 3.13 (for now). --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a58eb8acd..9b57e6c20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,7 +102,8 @@ dev = [ "pre-commit == 3.5.0 ; python_version < '3.9'", "pre-commit == 3.7.1 ; python_version >= '3.9'", "pytest == 8.2.1", - "pytest-xdist == 3.5.0", + # Having xdist in the pytest environment causes some weird failures on Windows with Py3.13 + "pytest-xdist == 3.6.1 ; python_version < '3.13'", "setuptools_scm == 8.1.0", "tox == 4.15.0", ]