[cleanup] Misc fixes
Closes #3565, https://github.com/yt-dlp/yt-dlp/issues/3514#issuecomment-1105944364
This commit is contained in:
parent
0a41f331cc
commit
1d485a1a79
19 changed files with 75 additions and 42 deletions
|
|
@ -1,9 +1,28 @@
|
|||
import collections
|
||||
import contextlib
|
||||
import importlib
|
||||
import sys
|
||||
import types
|
||||
|
||||
|
||||
_NO_ATTRIBUTE = object()
|
||||
|
||||
_Package = collections.namedtuple('Package', ('name', 'version'))
|
||||
|
||||
|
||||
def get_package_info(module):
|
||||
parent = module.__name__.split('.')[0]
|
||||
parent_module = None
|
||||
with contextlib.suppress(ImportError):
|
||||
parent_module = importlib.import_module(parent)
|
||||
|
||||
for attr in ('__version__', 'version_string', 'version'):
|
||||
version = getattr(parent_module, attr, None)
|
||||
if version is not None:
|
||||
break
|
||||
return _Package(getattr(module, '_yt_dlp__identifier', parent), str(version))
|
||||
|
||||
|
||||
def _is_package(module):
|
||||
try:
|
||||
module.__getattribute__('__path__')
|
||||
|
|
@ -12,9 +31,6 @@ def _is_package(module):
|
|||
return True
|
||||
|
||||
|
||||
_NO_ATTRIBUTE = object()
|
||||
|
||||
|
||||
def passthrough_module(parent, child, *, callback=lambda _: None):
|
||||
parent_module = importlib.import_module(parent)
|
||||
child_module = importlib.import_module(child, parent)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue