supriya-project/supriya

Grapher issue?

Closed this issue · 9 comments

Ok, so Supriya appears to be running here on windows. However, when I tried the 'Quickstart' part of the documentation here: http://josiahwolfoberholtzer.com/supriya/#quickstart, I get this:

C:\Windows\System32>py
Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import supriya
>>> server = supriya.Server().boot()
>>> from supriya.ugens import EnvGen, Out, SinOsc
>>> from supriya.synthdefs import Envelope, synthdef
>>> @synthdef()
... def simple_sine(frequency=440, amplitude=0.1, gate=1):
...     sine = SinOsc.ar(frequency) * amplitude
...     envelope = EnvGen.kr(envelope=Envelope.adsr(), gate=gate, done_action=2)
...     Out.ar(0, [sine * envelope] * 2)
...
>>> supriya.graph(simple_sine)
'open' is not recognized as an internal or external command,
operable program or batch file.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\prg\Python39\lib\site-packages\supriya\io.py", line 114, in graph
    return Grapher(
  File "E:\prg\Python39\lib\site-packages\uqbar\graphs\graphers.py", line 56, in __call__
    self.open_output_path(output_path)
  File "E:\prg\Python39\lib\site-packages\uqbar\graphs\graphers.py", line 120, in open_output_path
    subprocess.run(f"{viewer} {output_path}", shell=True, check=True)
  File "E:\prg\Python39\lib\subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'open C:\Users\falkd\AppData\Local\supriya\supriya\Cache\2022-08-14T06-02-39-722229-b70cc34.pdf' returned non-zero exit status 1.
>>>

Looking in the C:\Users\falkd\AppData\Local\supriya\supriya\Cache\, I found that Graphviz had successfully generated the 2022-08-14T06-02-39-722229-b70cc34.pdf which I can open in Acrobat for example.

Generally, when using windows paths in python, I've found that using double backslash yields better handling of names with blankspaces, dots and numbers. Like this:

>>> open ('C:\Users\falkd\AppData\Local\supriya\supriya\Cache\2022-08-14T06-02-39-722229-b70cc34.pdf')
  File "<stdin>", line 1
    open ('C:\Users\falkd\AppData\Local\supriya\supriya\Cache\2022-08-14T06-02-39-722229-b70cc34.pdf')
                                                                                                     ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

>>> open ('C:\\Users\\falkd\\AppData\\Local\\supriya\\supriya\\Cache\\2022-08-14T06-02-39-722229-b70cc34.pdf')
<_io.TextIOWrapper name='C:\\Users\\falkd\\AppData\\Local\\supriya\\supriya\\Cache\\2022-08-14T06-02-39-722229-b70cc34.pdf' mode='r' encoding='cp1252'>
>>>
  • SuperCollider: 3.12.12
  • Supriya: 22.8b3

Ah, that's coming from a different library of which I'm also the author: https://github.com/josiah-wolf-oberholtzer/uqbar

That library isn't tested on Windows yet either. The real error is that I don't know how you open a file from the command-line in Windows. On OSX one uses open <filename>. On many Linux distros it's xdg-open <filename>. What's the equivalent on Windows? See: https://github.com/josiah-wolf-oberholtzer/uqbar/blob/main/uqbar/graphs/graphers.py#L116-L120

If you run start C:\Users\falkd\AppData\Local\supriya\supriya\Cache\2022-08-14T06-02-39-722229-b70cc34.pdf from your command-line (not Python!) does the PDF open for you in a useful way?

Meanwhile, try upgrading uqbar to 0.6.1. That might fix the grapher issue for you.

I'm really impressed with your update frequency,

Indeed, start is the windows equivalent of open <filename> and xdg-open <filename>. If I run start C:\Users\falkd\AppData\Local\supriya\supriya\Cache\2022-08-14T06-02-39-722229-b70cc34.pdf, Acrobat opens the correct graph as it should.

I did update uqbar to 0.6.2 (pip took the latest), but it still throws an error:

>>> supriya.graph(simple_sine)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\prg\Python39\lib\site-packages\supriya\io.py", line 114, in graph
    return Grapher(
  File "E:\prg\Python39\lib\site-packages\uqbar\graphs\graphers.py", line 55, in __call__
    self.open_output_path(output_path)
  File "E:\prg\Python39\lib\site-packages\uqbar\graphs\graphers.py", line 116, in open_output_path
    open_path(output_path)
  File "E:\prg\Python39\lib\site-packages\uqbar\io.py", line 290, in open_path
    subprocess.run([viewer, str(path)], check=True)
  File "E:\prg\Python39\lib\subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "E:\prg\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "E:\prg\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
>>>

Should I pip install 0.6.1 explicitly perhaps?

No, there's nothing significant between v0.6.1 and v0.6.2, just adjustments to the PyPI publishing workflow: supriya-project/uqbar@v0.6.1...v0.6.2

I'm going to have to dig up a Windows VM to try this stuff locally.

In the meantime, see if you can get any old file launched from Python:

import subprocess

subprocess.run(["start", "path\to\something\you\could\open.txt"])

^ subprocess.run can take a list of tokens to run as a shell command, or a single string. See: https://docs.python.org/3/library/subprocess.html#subprocess.run

Hmmm,

subprocess.run don't seem to work here for some reason:

>>> subprocess.run(["start", "C:\\Users\\falkd\\AppData\\Local\\supriya\\supriya\\Cache\\2022-08-14T06-02-39-722229-b70cc34.pdf"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\prg\Python39\lib\subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "E:\prg\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "E:\prg\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

But I found a solution here: https://stackoverflow.com/questions/434597/open-document-with-default-os-application-in-python-both-in-windows-and-mac-os

I think it's the third answer from top, seems to be the cleanest on windows:

>>> import os
>>> os.startfile('C:\\Users\\falkd\\AppData\\Local\\supriya\\supriya\\Cache\\2022-08-14T06-02-39-722229-b70cc34.pdf', 'open')

and the pdf opens correctly.

OK, I can work with that. Will let you know when the libraries are updated.

Uqbar v0.6.3 is live.

You'll probably run into similar problems in Supriya in some rare circumstances - I'll patch in the new uqbar.io.open_path() function as I run across them.

Happy daze! 😀

I'll let you know if/when I find anything else. For now, I'm really stoked on digging into the intricacies of Supriya...