]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/compat/__init__.py
[cleanup] Consistent style for file heads
[yt-dlp.git] / yt_dlp / compat / __init__.py
index 3c395f6d9689356a70957eabd4403867b744f019..9f8e8c3e534a506f294da3186e60eec6c111224b 100644 (file)
@@ -1,6 +1,4 @@
-import contextlib
 import os
-import subprocess
 import sys
 import warnings
 import xml.etree.ElementTree as etree
@@ -9,10 +7,14 @@
 from ._deprecated import *  # noqa: F401, F403
 from .compat_utils import passthrough_module
 
-
 # XXX: Implement this the same way as other DeprecationWarnings without circular import
-passthrough_module(__name__, '._legacy', callback=lambda attr: warnings.warn(
-    DeprecationWarning(f'{__name__}.{attr} is deprecated'), stacklevel=2))
+try:
+    passthrough_module(__name__, '._legacy', callback=lambda attr: warnings.warn(
+        DeprecationWarning(f'{__name__}.{attr} is deprecated'), stacklevel=2))
+    HAS_LEGACY = True
+except ModuleNotFoundError:
+    # Keep working even without _legacy module
+    HAS_LEGACY = False
 del passthrough_module
 
 
@@ -46,17 +48,13 @@ def compat_ord(c):
     return c if isinstance(c, int) else ord(c)
 
 
-def compat_setenv(key, value, env=os.environ):
-    env[key] = value
-
-
 if compat_os_name == 'nt' and sys.version_info < (3, 8):
     # os.path.realpath on Windows does not follow symbolic links
     # prior to Python 3.8 (see https://bugs.python.org/issue9949)
     def compat_realpath(path):
         while os.path.islink(path):
             path = os.path.abspath(os.readlink(path))
-        return path
+        return os.path.realpath(path)
 else:
     compat_realpath = os.path.realpath
 
@@ -78,17 +76,3 @@ def compat_expanduser(path):
         return userhome + path[i:]
 else:
     compat_expanduser = os.path.expanduser
-
-
-WINDOWS_VT_MODE = False if compat_os_name == 'nt' else None
-
-
-def windows_enable_vt_mode():  # TODO: Do this the proper way https://bugs.python.org/issue30075
-    if compat_os_name != 'nt':
-        return
-    global WINDOWS_VT_MODE
-    startupinfo = subprocess.STARTUPINFO()
-    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
-    with contextlib.suppress(Exception):
-        subprocess.Popen('', shell=True, startupinfo=startupinfo).wait()
-        WINDOWS_VT_MODE = True