From c756262216d60dee3bdb6d733a57a7e6b8601321 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Thu, 12 Mar 2020 15:11:47 -0400 Subject: [PATCH 1/6] require license, license_file, and license_family fields --- conda_smithy/lint_recipe.py | 10 ++++++++++ news/req-lic.rst | 25 +++++++++++++++++++++++++ tests/test_lint_recipe.py | 12 ++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 news/req-lic.rst diff --git a/conda_smithy/lint_recipe.py b/conda_smithy/lint_recipe.py index a286bb778..9d9b97d2c 100644 --- a/conda_smithy/lint_recipe.py +++ b/conda_smithy/lint_recipe.py @@ -489,6 +489,16 @@ def lintify(meta, recipe_dir=None, conda_forge=False): ) ) + # 24: make sure that license, license_file, and license_family are all present + license_fields = ["license", "license_file", "license_family"] + for license_field in license_fields: + if license_field not in about_section: + lints.append( + "The ``about: {license_field}:`` entry must exist".format( + license_field=license_field + ) + ) + # hints # 1: suggest pip if "script" in build_section: diff --git a/news/req-lic.rst b/news/req-lic.rst new file mode 100644 index 000000000..88cfe19ec --- /dev/null +++ b/news/req-lic.rst @@ -0,0 +1,25 @@ +**Added:** + +* Linter will now check for the existence of ``license``, ``license_file``, and + ``license_family`` fields in the about section. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* + diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index e0f7c67f3..14fa6e6f1 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -964,6 +964,18 @@ def test_build_sh_with_shellcheck_findings(self): assert "Whenever possible fix all shellcheck findings" in hints[0] assert len(hints) == (50 + 2) + def test_no_licenses(self): + meta = {"about": {"url": "http://example.com"}} + lints, hints = linter.lintify(meta) + license_fields = ["license", "license_file", "license_family"] + for license_field in license_fields: + self.assertIn( + "The ``about: {license_field}:`` entry must exist".format( + license_field=license_field + ), + lints, + ) + @pytest.mark.cli class TestCLI_recipe_lint(unittest.TestCase): From f90063a2287ffa07a32d53e5cd16c5da11fe2e7f Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Thu, 12 Mar 2020 16:31:32 -0400 Subject: [PATCH 2/6] updates --- conda_smithy/lint_recipe.py | 16 ++++++---------- tests/test_lint_recipe.py | 23 +++++++++++++++-------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/conda_smithy/lint_recipe.py b/conda_smithy/lint_recipe.py index 9d9b97d2c..c0dbd29a5 100644 --- a/conda_smithy/lint_recipe.py +++ b/conda_smithy/lint_recipe.py @@ -285,6 +285,8 @@ def lintify(meta, recipe_dir=None, conda_forge=False): # 12a: License family must be valid (conda-build checks for that) license_family = about_section.get("license_family", license).lower() license_file = about_section.get("license_file", "") + if "license" not in about_section: + lints.append("license entry is missing, but is required.") if license_file == "" and any( f for f in NEEDED_FAMILIES if f in license_family ): @@ -489,16 +491,6 @@ def lintify(meta, recipe_dir=None, conda_forge=False): ) ) - # 24: make sure that license, license_file, and license_family are all present - license_fields = ["license", "license_file", "license_family"] - for license_field in license_fields: - if license_field not in about_section: - lints.append( - "The ``about: {license_field}:`` entry must exist".format( - license_field=license_field - ) - ) - # hints # 1: suggest pip if "script" in build_section: @@ -606,6 +598,10 @@ def lintify(meta, recipe_dir=None, conda_forge=False): "There have been errors while scanning with shellcheck." ) + # 4: recommend license_family + if "license_family" not in about_section: + lints.append("license_family entry is missing, but is recommended.") + return lints, hints diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index 14fa6e6f1..252571b59 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -967,14 +967,21 @@ def test_build_sh_with_shellcheck_findings(self): def test_no_licenses(self): meta = {"about": {"url": "http://example.com"}} lints, hints = linter.lintify(meta) - license_fields = ["license", "license_file", "license_family"] - for license_field in license_fields: - self.assertIn( - "The ``about: {license_field}:`` entry must exist".format( - license_field=license_field - ), - lints, - ) + self.assertIn( + "license entry is missing, but is required.", lints, + ) + self.assertIn( + "license_family entry is missing, but is recommended.", hints + ) + + meta["about"]["license"] = "BSD-3-Clause" + lints, hints = linter.lintify(meta) + self.assertIn( + "license_file entry is missing, but is required.", lints, + ) + self.assertIn( + "license_family entry is missing, but is recommended.", hints + ) @pytest.mark.cli From ab6db114fd5a0fdf97ccba4b82275d925102e0b7 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Thu, 12 Mar 2020 16:34:11 -0400 Subject: [PATCH 3/6] Update conda_smithy/lint_recipe.py Co-Authored-By: Isuru Fernando --- conda_smithy/lint_recipe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conda_smithy/lint_recipe.py b/conda_smithy/lint_recipe.py index c0dbd29a5..a1b552255 100644 --- a/conda_smithy/lint_recipe.py +++ b/conda_smithy/lint_recipe.py @@ -600,7 +600,7 @@ def lintify(meta, recipe_dir=None, conda_forge=False): # 4: recommend license_family if "license_family" not in about_section: - lints.append("license_family entry is missing, but is recommended.") + hints.append("license_family entry is missing, but is recommended.") return lints, hints From fe985fc1aa68bd0b3f5d301c29e725442e77a547 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Thu, 12 Mar 2020 16:38:38 -0400 Subject: [PATCH 4/6] +1 --- tests/test_lint_recipe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index 252571b59..771e883d9 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -962,7 +962,7 @@ def test_build_sh_with_shellcheck_findings(self): return_hints=True, ) assert "Whenever possible fix all shellcheck findings" in hints[0] - assert len(hints) == (50 + 2) + assert len(hints) == (50 + 3) def test_no_licenses(self): meta = {"about": {"url": "http://example.com"}} From 55336b94321453061e71b9067695a6eb6ad33d4d Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Thu, 12 Mar 2020 17:53:37 -0400 Subject: [PATCH 5/6] cleanup --- conda_smithy/lint_recipe.py | 2 -- tests/test_lint_recipe.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/conda_smithy/lint_recipe.py b/conda_smithy/lint_recipe.py index a1b552255..ed08762d6 100644 --- a/conda_smithy/lint_recipe.py +++ b/conda_smithy/lint_recipe.py @@ -285,8 +285,6 @@ def lintify(meta, recipe_dir=None, conda_forge=False): # 12a: License family must be valid (conda-build checks for that) license_family = about_section.get("license_family", license).lower() license_file = about_section.get("license_file", "") - if "license" not in about_section: - lints.append("license entry is missing, but is required.") if license_file == "" and any( f for f in NEEDED_FAMILIES if f in license_family ): diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index 771e883d9..d46cfc8db 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -968,7 +968,7 @@ def test_no_licenses(self): meta = {"about": {"url": "http://example.com"}} lints, hints = linter.lintify(meta) self.assertIn( - "license entry is missing, but is required.", lints, + "The license item is expected in the about section.", lints, ) self.assertIn( "license_family entry is missing, but is recommended.", hints From b299f38ce2d43c6b8d7f001005c1324189e4cd85 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Sat, 14 Mar 2020 11:24:27 -0400 Subject: [PATCH 6/6] Update req-lic.rst --- news/req-lic.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/news/req-lic.rst b/news/req-lic.rst index 88cfe19ec..3e5ad33de 100644 --- a/news/req-lic.rst +++ b/news/req-lic.rst @@ -1,7 +1,7 @@ **Added:** -* Linter will now check for the existence of ``license``, ``license_file``, and - ``license_family`` fields in the about section. +* Linter will now hint if the ``license_family`` fields in the about section + doesn't exist. **Changed:**