Skip to content
Open
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/2309.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Briefcase now supports license files with names "LICENCE", "LICENSE" and "COPYING" with the extensions ".rst", ".md" and ".txt".
29 changes: 26 additions & 3 deletions src/briefcase/commands/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,8 @@ def migrate_necessary_files(self, project_dir, test_source_dir, module_name):
self.merge_or_copy_pyproject(project_dir / "pyproject.toml")

# Copy license file if not already there
license_file = self.pep621_data.get("license", {}).get("file")

if license_file is None and not (self.base_path / "LICENSE").exists():
license = find_license_filename()
if license is None:
self.console.warning(
f"\nLicense file not found in '{self.base_path}'. "
"Briefcase will create a template 'LICENSE' file."
Expand Down Expand Up @@ -822,3 +821,27 @@ def find_changelog_filename(base_path):
if changelog.is_file():
return format
return None


def find_license_filename(base_path):
"""Find a valid license file in a given directory.

:param base_Path: The directory to search
:returns: The filename of a license if one is found. Else none if no such
license could be found.
"""
# Collect all possible license file formats.
license_formats = [
f"{name}{extension}"
for name in ["LICENSE", "LICENCE", "COPYING"]
for extension in ["", ".md", ".rst", ".txt"]
]

# If a particular format is found, it returns it as the license.
for file_format in license_formats:
license = base_path / file_format
if license.is_file():
return file_format

# Else, no such license exists and return None.
return None
6 changes: 3 additions & 3 deletions src/briefcase/platforms/linux/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
RunCommand,
UpdateCommand,
)
from briefcase.commands.convert import find_changelog_filename
from briefcase.commands.convert import find_changelog_filename, find_license_filename
from briefcase.config import AppConfig, merge_config
from briefcase.exceptions import BriefcaseCommandError, UnsupportedHostError
from briefcase.integrations.docker import Docker, DockerAppContext
Expand Down Expand Up @@ -736,7 +736,7 @@ def build_app(self, app: AppConfig, **kwargs):

with self.console.wait_bar("Installing license..."):
if license_file := app.license.get("file"):
license_file = self.base_path / license_file
license_file = find_license_filename()
if license_file.is_file():
self.tools.shutil.copy(license_file, doc_folder / "copyright")
else:
Expand Down Expand Up @@ -764,7 +764,7 @@ def build_app(self, app: AppConfig, **kwargs):
"""\
Your project does not contain a LICENSE definition.

Create a file named `LICENSE` in the same directory as your `pyproject.toml`
Create a file named `LICENSE`, `LICENCE` or `COPYING` in the same directory as your `pyproject.toml`
with your app's licensing terms, and set `license.file = 'LICENSE'` in your
app's configuration.
"""
Expand Down
42 changes: 42 additions & 0 deletions tests/commands/convert/test_find_license_filename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest

from briefcase.platforms.linux.system import find_license_filename

from ...utils import create_file


def test_no_license(tmp_path):
"""License file does not exist"""
assert find_license_filename(tmp_path) is None


def test_no_valid_license(tmp_path):
"""License file exists but with invalid name format so its not accepted"""
license_file = tmp_path / "base_path/invalid_license_format"
create_file(license_file, "First App License")
assert find_license_filename(tmp_path / "base_path") is None


@pytest.mark.parametrize(
"license_filename",
[
f"{name}{extension}"
for name in ["LICENSE", "LICENCE", "COPYING"]
for extension in ["", ".md", ".rst", ".txt"]
],
)
def test_has_license(tmp_path, license_filename):
"""Makes sure all formats are accepted"""
license_file = tmp_path / f"base_path/{license_filename}"
create_file(license_file, "First App License")
assert find_license_filename(tmp_path / "base_path") == license_filename


def test_multiple_changefile(tmp_path):
"""If there's more than one license, only one is found."""

license_file1 = tmp_path / "base_path/LICENCE.txt"
license_file2 = tmp_path / "base_path/LICENSE.md"
create_file(license_file1, "First App License")
create_file(license_file2, "First App Licence")
assert find_license_filename(tmp_path / "base_path") == "LICENSE.md"
Loading