fossasia / visdom

A flexible tool for creating, organizing, and sharing visualizations of live, rich data. Supports Torch and Numpy.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create `env_path` if it does not exist or give instructions what to do.

da-h opened this issue · comments

Is your feature request related to a problem? Please describe.
In case one specifies a env-path that does not exist, for instance, visdom -env_path /tmp/doesnotexist, visdom exits with a FileNotFoundError-Exception.

> $ visdom -env_path /tmp/blub                                                                                                            [±master ●]
Checking for scripts.
It's Alive!
Traceback (most recent call last):
  File "/home/dah/.pyenv/versions/3.8.13/bin/visdom", line 33, in <module>
    sys.exit(load_entry_point('visdom', 'console_scripts', 'visdom')())
  File "/home/dah/Projects/visdom/py/visdom/server.py", line 2102, in download_scripts_and_run
    main()
  File "/home/dah/Projects/visdom/py/visdom/server.py", line 2093, in main
    start_server(port=FLAGS.port, hostname=FLAGS.hostname, base_url=base_url,
  File "/home/dah/Projects/visdom/py/visdom/server.py", line 1960, in start_server
    app = Application(port=port, base_url=base_url, env_path=env_path,
  File "/home/dah/Projects/visdom/py/visdom/server.py", line 206, in __init__
    self.state = self.load_state()
  File "/home/dah/Projects/visdom/py/visdom/server.py", line 299, in load_state
    env_jsons = [i for i in os.listdir(env_path) if '.json' in i]
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/blub'                                 

I suggest to let visdom try to create the specified folder first.
This problem occurs also when some users run the project in an environment, where the DEFAULT_ENV_PATH ($USER/.visdom) does not exist. (See #874)

Describe the solution you'd like
I see two easy solutions here:
First: try to create the folder first.
I think this is the better approach, as the default env-folder will not exist for first-time users, giving them possibly the impression that the code does not work.

Describe alternatives you've considered
The alternative is to give the user the explicit instruction to create the folder before using it, effectively catching Pythons FileNotFoundError Exception.

Automatically creating the folder is definitely the right call. I'm surprised we overlooked it the first time around here.