diff options
author | Florian Bruhin <me@the-compiler.org> | 2023-12-01 23:35:46 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2023-12-01 23:38:11 +0100 |
commit | b5f11558a6d244bbbc8dd6fb5d819a51648d758e (patch) | |
tree | 7a61adee0a23590d5e018087a8864322a698de33 | |
parent | a2c74ec1bf2a0379d37716adc899ff71a65c1bf1 (diff) | |
download | qutebrowser-b5f11558a6d244bbbc8dd6fb5d819a51648d758e.tar.gz qutebrowser-b5f11558a6d244bbbc8dd6fb5d819a51648d758e.zip |
pdfjs: Simplify logic
Makes things easier if we get build/ right with the return value
-rw-r--r-- | qutebrowser/browser/pdfjs.py | 16 | ||||
-rw-r--r-- | qutebrowser/utils/version.py | 4 | ||||
-rw-r--r-- | tests/unit/utils/test_version.py | 6 |
3 files changed, 10 insertions, 16 deletions
diff --git a/qutebrowser/browser/pdfjs.py b/qutebrowser/browser/pdfjs.py index ad8f54b0d..841285deb 100644 --- a/qutebrowser/browser/pdfjs.py +++ b/qutebrowser/browser/pdfjs.py @@ -202,24 +202,24 @@ def _read_from_system(system_path, names): return (None, None) -def get_pdfjs_basename(): - """Checks for pdf.js main module availability and returns the basename if available.""" - exts = ['pdf.js', 'pdf.mjs'] - for ext in exts: +def get_pdfjs_js_path(): + """Checks for pdf.js main module availability and returns the path if available.""" + paths = ['build/pdf.js', 'build/pdf.mjs'] + for path in paths: try: - get_pdfjs_res('build/' + ext) + get_pdfjs_res(path) except PDFJSNotFound: pass else: - return ext + return path - raise PDFJSNotFound(" or ".join(f"'build/{ext}'" for ext in exts)) + raise PDFJSNotFound(" or ".join(paths)) def is_available(): """Return true if certain parts of a pdfjs installation are available.""" try: - get_pdfjs_basename() + get_pdfjs_js_path() get_pdfjs_res('web/viewer.html') except PDFJSNotFound: return False diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index ac0c8220f..a20774617 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -480,9 +480,7 @@ def _pdfjs_version() -> str: A string with the version number. """ try: - pdfjs_file, file_path = pdfjs.get_pdfjs_res_and_path( - str(pathlib.Path("build") / pdfjs.get_pdfjs_basename()) - ) + pdfjs_file, file_path = pdfjs.get_pdfjs_res_and_path(pdfjs.get_pdfjs_js_path()) except pdfjs.PDFJSNotFound: return 'no' else: diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py index a7b957f59..f8a1925e3 100644 --- a/tests/unit/utils/test_version.py +++ b/tests/unit/utils/test_version.py @@ -885,11 +885,7 @@ class TestPDFJSVersion: def test_real_file(self, data_tmpdir): """Test against the real file if pdfjs was found.""" - try: - pdfjs.get_pdfjs_res_and_path( - str(pathlib.Path("build") / pdfjs.get_pdfjs_basename()) - ) - except pdfjs.PDFJSNotFound: + if not pdfjs.is_available(): pytest.skip("No pdfjs found") ver = version._pdfjs_version() assert ver.split()[0] not in ['no', 'unknown'], ver |