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
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import re
import textwrap

from ..base.file_base_check import FileBaseCheck
from ..system.registry import register_beman_standard_check


# [LICENSE.*] checks category.
# All checks in this file extend the LicenseBaseCheck class.
Expand All @@ -14,7 +19,55 @@ def __init__(self, repo_info, beman_standard_check_config):
super().__init__(repo_info, beman_standard_check_config, "LICENSE")


# TODO LICENSE.APPROVED
@register_beman_standard_check("LICENSE.APPROVED")
class LicenseApprovedCheck(LicenseBaseCheck):
def __init__(self, repo_info, beman_standard_check_config):
super().__init__(repo_info, beman_standard_check_config)

def check(self):
content = self.read()

# Regex for LICENSE check
# - fixed header matching
# - non empty body matching
# - fixed footer matching
regex = re.compile(
textwrap.dedent(r"""
^={78}
The Beman Project is under the (Apache License v2\.0 with LLVM Exceptions|Boost Software License 1\.0|MIT License):
={78}

(.+?)

={78}
Software from third parties included in the Beman Project:
={78}
The Beman Project contains third party software which is under different license
terms\. All such code will be identified clearly using at least one of two
mechanisms:
1\) It will be in a separate directory tree with its own `LICENSE\.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2\) It will contain specific license and restriction terms at the top of every
file\.
""").strip(),
re.DOTALL,
)

if not regex.match(content):
self.log(
"LICENSE file does not match the required format. "
"See https://github.com/bemanproject/beman/blob/main/docs/BEMAN_STANDARD.md#licenseapproved for more information."
)
return False

return True

def fix(self):
self.log(
"Please update the LICENSE file to include an approved license. "
"See https://github.com/bemanproject/beman/blob/main/docs/BEMAN_STANDARD.md#licenseapproved for more information."
)


# TODO LICENSE.APACHE_LLVM
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import pytest

from tests.utils.conftest import mock_repo_info, mock_beman_standard_check_config # noqa: F401


@pytest.fixture(autouse=True)
def repo_info(mock_repo_info): # noqa: F811
return mock_repo_info


@pytest.fixture
def beman_standard_check_config(mock_beman_standard_check_config): # noqa: F811
return mock_beman_standard_check_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Dummy LICENSE lines.
# beman-tidy does not actually check the content between the header and the footer.

==============================================================================
Software from third parties included in the Beman Project:
==============================================================================
The Beman Project contains third party software which is under different license
terms. All such code will be identified clearly using at least one of two
mechanisms:
1) It will be in a separate directory tree with its own `LICENSE.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2) It will contain specific license and restriction terms at the top of every
file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
==============================================================================
The Beman Project is under the Apache License v2.0 with LLVM Exceptions:
==============================================================================

# Dummy LICENSE lines.
# beman-tidy does not actually check the content between the header and the footer.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
==============================================================================
The Beman Project is under the Apache License v2.0 with LLVM Exceptions:
==============================================================================

==============================================================================
Software from third parties included in the Beman Project:
==============================================================================
The Beman Project contains third party software which is under different license
terms. All such code will be identified clearly using at least one of two
mechanisms:
1) It will be in a separate directory tree with its own `LICENSE.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2) It will contain specific license and restriction terms at the top of every
file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==============================================================================
The "Extra" Beman Project is under the Apache License v2.0 with LLVM Exceptions:
==============================================================================

# Dummy LICENSE lines.
# beman-tidy does not actually check the content between the header and the footer.

==============================================================================
Software from third parties included in the Beman Project:
==============================================================================
The Beman Project contains third party software which is under different license
terms. All such code will be identified clearly using at least one of two
mechanisms:
1) It will be in a separate directory tree with its own `LICENSE.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2) It will contain specific license and restriction terms at the top of every
file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==============================================================================
The Beman Project is under the Apache License v2.0 with LLVM Exceptions:
==============================================================================

# Dummy LICENSE lines.
# beman-tidy does not actually check the content between the header and the footer.

==============================================================================
"Extra" Software from third parties included in the Beman Project:
==============================================================================
The Beman Project contains third party software which is under different license
terms. All such code will be identified clearly using at least one of two
mechanisms:
1) It will be in a separate directory tree with its own `LICENSE.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2) It will contain specific license and restriction terms at the top of every
file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==============================================================================
The Beman Project is under the Apache License v2.0 with LLVM Exceptions:
==============================================================================

# Dummy LICENSE lines.
# beman-tidy does not actually check the content between the header and the footer.

==============================================================================
Software from third parties included in the Beman Project:
==============================================================================
The Beman Project contains third party software which is under different license
terms. All such code will be identified clearly using at least one of two
mechanisms:
1) It will be in a separate directory tree with its own `LICENSE.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2) It will contain specific license and restriction terms at the top of every
file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==============================================================================
The Beman Project is under the Boost Software License 1.0:
==============================================================================

# Dummy LICENSE lines.
# beman-tidy does not actually check the content between the header and the footer.

==============================================================================
Software from third parties included in the Beman Project:
==============================================================================
The Beman Project contains third party software which is under different license
terms. All such code will be identified clearly using at least one of two
mechanisms:
1) It will be in a separate directory tree with its own `LICENSE.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2) It will contain specific license and restriction terms at the top of every
file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==============================================================================
The Beman Project is under the MIT License:
==============================================================================

# Dummy LICENSE lines.
# beman-tidy does not actually check the content between the header and the footer.

==============================================================================
Software from third parties included in the Beman Project:
==============================================================================
The Beman Project contains third party software which is under different license
terms. All such code will be identified clearly using at least one of two
mechanisms:
1) It will be in a separate directory tree with its own `LICENSE.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2) It will contain specific license and restriction terms at the top of every
file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import pytest
from pathlib import Path

from tests.utils.path_runners import (
run_check_for_each_path,
)

# Actual tested checks.
from beman_tidy.lib.checks.beman_standard.license import (
LicenseApprovedCheck,
)

test_data_prefix = "tests/lib/checks/beman_standard/license/data"
valid_prefix = f"{test_data_prefix}/valid"
invalid_prefix = f"{test_data_prefix}/invalid"


def test__LICENSE_APPROVED__valid(repo_info, beman_standard_check_config):
"""
Test that a valid LICENSE file passes the check.
"""
valid_license_paths = [
# Apache License v2.0 with LLVM Exceptions
Path(f"{valid_prefix}/valid-LICENSE-v1"),
# Boost Software License 1.0
Path(f"{valid_prefix}/valid-LICENSE-v2"),
# MIT License
Path(f"{valid_prefix}/valid-LICENSE-v3"),
]

run_check_for_each_path(
True,
valid_license_paths,
LicenseApprovedCheck,
repo_info,
beman_standard_check_config,
)


def test__LICENSE_APPROVED__invalid(repo_info, beman_standard_check_config):
"""
Test that an invalid LICENSE file fails the check.
"""
invalid_license_paths = [
# Almost valid LICENSE, but without header
Path(f"{invalid_prefix}/invalid-LICENSE-v1"),
# Almost valid LICENSE, but without footer
Path(f"{invalid_prefix}/invalid-LICENSE-v2"),
# Almost valid LICENSE, but not content between header and footer
Path(f"{invalid_prefix}/invalid-LICENSE-v3"),
# Almost valid LICENSE, but not exact header
Path(f"{invalid_prefix}/invalid-LICENSE-v4"),
# Almost valid LICENSE, but not exact footer
Path(f"{invalid_prefix}/invalid-LICENSE-v5"),
]

run_check_for_each_path(
False,
invalid_license_paths,
LicenseApprovedCheck,
repo_info,
beman_standard_check_config,
)


@pytest.mark.skip(reason="NOT implemented")
def test__LICENSE_APPROVED__fix_inplace(repo_info, beman_standard_check_config):
pass