Revert "Add AffectedFile.Extension() in presubmit_support"

This reverts commit d447f41294.

Reason for revert: "AttributeError: 'str' object has no attribute 'Extension'"

Original change's description:
> Add AffectedFile.Extension() in presubmit_support
>
> Add convenience method AffectedFile.Extension() for extracting file
> extension in a standard way. Add a test for this new functionality.
> Add a similar test for AffectedFile.UnixLocalPath().
>
> Bug: None
> Change-Id: If591e751fb2e4fb5355ad0b6f93f310667849d68
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6273341
> Commit-Queue: Anton Bershanskyi <bershanskyi@gmail.com>
> Reviewed-by: Dirk Pranke <dpranke@google.com>
> Reviewed-by: Gavin Mak <gavinmak@google.com>

Bug: None
Change-Id: Ic51b0942e3a3267194fb73af5e92c902b2098c4c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6279837
Auto-Submit: Gavin Mak <gavinmak@google.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
This commit is contained in:
Gavin Mak
2025-02-18 15:30:10 -08:00
committed by LUCI CQ
parent d447f41294
commit 9f715f8017
3 changed files with 6 additions and 55 deletions

View File

@@ -1041,10 +1041,10 @@ class AffectedFile(object):
self._path = path
self._action = action
self._local_root = repository_root
self._diff_cache = diff_cache
self._is_directory = None
self._cached_changed_contents = None
self._cached_new_contents = None
self._extension = None
self._diff_cache = diff_cache
self._is_testable_file = None
logging.debug('%s(%s)', self.__class__.__name__, self._path)
@@ -1161,20 +1161,6 @@ class AffectedFile(object):
self._cached_changed_contents = result
return self._cached_changed_contents[:]
def Extension(self):
"""Returns the file extension as a string.
File extension is the portion of file name after the last dot, including the dot.
If file name has no dot (like 'OWNERS'), then returns an empty string ''.
If file has multiple extensions (like 'archive.tar.gz'), then the last
extension is returned (like '.gz')
This method is equivalent to NodeJS node:path method path.extname()
and Python3 pathlib PurePath.suffix() and os.path.splitext()
"""
if self._extension is None:
self._extension = os.path.splitext(self._path)[1]
return self._extension
def __str__(self):
return self.LocalPath()