From b1c2cffe0196e7630ff37ff003475aa7b4369892 Mon Sep 17 00:00:00 2001 From: dorschw <81086590+dorschw@users.noreply.github.com> Date: Wed, 9 Oct 2024 18:21:19 +0300 Subject: [PATCH] change file_path to path --- .../content_graph/parsers/related_files.py | 14 +++++++------- .../commands/validate/tests/PA_validators_test.py | 6 +++--- .../commands/validate/tests/RN_validators_test.py | 4 ++-- ...S105_is_description_contains_contrib_details.py | 2 +- .../DS106_is_valid_description_name.py | 2 +- .../IM_validators/IM101_image_too_large.py | 2 +- .../IM111_invalid_image_dimensions.py | 6 ++---- .../PA_validators/PA128_validate_pack_files.py | 4 ++-- .../RM_validators/RM106_is_contain_demisto_word.py | 2 +- .../RN_validators/RN112_is_bc_rn_exist.py | 2 +- .../commands/validate/validators/base_validator.py | 6 +++--- 11 files changed, 24 insertions(+), 26 deletions(-) diff --git a/demisto_sdk/commands/content_graph/parsers/related_files.py b/demisto_sdk/commands/content_graph/parsers/related_files.py index 323294f4216..8e1764ab69f 100644 --- a/demisto_sdk/commands/content_graph/parsers/related_files.py +++ b/demisto_sdk/commands/content_graph/parsers/related_files.py @@ -46,7 +46,7 @@ def __init__(self, main_file_path: Path, git_sha: Optional[str] = None) -> None: self.main_file_path: Path = main_file_path self.git_sha = git_sha self.exist: bool = False - self.file_path: Path = self.find_the_right_path(self.get_optional_paths()) + self.path: Path = self.find_the_right_path(self.get_optional_paths()) @property def git_status(self) -> Union[GitStatuses, None]: @@ -56,7 +56,7 @@ def git_status(self) -> Union[GitStatuses, None]: remote, branch = git_util.handle_prev_ver( self.git_sha # type: ignore[arg-type] ) - status = git_util._check_file_status(str(self.file_path), remote, branch) + status = git_util._check_file_status(str(self.path), remote, branch) return None if not status else GitStatuses(status) def find_the_right_path(self, file_paths: List[Path]) -> Path: @@ -94,12 +94,12 @@ def file_content(self) -> str: try: if self.git_sha: self.file_content_str = TextFile.read_from_git_path( - path=self.file_path, + path=self.path, tag=self.git_sha, ) else: self.file_content_str = TextFile.read_from_local_path( - path=self.file_path + path=self.path ) except Exception as e: logger.debug(f"Failed to get related text file, error: {e}") @@ -236,11 +236,11 @@ def load_image(self): class PNGFiles(ImageFiles): def get_file_size(self): - return self.file_path.stat() + return self.path.stat() def load_image(self) -> Union[str, bytearray, memoryview]: encoded_image = "" - with open(self.file_path, "rb") as image: + with open(self.path, "rb") as image: image_data = image.read() encoded_image = base64.b64encode(image_data) # type: ignore if isinstance(encoded_image, bytes): @@ -251,7 +251,7 @@ def load_image(self) -> Union[str, bytearray, memoryview]: class SVGFiles(ImageFiles): def load_image(self) -> bytes: encoded_image = b"" - with open(self.file_path, "rb") as image_file: + with open(self.path, "rb") as image_file: encoded_image = image_file.read() # type: ignore return encoded_image diff --git a/demisto_sdk/commands/validate/tests/PA_validators_test.py b/demisto_sdk/commands/validate/tests/PA_validators_test.py index 75c191bb86c..a9c6e93e439 100644 --- a/demisto_sdk/commands/validate/tests/PA_validators_test.py +++ b/demisto_sdk/commands/validate/tests/PA_validators_test.py @@ -1663,18 +1663,18 @@ def test_PackFilesValidator_fix(file_attribute: str): pack = create_pack_object() meta_file: RelatedFile = getattr(pack, file_attribute) - meta_file.file_path.unlink() + meta_file.path.unlink() meta_file.exist = False assert not meta_file.exist # sanity check - assert not meta_file.file_path.exists() # sanity check + assert not meta_file.path.exists() # sanity check assert PackFilesValidator().obtain_invalid_content_items( [pack] ) # invalid once deleted PackFilesValidator().fix(pack) - assert meta_file.file_path.exists() + assert meta_file.path.exists() assert meta_file.exist # changed in the fix diff --git a/demisto_sdk/commands/validate/tests/RN_validators_test.py b/demisto_sdk/commands/validate/tests/RN_validators_test.py index 51d91e6bf71..7e52dc3fa4f 100644 --- a/demisto_sdk/commands/validate/tests/RN_validators_test.py +++ b/demisto_sdk/commands/validate/tests/RN_validators_test.py @@ -311,8 +311,8 @@ def test_IsBCRNExistValidator_obtain_invalid_content_items(): content_items=content_items ) expected_msgs = [ - f"The release notes contain information about breaking changes but missing a breaking change file, make sure to add one as {str(content_items[1].release_note.file_path).replace('.md', '.json')} and that the file contains the 'breakingChanges' entry.", - f"The release notes contain information about breaking changes but missing a breaking change file, make sure to add one as {str(content_items[2].release_note.file_path).replace('.md', '.json')} and that the file contains the 'breakingChanges' entry.", + f"The release notes contain information about breaking changes but missing a breaking change file, make sure to add one as {str(content_items[1].release_note.path).replace('.md', '.json')} and that the file contains the 'breakingChanges' entry.", + f"The release notes contain information about breaking changes but missing a breaking change file, make sure to add one as {str(content_items[2].release_note.path).replace('.md', '.json')} and that the file contains the 'breakingChanges' entry.", ] assert len(results) == 2 diff --git a/demisto_sdk/commands/validate/validators/DS_validators/DS105_is_description_contains_contrib_details.py b/demisto_sdk/commands/validate/validators/DS_validators/DS105_is_description_contains_contrib_details.py index 11cf9d002eb..834067c5d68 100644 --- a/demisto_sdk/commands/validate/validators/DS_validators/DS105_is_description_contains_contrib_details.py +++ b/demisto_sdk/commands/validate/validators/DS_validators/DS105_is_description_contains_contrib_details.py @@ -35,7 +35,7 @@ def obtain_invalid_content_items( ValidationResult( validator=self, message=self.error_message.format( - content_item.description_file.file_path.name + content_item.description_file.path.name ), content_object=content_item, ) diff --git a/demisto_sdk/commands/validate/validators/DS_validators/DS106_is_valid_description_name.py b/demisto_sdk/commands/validate/validators/DS_validators/DS106_is_valid_description_name.py index 451358cdb12..853ea707cbb 100644 --- a/demisto_sdk/commands/validate/validators/DS_validators/DS106_is_valid_description_name.py +++ b/demisto_sdk/commands/validate/validators/DS_validators/DS106_is_valid_description_name.py @@ -38,7 +38,7 @@ def obtain_invalid_content_items( ValidationResult( validator=self, message=self.error_message.format( - content_item.description_file.file_path.name + content_item.description_file.path.name ), content_object=content_item, ) diff --git a/demisto_sdk/commands/validate/validators/IM_validators/IM101_image_too_large.py b/demisto_sdk/commands/validate/validators/IM_validators/IM101_image_too_large.py index 22437a11247..ee53d543c05 100644 --- a/demisto_sdk/commands/validate/validators/IM_validators/IM101_image_too_large.py +++ b/demisto_sdk/commands/validate/validators/IM_validators/IM101_image_too_large.py @@ -38,7 +38,7 @@ def obtain_invalid_content_items( ] def is_image_valid(self, content_item: ContentTypes): - file_type = content_item.image.file_path.suffix + file_type = content_item.image.path.suffix if file_type == ".png": return content_item.image.get_file_size().st_size > IMAGE_MAX_SIZE diff --git a/demisto_sdk/commands/validate/validators/IM_validators/IM111_invalid_image_dimensions.py b/demisto_sdk/commands/validate/validators/IM_validators/IM111_invalid_image_dimensions.py index 9bdf4c09343..b61a8d9286a 100644 --- a/demisto_sdk/commands/validate/validators/IM_validators/IM111_invalid_image_dimensions.py +++ b/demisto_sdk/commands/validate/validators/IM_validators/IM111_invalid_image_dimensions.py @@ -17,10 +17,8 @@ def is_image_dimensions_valid(content_item: ContentTypes) -> bool: - if content_item.image.file_path.suffix == "png": - return (IMAGE_WIDTH, IMAGE_HEIGHT) == imagesize.get( - content_item.image.file_path - ) + if content_item.image.path.suffix == "png": + return (IMAGE_WIDTH, IMAGE_HEIGHT) == imagesize.get(content_item.image.path) return True diff --git a/demisto_sdk/commands/validate/validators/PA_validators/PA128_validate_pack_files.py b/demisto_sdk/commands/validate/validators/PA_validators/PA128_validate_pack_files.py index 38af00d1b2e..7326fe9fce5 100644 --- a/demisto_sdk/commands/validate/validators/PA_validators/PA128_validate_pack_files.py +++ b/demisto_sdk/commands/validate/validators/PA_validators/PA128_validate_pack_files.py @@ -49,8 +49,8 @@ def obtain_invalid_content_items( def fix(self, content_item: ContentTypes) -> FixResult: for meta_file in find_related_files(content_item): if not meta_file.exist: - logger.debug(f"creating {type(meta_file)} {meta_file.file_path!s}") - meta_file.file_path.touch() + logger.debug(f"creating {type(meta_file)} {meta_file.path!s}") + meta_file.path.touch() meta_file.exist = True return FixResult( diff --git a/demisto_sdk/commands/validate/validators/RM_validators/RM106_is_contain_demisto_word.py b/demisto_sdk/commands/validate/validators/RM_validators/RM106_is_contain_demisto_word.py index 453c5ae0be9..530cbd7ba98 100644 --- a/demisto_sdk/commands/validate/validators/RM_validators/RM106_is_contain_demisto_word.py +++ b/demisto_sdk/commands/validate/validators/RM_validators/RM106_is_contain_demisto_word.py @@ -38,7 +38,7 @@ def obtain_invalid_content_items( ValidationResult( validator=self, message=self.error_message.format(", ".join(lines_contain_demsito)), - content_object=content_item, + content_object=content_item.readme, ) for content_item in content_items if ( diff --git a/demisto_sdk/commands/validate/validators/RN_validators/RN112_is_bc_rn_exist.py b/demisto_sdk/commands/validate/validators/RN_validators/RN112_is_bc_rn_exist.py index ac42950aafe..8cb41a6367e 100644 --- a/demisto_sdk/commands/validate/validators/RN_validators/RN112_is_bc_rn_exist.py +++ b/demisto_sdk/commands/validate/validators/RN_validators/RN112_is_bc_rn_exist.py @@ -30,7 +30,7 @@ def obtain_invalid_content_items( for content_item in content_items: if "breaking change" not in content_item.release_note.file_content: continue - json_path = str(content_item.release_note.file_path).replace(".md", ".json") + json_path = str(content_item.release_note.path).replace(".md", ".json") if Path(json_path).exists(): if ( json_file_content := get_dict_from_file(path=json_path)[0] diff --git a/demisto_sdk/commands/validate/validators/base_validator.py b/demisto_sdk/commands/validate/validators/base_validator.py index 4bf68b6bc52..817e2217521 100644 --- a/demisto_sdk/commands/validate/validators/base_validator.py +++ b/demisto_sdk/commands/validate/validators/base_validator.py @@ -27,7 +27,7 @@ BaseContentMetaclass, ) from demisto_sdk.commands.content_graph.objects.content_item import ContentItem -from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFileType +from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFile, RelatedFileType ContentTypes = TypeVar("ContentTypes", bound=BaseContent) @@ -220,10 +220,10 @@ def get_all_validators_specific_validation( class BaseResult(BaseModel): validator: BaseValidator message: str - content_object: BaseContent + content_object: BaseContent | RelatedFile @property - def format_readable_message(self): + def format_readable_message(self) -> str: path: Path = self.content_object.path if path.is_absolute(): path = path.relative_to(CONTENT_PATH)