From b223ba99d91b769898983d1dad03c71adfcab9f1 Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Fri, 23 Dec 2022 15:25:39 +0100 Subject: [PATCH 1/9] yamllinter: raise if actual patch files are not coherent with conandata.yml It can happen if: -conadata.yml patches section reference some files which do not exist - or if some patches exist in patches subfolder, but not in conandata.yml --- linter/conandata_yaml_linter.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/linter/conandata_yaml_linter.py b/linter/conandata_yaml_linter.py index e55abd40a32c1..3270e6100dd96 100644 --- a/linter/conandata_yaml_linter.py +++ b/linter/conandata_yaml_linter.py @@ -61,6 +61,9 @@ def main(): sys.exit(1) exit_code = 0 + patches_path = os.path.join(os.dirname(args.path), "patches") + actual_patches = os.listdir(patches_path) + unused_patches = copy.copy(actual_patches) if "patches" in parsed: for version in parsed["patches"]: patches = parsed["patches"][version] @@ -73,6 +76,25 @@ def main(): exit_code = 1 continue + if not patch["patch_file"].startswith("patches/"): + print( + f"::error file={args.path},line={type.start_line},endline={type.end_line}," + f"title=conandata.yml patch path error" + f"::'patches' should be located in `patches` subfolder" + ) + exit_code = 1 + else: + patch_file_name = patch["patch_file"][8:] + if patch_file_name in unused_patches: + unused_patches.remove("patch_file_name") + if patch_file_name not in actual_patches: + print( + f"::error file={args.path},line={type.start_line},endline={type.end_line}," + f"title=conandata.yml patch existence" + f"::The file `{patch_file_name}` does not exist in the `patches` folder" + ) + exit_code = 1 + # Make sure `patch_source` exists where it's encouraged type = parsed["patches"][version][i]["patch_type"] if ( @@ -97,7 +119,14 @@ def main(): " layouts (see https://docs.conan.io/en/latest/reference/conanfile/tools/layout.html) and" " the new helper (see https://docs.conan.io/en/latest/reference/conanfile/tools/files/patches.html#conan-tools-files-apply-conandata-patches)" ) - + for p in unused_patches: + print( + f"::error file={patches_path}," + f"title=patch file unused" + f"::Patch file {p} is not referenced in {args.path}" + ) + exit_code = 1 + sys.exit(exit_code) From 10b0a1b2811f02469268e7bd7cbe4cdaa61feed9 Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Fri, 23 Dec 2022 15:30:08 +0100 Subject: [PATCH 2/9] Update conandata_yaml_linter.py --- linter/conandata_yaml_linter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linter/conandata_yaml_linter.py b/linter/conandata_yaml_linter.py index 3270e6100dd96..5fbb999b717a8 100644 --- a/linter/conandata_yaml_linter.py +++ b/linter/conandata_yaml_linter.py @@ -1,3 +1,4 @@ +import os import argparse import sys from strictyaml import ( @@ -126,7 +127,7 @@ def main(): f"::Patch file {p} is not referenced in {args.path}" ) exit_code = 1 - + sys.exit(exit_code) From 7514e68470f74ed93f9a5bb705646d489dbe0e1f Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Fri, 23 Dec 2022 15:33:47 +0100 Subject: [PATCH 3/9] Update conandata_yaml_linter.py --- linter/conandata_yaml_linter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/linter/conandata_yaml_linter.py b/linter/conandata_yaml_linter.py index 5fbb999b717a8..43277ffdf0371 100644 --- a/linter/conandata_yaml_linter.py +++ b/linter/conandata_yaml_linter.py @@ -1,5 +1,6 @@ -import os import argparse +import copy +import os import sys from strictyaml import ( load, @@ -62,7 +63,7 @@ def main(): sys.exit(1) exit_code = 0 - patches_path = os.path.join(os.dirname(args.path), "patches") + patches_path = os.path.join(os.path.dirname(args.path), "patches") actual_patches = os.listdir(patches_path) unused_patches = copy.copy(actual_patches) if "patches" in parsed: From 426c5464de48b8982af0e3eb5d6411483174715f Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Fri, 23 Dec 2022 15:51:59 +0100 Subject: [PATCH 4/9] Update conandata_yaml_linter.py --- linter/conandata_yaml_linter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linter/conandata_yaml_linter.py b/linter/conandata_yaml_linter.py index 43277ffdf0371..3f17bf963628c 100644 --- a/linter/conandata_yaml_linter.py +++ b/linter/conandata_yaml_linter.py @@ -64,7 +64,7 @@ def main(): exit_code = 0 patches_path = os.path.join(os.path.dirname(args.path), "patches") - actual_patches = os.listdir(patches_path) + actual_patches = os.listdir(patches_path) if os.path.isdir(patches_path) else [] unused_patches = copy.copy(actual_patches) if "patches" in parsed: for version in parsed["patches"]: @@ -78,7 +78,7 @@ def main(): exit_code = 1 continue - if not patch["patch_file"].startswith("patches/"): + if not str(patch["patch_file"]).startswith("patches/"): print( f"::error file={args.path},line={type.start_line},endline={type.end_line}," f"title=conandata.yml patch path error" From 4eb8c09c3f7bd055d22dab97147f5c107ef9c64c Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Fri, 23 Dec 2022 16:00:05 +0100 Subject: [PATCH 5/9] Update conandata_yaml_linter.py --- linter/conandata_yaml_linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linter/conandata_yaml_linter.py b/linter/conandata_yaml_linter.py index 3f17bf963628c..672c75d218efb 100644 --- a/linter/conandata_yaml_linter.py +++ b/linter/conandata_yaml_linter.py @@ -88,7 +88,7 @@ def main(): else: patch_file_name = patch["patch_file"][8:] if patch_file_name in unused_patches: - unused_patches.remove("patch_file_name") + unused_patches.remove(patch_file_name) if patch_file_name not in actual_patches: print( f"::error file={args.path},line={type.start_line},endline={type.end_line}," From 9644214bebc58b2b3f14f62c4341977782bf1373 Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Fri, 23 Dec 2022 16:19:15 +0100 Subject: [PATCH 6/9] Update conandata_yaml_linter.py --- linter/conandata_yaml_linter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/linter/conandata_yaml_linter.py b/linter/conandata_yaml_linter.py index 672c75d218efb..94540a2d42328 100644 --- a/linter/conandata_yaml_linter.py +++ b/linter/conandata_yaml_linter.py @@ -78,7 +78,8 @@ def main(): exit_code = 1 continue - if not str(patch["patch_file"]).startswith("patches/"): + patch_file_name = str(patch["patch_file"]) + if not patch_file_name.startswith("patches/"): print( f"::error file={args.path},line={type.start_line},endline={type.end_line}," f"title=conandata.yml patch path error" @@ -86,12 +87,12 @@ def main(): ) exit_code = 1 else: - patch_file_name = patch["patch_file"][8:] + patch_file_name = patch_file_name[8:] if patch_file_name in unused_patches: unused_patches.remove(patch_file_name) if patch_file_name not in actual_patches: print( - f"::error file={args.path},line={type.start_line},endline={type.end_line}," + f"::error file={args.path},line={patch['patch_file'].start_line},endline={patch['patch_file'].end_line}," f"title=conandata.yml patch existence" f"::The file `{patch_file_name}` does not exist in the `patches` folder" ) From bf5b7e36a2e45077da01b9718120063d1e9516d7 Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Fri, 23 Dec 2022 15:28:40 +0000 Subject: [PATCH 7/9] fixup --- linter/conandata_yaml_linter.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/linter/conandata_yaml_linter.py b/linter/conandata_yaml_linter.py index 94540a2d42328..cdabfafe29e42 100644 --- a/linter/conandata_yaml_linter.py +++ b/linter/conandata_yaml_linter.py @@ -70,14 +70,6 @@ def main(): for version in parsed["patches"]: patches = parsed["patches"][version] for i, patch in enumerate(patches): - # Individual report errors for each patch object - try: - parsed["patches"][version][i].revalidate(patch_fields) - except YAMLValidationError as error: - pretty_print_yaml_validate_error(args, error) - exit_code = 1 - continue - patch_file_name = str(patch["patch_file"]) if not patch_file_name.startswith("patches/"): print( @@ -98,6 +90,14 @@ def main(): ) exit_code = 1 + # Individual report errors for each patch object + try: + parsed["patches"][version][i].revalidate(patch_fields) + except YAMLValidationError as error: + pretty_print_yaml_validate_error(args, error) + exit_code = 1 + continue + # Make sure `patch_source` exists where it's encouraged type = parsed["patches"][version][i]["patch_type"] if ( From 373bb2a00168115d245f791f0c16539c4ed7f50a Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Fri, 23 Dec 2022 15:41:38 +0000 Subject: [PATCH 8/9] fixup --- linter/conandata_yaml_linter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/linter/conandata_yaml_linter.py b/linter/conandata_yaml_linter.py index cdabfafe29e42..9e9033af79f9f 100644 --- a/linter/conandata_yaml_linter.py +++ b/linter/conandata_yaml_linter.py @@ -64,7 +64,11 @@ def main(): exit_code = 0 patches_path = os.path.join(os.path.dirname(args.path), "patches") - actual_patches = os.listdir(patches_path) if os.path.isdir(patches_path) else [] + actual_patches = [] + if os.path.isdir(patches_path): + for root, _, files in os.walk(patches_path): + for f in files: + actual_patches.append(os.path.join(root[len(patches_path)+1:], f)) unused_patches = copy.copy(actual_patches) if "patches" in parsed: for version in parsed["patches"]: From df6786f38fa16c4c5f1d3b0578a5068663cb273b Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Fri, 27 Jan 2023 11:28:26 +0100 Subject: [PATCH 9/9] Update conandata_yaml_linter.py --- linter/conandata_yaml_linter.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/linter/conandata_yaml_linter.py b/linter/conandata_yaml_linter.py index dfa33a49b0e59..a7fff2641bd76 100644 --- a/linter/conandata_yaml_linter.py +++ b/linter/conandata_yaml_linter.py @@ -79,7 +79,6 @@ def main(): f"title=conandata.yml patch path error" f"::'patches' should be located in `patches` subfolder" ) - exit_code = 1 else: patch_file_name = patch_file_name[8:] if patch_file_name in unused_patches: @@ -90,7 +89,6 @@ def main(): f"title=conandata.yml patch existence" f"::The file `{patch_file_name}` does not exist in the `patches` folder" ) - exit_code = 1 # Individual report errors for each patch object try: @@ -129,7 +127,6 @@ def main(): f"title=patch file unused" f"::Patch file {p} is not referenced in {args.path}" ) - exit_code = 1 def pretty_print_yaml_validate_error(args, error):