earlyinit refactor: Use programmatic imports.
This commit is contained in:
parent
18e56eca90
commit
3234d9a821
@ -109,11 +109,7 @@ def main():
|
|||||||
log.init.debug("Doing early init.")
|
log.init.debug("Doing early init.")
|
||||||
earlyinit.fix_harfbuzz(args)
|
earlyinit.fix_harfbuzz(args)
|
||||||
earlyinit.check_qt_version()
|
earlyinit.check_qt_version()
|
||||||
earlyinit.check_pyqt_webkit()
|
earlyinit.check_libraries()
|
||||||
earlyinit.check_pkg_resources()
|
|
||||||
earlyinit.check_pypeg2()
|
|
||||||
earlyinit.check_jinja2()
|
|
||||||
earlyinit.check_pygments()
|
|
||||||
# We do this import late as we need to fix harfbuzz first.
|
# We do this import late as we need to fix harfbuzz first.
|
||||||
from qutebrowser import app
|
from qutebrowser import app
|
||||||
from PyQt5.QtCore import pyqtRemoveInputHook
|
from PyQt5.QtCore import pyqtRemoveInputHook
|
||||||
|
@ -214,68 +214,45 @@ def check_qt_version():
|
|||||||
_die(text, exception=False)
|
_die(text, exception=False)
|
||||||
|
|
||||||
|
|
||||||
def check_pyqt_webkit():
|
def check_libraries():
|
||||||
"""Check if PyQt WebKit is installed."""
|
"""Check if all needed Python libraries are installed."""
|
||||||
try:
|
import importlib
|
||||||
import PyQt5.QtWebKit # pylint: disable=unused-variable
|
modules = {
|
||||||
except ImportError:
|
'PyQt5.QtWebKit':
|
||||||
text = _missing_str("QtWebKit",
|
_missing_str("QtWebKit",
|
||||||
debian="apt-get install python3-pyqt5.qtwebkit",
|
debian="apt-get install python3-pyqt5.qtwebkit",
|
||||||
arch="pacman -S qt5-webkit")
|
arch="pacman -S qt5-webkit"),
|
||||||
_die(text)
|
'pkg_resources':
|
||||||
|
_missing_str("pkg_resources",
|
||||||
|
debian="apt-get install python3-pkg-resources",
|
||||||
def check_pkg_resources():
|
arch="pacman -S python-setuptools",
|
||||||
"""Check if pkg_resources is installed."""
|
windows="Run python -m ensurepip "
|
||||||
try:
|
"(python >= 3.4) or scripts/ez_setup.py."),
|
||||||
import pkg_resources # pylint: disable=unused-variable
|
'pypeg2':
|
||||||
except ImportError:
|
_missing_str("pypeg2",
|
||||||
text = _missing_str("pkg_resources",
|
debian="No package available, do 'apt-get install "
|
||||||
debian="apt-get install python3-pkg-resources",
|
"python3-pip' and then install via pip3.",
|
||||||
arch="pacman -S python-setuptools",
|
arch="Install python-pypeg2 from the AUR",
|
||||||
windows="Run python -m ensurepip "
|
windows="Install via pip.",
|
||||||
"(python >= 3.4) or scripts/ez_setup.py.")
|
pip="pypeg2 --allow-external pypeg2 "
|
||||||
_die(text)
|
"--allow-unverified pypeg2"),
|
||||||
|
'jinja2':
|
||||||
|
_missing_str("jinja2",
|
||||||
def check_pypeg2():
|
debian="apt-get install python3-jinja2",
|
||||||
"""Check if pypeg2 is installed."""
|
arch="Install python-jinja from the AUR",
|
||||||
try:
|
windows="Install from http://www.lfd.uci.edu/"
|
||||||
import pypeg2 # pylint: disable=unused-variable
|
"~gohlke/pythonlibs/#jinja2 or via pip.",
|
||||||
except ImportError:
|
pip="jinja2"),
|
||||||
text = _missing_str("pypeg2",
|
'pygments':
|
||||||
debian="No package available, do 'apt-get install "
|
_missing_str("pygments",
|
||||||
"python3-pip' and then install via pip3.",
|
debian="apt-get install python3-pygments",
|
||||||
arch="Install python-pypeg2 from the AUR",
|
arch="Install python-jinja from the AUR",
|
||||||
windows="Install via pip.",
|
windows="Install from http://www.lfd.uci.edu/"
|
||||||
pip="pypeg2 --allow-external pypeg2 "
|
"~gohlke/pythonlibs/#pygments or via pip.",
|
||||||
"--allow-unverified pypeg2")
|
pip="pygments"),
|
||||||
_die(text)
|
}
|
||||||
|
for name, text in modules.items():
|
||||||
|
try:
|
||||||
def check_jinja2():
|
importlib.import_module(name)
|
||||||
"""Check if jinja2 is installed."""
|
except ImportError:
|
||||||
try:
|
_die(text)
|
||||||
import jinja2 # pylint: disable=unused-variable
|
|
||||||
except ImportError:
|
|
||||||
text = _missing_str("jinja2",
|
|
||||||
debian="apt-get install python3-jinja2",
|
|
||||||
arch="Install python-jinja from the AUR",
|
|
||||||
windows="Install from http://www.lfd.uci.edu/"
|
|
||||||
"~gohlke/pythonlibs/#jinja2 or via pip.",
|
|
||||||
pip="jinja2")
|
|
||||||
_die(text)
|
|
||||||
|
|
||||||
|
|
||||||
def check_pygments():
|
|
||||||
"""Check if pygments is installed."""
|
|
||||||
try:
|
|
||||||
import pygments # pylint: disable=unused-variable
|
|
||||||
except ImportError:
|
|
||||||
text = _missing_str("pygments",
|
|
||||||
debian="apt-get install python3-pygments",
|
|
||||||
arch="Install python-jinja from the AUR",
|
|
||||||
windows="Install from http://www.lfd.uci.edu/"
|
|
||||||
"~gohlke/pythonlibs/#pygments or via pip.",
|
|
||||||
pip="pygments")
|
|
||||||
_die(text)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user