vinci1it2000/schedula

UNC problem on Windows & conda when launching DOT to render plots

Closed this issue · 8 comments

There seems to be problem on Windows with a UNC + CMD shell when co2mpas (also co2wui#146) try to launch the internal flask-server serving the plots:

(base) C:\Users\vagrant\Documents>co2mpas plot
 * Serving Flask app "C:\Users\vagrant\Documents\cache_plot" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
2019-10-12 09:34:12,666: INFO:werkzeug: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2019-10-12 09:34:13,338: INFO:co2mpas:Done! [17.17 sec]
2019-10-12 09:34:14,978: INFO:werkzeug:127.0.0.1 - - [12/Oct/2019 09:34:14] "GET / HTTP/1.1" 200 -
2019-10-12 09:34:16,510: INFO:werkzeug:127.0.0.1 - - [12/Oct/2019 09:34:16] "GET /favicon.ico HTTP/1.1" 404 -
2019-10-12 09:34:16,556: INFO:werkzeug:127.0.0.1 - - [12/Oct/2019 09:34:16] "GET /favicon.ico HTTP/1.1" 404 -
'\\?\C:\Users\vagrant\Documents\cache_plot\static'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
Error: dot: can't open tmpdx48cqh0
2019-10-12 09:34:29,556:ERROR:schedula.utils.drw:dot could not render C:\Users\vagrant\Documents\cache_plot\static\core.html due to:
 CalledProcessError(2, ['dot.bat', '-Tsvg', '-O', 'tmpdx48cqh0'])
2019-10-12 09:34:29,556: INFO:werkzeug:127.0.0.1 - - [12/Oct/2019 09:34:29] "GET /core.html HTTP/1.1" 404 -

UNC paths are supported on windows. To solve your issue you can set the module variable as follows:

import schedula.utils.drw as mdl
setattr(mdl, '_UNC', '')

What if longer than 260 chars is needed?

You have to solve the problem with the CMD.EXE.

So i guess the answer to my "what if" question is that "without UNC paths, schedula will fail for longer than 260-char paths", correct?
And that is why you suggest to fix the CMD problem. correct?

Now, that CMD.exe, i wouldn't be so assertive it is my problem...

Please re-open.

The issue is caused by a difference in the way Graphviz suite installs on Windows,

  • when downloading and installing it from the site, or
  • when using conda install graphviz.

TL;DR, in conda, the default executable extension is BAT, not exe, and BAT cannot handle UNC paths as CWD.

Normally there wouldn't be an issue, if schedula were not using UNC-paths.
(problem reported also in respective feedstock conda-forge/graphviz-feedstock#34)

Workaround

The dot.exe in conda's Graphvis in inside graphviz/ dir from where the bat is installed:

def is_conda():
    return os.path.exists(os.path.join(sys.prefix, 'conda-meta'))

if os.name == 'nt' and not os.path.splitext(prg)[1] and is_conda():
    monkeypatch_graphviz()

The monkeypatch_graphviz() must change the lines graphviz/backend.py#L124-L125 from this:

    if PLATFORM == 'windows':
        engine = '%s.bat' % engine

to this:

    if PLATFORM == 'windows':
        engine = 'graphviz\%s.exe' % engine

NOTE: you wont find the "from" lines in the original sources of the graphviz project, or in a non-conda Python - these lines are delivered by a conda-patch.

I'm sorry but your patch is invalid. You have used the wrong graphviz library (conda install -c conda-forge graphviz).

The graphviz requirement in schedula corresponds to conda install -c conda-forge python-graphviz=0.8.4.

You seem to be confusing:

  • python-graphviz (python) and
  • graphviz the native OS suite.

The former, depends on the later, you can't have one or the other, you need both in conda.

My patch is a temporary fix for schedula's UNC paths to play well there, n particular, with python-graphviz, until they fix this upstream (conda-forge/graphviz-feedstock#34, comment).

But the old version python-graphviz-8.4 indeed solves the problem 👍
(reported in graphviz-feedstock-34).

I'm not asking to add this version-boundary to scheulas setup.py since is only involves conda environments - not PyPi packages.