ralphbean / taskw

python taskwarrior api
http://threebean.org
GNU General Public License v3.0
176 stars 47 forks source link

Fix importing taskw without taskwarrior #130

Closed gdetrez closed 3 years ago

gdetrez commented 4 years ago

Importing taskw without having taskwarrior installed raises an exception (tested with CPython3.7):

❯❯❯ python -c 'import taskw.warrior'
Traceback (most recent call last):
  File "/src/taskw/warrior.py", line 554, in get_version
    stdout=subprocess.PIPE
  File "/usr/local/lib/python3.7/subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "/usr/local/lib/python3.7/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'task': 'task'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/src/taskw/__init__.py", line 1, in <module>
    from taskw.warrior import (
  File "/src/taskw/warrior.py", line 916, in <module>
    if TaskWarriorShellout.can_use():
  File "/src/taskw/warrior.py", line 543, in can_use
    return cls.get_version() > LooseVersion('2')
  File "/src/taskw/warrior.py", line 557, in get_version
    if 'No such file or directory' in e:
TypeError: argument of type 'FileNotFoundError' is not iterable

This fixes the issue by refactoring exception handling in taskw/warrior.py to use FileNotFoundError instead of matching on the string.

It is however a python 3.3+ solution and I just realized you advertise legacy python compatibility in setup.py. But since it's two weeks to 2020 maybe that's ok? :crossed_fingers:

gdetrez commented 4 years ago

Hi @ralphbean! I'd love to get some feedback on this if you have time. I can restore compatibility with legacy python if that's a concern.

jayvdb commented 3 years ago

This likely broke Python 2 support, as FileNotFoundError doesnt exist in Python 2.

Python 2 is declared as supported in setup.py

coddingtonbear commented 3 years ago

Oh, hrm; that wasn't intentional, but I am also not all that motivated to worry about maintaining Python 2.7 support in general given that it has been EOL'd for nearly a year now, and prevents us from doing things like adding type annotations.

Was there a reason we wanted to preserve Python 2.7 support?