dsanson / termpdf.py

A graphical pdf and epub reader that works inside the kitty terminal
MIT License
496 stars 30 forks source link

Error when trying to launch termpdf.py in a new kitty window with --single-instance #26

Closed cobcobs closed 2 years ago

cobcobs commented 2 years ago

Hi! Thanks for all the work on termpdf.py!

I'm running into a problem while trying to integrate termpdf.py with ranger. In order to launch a pdf in a new kitty window from ranger, I'm using the following line in my rifle.conf:

ext pdf, flag f = kitty --single-instance termpdf.py "$@"

However, it always briefly opens a kitty instance then closes it, even when running the command directly from the command line. It gives this error:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/pybtex/io.py", line 83, in _open
    return _open_existing(opener, filename, mode, locate=kpsewhich, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/pybtex/io.py", line 54, in _open_existing
    found = locate(filename)
  File "/opt/homebrew/lib/python3.9/site-packages/pybtex/kpathsea.py", line 28, in kpsewhich
    p = Popen(['kpsewhich', filename], stdout=PIPE, stderr=PIPE)
  File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'kpsewhich'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/bin/termpdf.py", line 1859, in <module>
    main()
  File "/opt/homebrew/bin/termpdf.py", line 1830, in main
    doc.citekey = citekey_from_path(doc.filename)
  File "/opt/homebrew/bin/termpdf.py", line 1142, in citekey_from_path
    bib = bib_from_field('File',path)
  File "/opt/homebrew/bin/termpdf.py", line 1128, in bib_from_field
    bib = parse_file(config.BIBTEX,'bibtex')
  File "/opt/homebrew/lib/python3.9/site-packages/pybtex/database/__init__.py", line 928, in parse_file
    return parser.parse_file(file)
  File "/opt/homebrew/lib/python3.9/site-packages/pybtex/database/input/__init__.py", line 52, in parse_file
    with open_file(filename, encoding=self.encoding) as f:
  File "/opt/homebrew/lib/python3.9/site-packages/pybtex/io.py", line 95, in open_unicode
    return _open(io.open, filename, mode, encoding=encoding)
  File "/opt/homebrew/lib/python3.9/site-packages/pybtex/io.py", line 85, in _open
    raise PybtexError("unable to open %s. %s" % (filename, error.strerror))
pybtex.exceptions.PybtexError: unable to open $HOME/Documents/pubs/references.bib. No such file or directory

termpdf.py finds my .bib file without any problems when running kitty without the --single-instance option. The same thing occurs even when not specifying a bibtex file in the config. Instead, the last error looks like this:

pybtex.exceptions.PybtexError: unable to open . No such file or directory

While it works properly when not specifying --single-instance, I'm wondering if there's a way to fix this. Thanks!

dsanson commented 2 years ago

It looks like maybe it isn't expanding the $HOME variable properly. Does it work if you specify the bibliography as an absolute path?

cobcobs commented 2 years ago

I just tried it, and it seems like it works properly now. Thanks @dsanson!