Make globals internal-only

This commit is contained in:
coletdjnz 2024-10-19 16:25:36 +13:00
parent 4266658602
commit 413ae7693b
No known key found for this signature in database
GPG key ID: 91984263BB39894A
9 changed files with 14 additions and 13 deletions

View file

@ -11,7 +11,7 @@ sys.path.append(str(TEST_DATA_DIR))
importlib.invalidate_caches() importlib.invalidate_caches()
from yt_dlp.plugins import PACKAGE_NAME, PluginType, directories, load_plugins from yt_dlp.plugins import PACKAGE_NAME, PluginType, directories, load_plugins
from yt_dlp.globals import extractors, postprocessors from yt_dlp._globals import extractors, postprocessors
class TestPlugins(unittest.TestCase): class TestPlugins(unittest.TestCase):

View file

@ -33,7 +33,7 @@ from .downloader.rtmp import rtmpdump_version
from .extractor import gen_extractor_classes, get_info_extractor, import_extractors from .extractor import gen_extractor_classes, get_info_extractor, import_extractors
from .extractor.common import UnsupportedURLIE from .extractor.common import UnsupportedURLIE
from .extractor.openload import PhantomJSwrapper from .extractor.openload import PhantomJSwrapper
from .globals import ( from ._globals import (
IN_CLI, IN_CLI,
LAZY_EXTRACTORS, LAZY_EXTRACTORS,
plugin_ies, plugin_ies,

View file

@ -20,7 +20,7 @@ from .downloader.external import get_external_downloader
from .extractor import list_extractor_classes from .extractor import list_extractor_classes
from .extractor.adobepass import MSO_INFO from .extractor.adobepass import MSO_INFO
from .networking.impersonate import ImpersonateTarget from .networking.impersonate import ImpersonateTarget
from .globals import IN_CLI, plugin_dirs from ._globals import IN_CLI, plugin_dirs
from .options import parseOpts from .options import parseOpts
from .plugins import load_all_plugin_types from .plugins import load_all_plugin_types
from .postprocessor import ( from .postprocessor import (

View file

@ -1,7 +1,7 @@
from collections import defaultdict from collections import defaultdict
from contextvars import ContextVar from contextvars import ContextVar
# NAME = 'yt-dlp' # Internal only - no backwards compatibility guaranteed
postprocessors = ContextVar('postprocessors', default={}) postprocessors = ContextVar('postprocessors', default={})
extractors = ContextVar('extractors', default={}) extractors = ContextVar('extractors', default={})

View file

@ -1,5 +1,5 @@
from .._globals import extractors as _extractors_context
from ..compat.compat_utils import passthrough_module from ..compat.compat_utils import passthrough_module
from ..globals import extractors as _extractors_context
passthrough_module(__name__, '.extractors') passthrough_module(__name__, '.extractors')
del passthrough_module del passthrough_module

View file

@ -1,8 +1,8 @@
import inspect import inspect
import os import os
from ..globals import LAZY_EXTRACTORS from .._globals import LAZY_EXTRACTORS
from ..globals import extractors as _extractors_context from .._globals import extractors as _extractors_context
_CLASS_LOOKUP = None _CLASS_LOOKUP = None
if not os.environ.get('YTDLP_NO_LAZY_EXTRACTORS'): if not os.environ.get('YTDLP_NO_LAZY_EXTRACTORS'):

View file

@ -17,7 +17,7 @@ from contextvars import ContextVar
from pathlib import Path from pathlib import Path
from zipfile import ZipFile from zipfile import ZipFile
from .globals import ( from ._globals import (
extractors, extractors,
plugin_dirs, plugin_dirs,
plugin_ies, plugin_ies,
@ -268,7 +268,7 @@ def load_plugins(plugin_type: PluginType):
regular_classes.update(get_regular_modules(plugins, spec.name, suffix)) regular_classes.update(get_regular_modules(plugins, spec.name, suffix))
# Configure override classes # Configure override classes
for name, klass in override_classes.items(): for _, klass in override_classes.items():
plugin_name = getattr(klass, '_plugin_name', None) plugin_name = getattr(klass, '_plugin_name', None)
if not plugin_name: if not plugin_name:
# these should always have plugin_name # these should always have plugin_name
@ -298,6 +298,7 @@ def load_all_plugin_types():
for plugin_type in PluginType: for plugin_type in PluginType:
load_plugins(plugin_type) load_plugins(plugin_type)
sys.meta_path.insert(0, PluginFinder(f'{PACKAGE_NAME}.extractor', f'{PACKAGE_NAME}.postprocessor')) sys.meta_path.insert(0, PluginFinder(f'{PACKAGE_NAME}.extractor', f'{PACKAGE_NAME}.postprocessor'))
__all__ = [ __all__ = [

View file

@ -33,7 +33,7 @@ from .movefilesafterdownload import MoveFilesAfterDownloadPP
from .sponskrub import SponSkrubPP from .sponskrub import SponSkrubPP
from .sponsorblock import SponsorBlockPP from .sponsorblock import SponsorBlockPP
from .xattrpp import XAttrMetadataPP from .xattrpp import XAttrMetadataPP
from ..globals import plugin_pps, postprocessors from .._globals import plugin_pps, postprocessors
from ..plugins import PACKAGE_NAME from ..plugins import PACKAGE_NAME
from ..utils import deprecation_warning from ..utils import deprecation_warning

View file

@ -52,7 +52,7 @@ from ..compat import (
compat_os_name, compat_os_name,
) )
from ..dependencies import xattr from ..dependencies import xattr
from ..globals import IN_CLI from .._globals import IN_CLI
__name__ = __name__.rsplit('.', 1)[0] # noqa: A001: Pretend to be the parent module __name__ = __name__.rsplit('.', 1)[0] # noqa: A001: Pretend to be the parent module