WasatchPhotonics / ENLIGHTEN

Open-source spectroscopy application for controlling and taking measurements from Wasatch Photonics spectrometers.
https://wasatchphotonics.com/product-category/software/
MIT License
3 stars 6 forks source link

asset relative paths #294

Closed mzieg closed 9 months ago

mzieg commented 11 months ago

When running 4.0.17's run-burnin.bat from the Windows installer I found errors about missing ASTM JSON file. That's probably because it's loaded from a relative path enlighten/assets/example_data/... and run-burnin.bat is run from plugins/Prod. Consider doing an internal "change directory" as soon as ENLIGHTEN launches so it's running from the directory containing the .exe, or the directory "above" Enlighten.py if run from source.

mzieg commented 11 months ago

At runtime from the installer, argv[0] can contain anything from "enlighten" to "C:\Program Files\Wasatch Photonics\ENLIGHTEN\Enlighten\enlighten" (with or without .exe extension). When run from source, should always end in ".py".

samiebee43 commented 11 months ago

Should we chdir to the dirname of arg[0] on Enlighten's start?

Using os.chdir this will only affect the python program and its descendants, not the calling shell

sbee@Samies-MBP ~ % python3 foo.py  # contains a chdir
Traceback (most recent call last):
  File "/Users/sbee/foo.py", line 2, in <module>
    os.chdir("somewhere")
FileNotFoundError: [Errno 2] No such file or directory: 'somewhere'  # errors if folder !exists
sbee@Samies-MBP ~ % mkdir somewhere
sbee@Samies-MBP ~ % python3 foo.py # contains os.chdir("somewhere")
sbee@Samies-MBP ~ % # shell path is preserved
mzieg commented 9 months ago

fixed in 4.1.0