From 87e46c3f20b8e599cf93355bbc52d929b2b446f7 Mon Sep 17 00:00:00 2001 From: Kent Pitman Date: Wed, 2 Aug 2023 04:04:26 -0400 Subject: [PATCH] Allow copyright ownwer and copyright title to be a regexp. Make C4 rules use optional 'The' in copyright title. --- dcicutils/license_utils.py | 12 ++++++------ pyproject.toml | 2 +- test/test_license_utils.py | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dcicutils/license_utils.py b/dcicutils/license_utils.py index 4cc1cd5f7..119e96cb0 100644 --- a/dcicutils/license_utils.py +++ b/dcicutils/license_utils.py @@ -275,8 +275,8 @@ def report(message): parsed = cls.parse_simple_license_file(filename=filename) if check_license_title: license_title = parsed['license-title'] - if license_title != check_license_title: - report(f"The license, {license_title!r}, was expected to be {check_license_title!r}.") + if not re.match(check_license_title, license_title): + report(f"The license, {license_title!r}, was expected to match {check_license_title!r}.") if check_copyright_year: if check_copyright_year is True: check_copyright_year = str(datetime.datetime.now().year) @@ -285,8 +285,8 @@ def report(message): report(f"The copyright year, {copyright_year!r}, should have {check_copyright_year!r} at the end.") if check_copyright_owner: copyright_owner = parsed['copyright-owner'] - if copyright_owner != check_copyright_owner: - report(f"The copyright owner, {copyright_owner!r}, was expected to be {check_copyright_owner!r}.") + if not re.match(check_copyright_owner, copyright_owner): + report(f"The copyright owner, {copyright_owner!r}, was expected to match {check_copyright_owner!r}.") class LicenseChecker: @@ -531,7 +531,7 @@ class C4InfrastructureLicenseChecker(LicenseChecker): """ COPYRIGHT_OWNER = "President and Fellows of Harvard College" - LICENSE_TITLE = "The MIT License" + LICENSE_TITLE = "(The )?MIT License" LICENSE_FRAMEWORKS = ['python', 'javascript'] ALLOWED = [ @@ -729,7 +729,7 @@ class C4InfrastructureLicenseChecker(LicenseChecker): # This seems to be a BSD-3-Clause-Modification license. # Ref: https://github.com/Pylons/translationstring/blob/master/LICENSE.txt - # 'translationstring', + 'translationstring', # This seems to be a BSD-3-Clause-Modification license. # Ref: https://github.com/Pylons/venusian/blob/master/LICENSE.txt diff --git a/pyproject.toml b/pyproject.toml index 16490702a..144832980 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcicutils" -version = "7.6.0.2b9" +version = "7.6.0.2b10" description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources" authors = ["4DN-DCIC Team "] license = "MIT" diff --git a/test/test_license_utils.py b/test/test_license_utils.py index 670b5b0e5..78eba6905 100644 --- a/test/test_license_utils.py +++ b/test/test_license_utils.py @@ -457,7 +457,7 @@ def perturb_setup(): def checker(printed, license_warnings): ignored(printed) # tested elsewhere - assert "The license, 'BAD TITLE', was expected to be 'Some License'." in license_warnings + assert "The license, 'BAD TITLE', was expected to match 'Some License'." in license_warnings check_license_checker_full_scenario_failing_generic( perturb_setup=perturb_setup, @@ -491,7 +491,8 @@ def test_license_checker_bad_license_owner(): def checker(printed, license_warnings): ignored(printed) # tested elsewhere - assert (f"The copyright owner, 'Someone different', was expected to be {DEFAULT_COPYRIGHT_OWNER_FOR_TESTING!r}." + assert ((f"The copyright owner, 'Someone different'," + f" was expected to match {DEFAULT_COPYRIGHT_OWNER_FOR_TESTING!r}.") in license_warnings) check_license_checker_full_scenario_failing_generic(