-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace use of strings with pathlib #895
Comments
Seems like we are, or are approaching the worst of both worlds with both strings and pathlib being used randomly. Its been in the standard library since 3.4 and might make something easier. I would be inclined to move everything to pathlib, and then call out the exceptions like freetype needing a string. All that said I haven't even glanced at the code to see how much work this might be. There is a fair amount of code referencing files, config and startup, loading/saving image data, channel configs and I am sure other places too. I will have a look at the code base and see how much work it looks like. We can talk about it at tomorrows development meeting (Note the 30 min late start!) |
A quick grep through the source produces about 300 lines with path in then of which maybe 10% are not about files from a quick glance. So converting from strings seems reasonable but not trivial. |
I've spent some time here and here's some notes:
Can you try the |
I pulled it onto my windows machine with picamera and red pitaya executor and it appears to work fine. Opened config files etc. The new display config files worked and it was able to run and save a simple Z stack experiment. Oncxe saved the "view last file" worked fine. However I ran into trouble in the save mosaic routine. The interface hung with a progress bar saying "Saving mosaic image data" and the stderr had the output "Exception in thread saveTiles" "--- Logging error ---". I will try to find out nmore about what is actually dying. |
The actual crash is in gui/mosaic/canvas.py at line 513
cant add a WindowsPath and a str object. |
The following code fixes the save issue.
However, the saved file can now not be loaded, presumable for similar pathlib issues. |
I also don't think we need the code...
|
Error on load is a dialog saying.... I was unable to load the MRC file at 'str' object has no attribute 'absolute' Please verify that the file path is correct and the file is valid. |
Ok this just needs a little edit in the loadtiles function. The following one line change just sets mrcpath to be a pathlib path. It also needs and import at the top of the canvas.py file "from pathlib import Path"
|
These two changes enable save and reloading of mosaics with the pathlib code. I also tested the channels load and save which works fine. |
Pushed these changes to my wip-895-pathlib branch on github. |
Currently we do not use pathlib in cockpit. However, some of our dependencies do. Recently I fixed an issue that was caused because
pkg_resources
now returnspathlib.Path
instances instead of strings which we ten passed tofreetype
which required a string.pathlib is now more established and support for it seems to be quite common all over python. We could consider migrating it to.
I do not have a strong opinion --- to be honest I'm not super clear on the advantages of using
pathlib
---but if we decide to migrate them we should adoptpathlib
everywhere. Having a mix of both seems like the worst case (and I fear that with time we'll be in that situation whether we like it nor not other libraries make that move). Opinions?The text was updated successfully, but these errors were encountered: