chrisjbillington / desktop-app

OS menu shortcuts, correct taskbar behaviour, and environment activation for Python GUI apps
BSD 2-Clause "Simplified" License
6 stars 5 forks source link

Cast Path to str in subprocess.call #5

Closed rpanderson closed 4 years ago

rpanderson commented 4 years ago

Required for Python < 3.8, which otherwise fails in launcher.py.

(base) C:\Users\rpanderson\dev>oink
Traceback (most recent call last):
  File "C:\Users\rpanderson\AppData\Local\Continuum\anaconda3\Scripts\oink-script.py", line 11, in <module>
    load_entry_point('oink', 'console_scripts', 'oink')()
  File "c:\users\rpanderson\dev\desktop-app\desktop_app\launcher.py", line 81, in entry_point
    sys.exit(subprocess.call([python, script_path] + sys.argv[1:], **popen_kwargs))
  File "C:\Users\rpanderson\AppData\Local\Continuum\anaconda3\lib\subprocess.py", line 339, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\Users\rpanderson\AppData\Local\Continuum\anaconda3\lib\subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "C:\Users\rpanderson\AppData\Local\Continuum\anaconda3\lib\subprocess.py", line 1148, in _execute_child
    args = list2cmdline(args)
  File "C:\Users\rpanderson\AppData\Local\Continuum\anaconda3\lib\subprocess.py", line 555, in list2cmdline
    needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'WindowsPath' is not iterable

Testing confirms this, i.e. example app does not launch successfully when shortcut is invoked: example.

chrisjbillington commented 4 years ago

Good catch! Remove the left-in printlines and I'll merge.

I knew there'd be one or two things like that coming up. Although pathlib is great, there are still plenty of APIs that require strings. I've gone with the philosophy of storing Paths in the application, and only converting to string last-second when needed, kinda like always working with strings in-app and only encoding/decoding at boundaries. It's a bit rough but better than inconsistently having some paths as strings and some as Paths within the application.

rpanderson commented 4 years ago

Although pathlib is great, there are still plenty of APIs that require strings.

Yeah, there are plenty of examples of this, e.g. shutil.move (fixed in Python 3.9).

I've gone with the philosophy of storing Paths in the application, and only converting to string last-second when needed.

Ditto.