From eb561dd371cb0ae7825ac2fc281ffb7fd1cfe720 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 31 Oct 2024 20:07:31 +0100 Subject: [PATCH 1/8] Remove `os.link` compatibility for Windows. Support for Windows exists since Py 3.2 See: https://docs.python.org/3/library/os.html#os.link --- client/ayon_core/lib/path_tools.py | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/client/ayon_core/lib/path_tools.py b/client/ayon_core/lib/path_tools.py index 5c81fbfebf..efe2556afe 100644 --- a/client/ayon_core/lib/path_tools.py +++ b/client/ayon_core/lib/path_tools.py @@ -38,31 +38,7 @@ def create_hard_link(src_path, dst_path): dst_path(str): Full path to a file where a link of source will be added. """ - # Use `os.link` if is available - # - should be for all platforms with newer python versions - if hasattr(os, "link"): - os.link(src_path, dst_path) - return - - # Windows implementation of hardlinks - # - used in Python 2 - if platform.system().lower() == "windows": - import ctypes - from ctypes.wintypes import BOOL - CreateHardLink = ctypes.windll.kernel32.CreateHardLinkW - CreateHardLink.argtypes = [ - ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_void_p - ] - CreateHardLink.restype = BOOL - - res = CreateHardLink(dst_path, src_path, None) - if res == 0: - raise ctypes.WinError() - return - # Raises not implemented error if gets here - raise NotImplementedError( - "Implementation of hardlink for current environment is missing." - ) + os.link(src_path, dst_path) def collect_frames(files): From 0a970abed6bcccb2755f70af189959ca00c6b3d9 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 31 Oct 2024 20:11:52 +0100 Subject: [PATCH 2/8] Remove Python 2 code. `unicode` does not exist in Py3+ --- client/ayon_core/lib/log.py | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/client/ayon_core/lib/log.py b/client/ayon_core/lib/log.py index 36c39f9d84..1ed16b36ff 100644 --- a/client/ayon_core/lib/log.py +++ b/client/ayon_core/lib/log.py @@ -11,12 +11,12 @@ import copy from . import Terminal -# Check for `unicode` in builtins -USE_UNICODE = hasattr(__builtins__, "unicode") - class LogStreamHandler(logging.StreamHandler): - """ StreamHandler class designed to handle utf errors in python 2.x hosts. + """StreamHandler class. + + This was originally designed to handle UTF errors in python 2.x hosts, + however currently solely remains for backwards compatibility. """ @@ -47,27 +47,7 @@ class LogStreamHandler(logging.StreamHandler): stream = self.stream if stream is None: return - fs = "%s\n" - # if no unicode support... - if not USE_UNICODE: - stream.write(fs % msg) - else: - try: - if (isinstance(msg, unicode) and # noqa: F821 - getattr(stream, 'encoding', None)): - ufs = u'%s\n' - try: - stream.write(ufs % msg) - except UnicodeEncodeError: - stream.write((ufs % msg).encode(stream.encoding)) - else: - if (getattr(stream, 'encoding', 'utf-8')): - ufs = u'%s\n' - stream.write(ufs % unicode(msg)) # noqa: F821 - else: - stream.write(fs % msg) - except UnicodeError: - stream.write(fs % msg.encode("UTF-8")) + stream.write(f"{msg}\n") self.flush() except (KeyboardInterrupt, SystemExit): raise From 9f9c03179a6ab3bec5dfe3f8e757be6baf8cc055 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 31 Oct 2024 20:16:16 +0100 Subject: [PATCH 3/8] Fix enabled check + fix docstrings --- client/ayon_core/lib/log.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/ayon_core/lib/log.py b/client/ayon_core/lib/log.py index 1ed16b36ff..d619310eb8 100644 --- a/client/ayon_core/lib/log.py +++ b/client/ayon_core/lib/log.py @@ -25,21 +25,21 @@ class LogStreamHandler(logging.StreamHandler): self.enabled = True def enable(self): - """ Enable StreamHandler + """Enable StreamHandler - Used to silence output + Make StreamHandler output again """ self.enabled = True def disable(self): - """ Disable StreamHandler + """Disable StreamHandler - Make StreamHandler output again + Used to silence output """ self.enabled = False def emit(self, record): - if not self.enable: + if not self.enabled: return try: msg = self.format(record) From 300e086c8d4075b39e5627e1a68e7cfa6a6c8793 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 31 Oct 2024 20:28:59 +0100 Subject: [PATCH 4/8] Update client/ayon_core/lib/log.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/lib/log.py b/client/ayon_core/lib/log.py index d619310eb8..d392610f32 100644 --- a/client/ayon_core/lib/log.py +++ b/client/ayon_core/lib/log.py @@ -39,7 +39,7 @@ class LogStreamHandler(logging.StreamHandler): self.enabled = False def emit(self, record): - if not self.enabled: + if not self.enabled or self.stream is None: return try: msg = self.format(record) From 01bd1594f5bbabb21cfb85ee312064bbbe9c7a7b Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 31 Oct 2024 20:29:31 +0100 Subject: [PATCH 5/8] Remove condition that was moved up --- client/ayon_core/lib/log.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/ayon_core/lib/log.py b/client/ayon_core/lib/log.py index d392610f32..692df93dad 100644 --- a/client/ayon_core/lib/log.py +++ b/client/ayon_core/lib/log.py @@ -45,8 +45,6 @@ class LogStreamHandler(logging.StreamHandler): msg = self.format(record) msg = Terminal.log(msg) stream = self.stream - if stream is None: - return stream.write(f"{msg}\n") self.flush() except (KeyboardInterrupt, SystemExit): From d4ace0706c90e032bdea5139cdc8e690b2f2c673 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 31 Oct 2024 20:30:53 +0100 Subject: [PATCH 6/8] Remove unused import --- client/ayon_core/lib/path_tools.py | 1 - 1 file changed, 1 deletion(-) diff --git a/client/ayon_core/lib/path_tools.py b/client/ayon_core/lib/path_tools.py index efe2556afe..c6a833f43a 100644 --- a/client/ayon_core/lib/path_tools.py +++ b/client/ayon_core/lib/path_tools.py @@ -1,7 +1,6 @@ import os import re import logging -import platform import clique From df9821f928af8f26863f502737f863cd39778ef9 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 31 Oct 2024 20:31:21 +0100 Subject: [PATCH 7/8] Fix typo --- client/ayon_core/lib/path_tools.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/ayon_core/lib/path_tools.py b/client/ayon_core/lib/path_tools.py index c6a833f43a..ebd22b43c5 100644 --- a/client/ayon_core/lib/path_tools.py +++ b/client/ayon_core/lib/path_tools.py @@ -185,7 +185,7 @@ def get_last_version_from_path(path_dir, filter): assert isinstance(filter, list) and ( len(filter) != 0), "`filter` argument needs to be list and not empty" - filtred_files = list() + filtered_files = list() # form regex for filtering pattern = r".*".join(filter) @@ -193,10 +193,10 @@ def get_last_version_from_path(path_dir, filter): for file in os.listdir(path_dir): if not re.findall(pattern, file): continue - filtred_files.append(file) + filtered_files.append(file) - if filtred_files: - sorted(filtred_files) - return filtred_files[-1] + if filtered_files: + sorted(filtered_files) + return filtered_files[-1] return None From a02954d908507538e62de6818d3339ee945ce4fe Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 31 Oct 2024 23:19:23 +0100 Subject: [PATCH 8/8] Fix sorting Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/path_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/lib/path_tools.py b/client/ayon_core/lib/path_tools.py index ebd22b43c5..31baac168c 100644 --- a/client/ayon_core/lib/path_tools.py +++ b/client/ayon_core/lib/path_tools.py @@ -196,7 +196,7 @@ def get_last_version_from_path(path_dir, filter): filtered_files.append(file) if filtered_files: - sorted(filtered_files) + filtered_files.sort() return filtered_files[-1] return None