Skip to content

Commit

Permalink
Merge pull request #1851 from rmartin16/license-warning
Browse files Browse the repository at this point in the history
Update warning for pyproject.toml license spec
  • Loading branch information
rmartin16 authored Jun 3, 2024
2 parents f4b6301 + bb3ad79 commit fd89e3a
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 19 deletions.
1 change: 1 addition & 0 deletions changes/1851.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The warning for specifying the license in pyproject.toml was updated to include additional information.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.6.1",
# 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",
]
Expand Down
44 changes: 31 additions & 13 deletions src/briefcase/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
119 changes: 114 additions & 5 deletions tests/config/test_parse_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from io import BytesIO
from unittest.mock import Mock
from unittest.mock import Mock, call

import pytest

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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"
*************************************************************************
"""
),
]
)

0 comments on commit fd89e3a

Please sign in to comment.