-
Notifications
You must be signed in to change notification settings - Fork 55
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
Fix load_morpholgies to always resolve paths #1047
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if the path resolution should not be located in the Population
constructor? Because creating a new Population
instance will still have the same issue if the user does not use the load_morphologies
function.
Co-authored-by: Adrien Berchet <adrien.berchet@gmail.com>
Codecov Report
@@ Coverage Diff @@
## v4 #1047 +/- ##
======================================
Coverage ? 100.00%
======================================
Files ? 35
Lines ? 2475
Branches ? 0
======================================
Hits ? 2475
Misses ? 0
Partials ? 0 |
I am not so much in favor for the Population to do io stuff, as it is not its job. |
But it already does, isn't it? If the cache is disabled, only file paths are stored in the Population object. |
Well, yeah but my issue is that it can take either files or morphologies as the first argument. However, for the resolution to be correct, it cannot be lazy, because the directory can be changed at any time after init, before calling the iterators. So for this to work on the population, I would need to add a line that checks all files if they are morphologies or paths and then resolve them as needed, before letting cache and the rest do their own thing. I would be more willing to add an assertion in |
Yeah, I prefer the first solution (resolving before the cache and other stuffs) because it makes it more consistent. But I agree that it would be cleaner to have a constructor that only accept a list of morphologies so the paths can be processed elsewhere but this would induce breaking changes. So as you prefer :-) |
Unfortunately, I cannot make Population fully resolve the paths, because there are test cases that use symlinks to morphologies with different filename... Therefore paths are made absolute, but they are not resolved, which means that neither symlinks are resolved nor dot paths e.g. "..". Edit: I have ended up resolving the parent, but not the full path. This works with the symlinked files and resolves any relative path or symlinks in the parent path. |
I don't get what's the issue with symlinks to morphologies with different filename? Is it because the tests check the file names? |
According to the test: NeuroM/tests/io/test_io_utils.py Lines 220 to 226 in 7ef31d9
The name of the morphology should be the name of the file that is passed. If the symlink uses a different name and the path is resolved, that name will be lost to the name of the file it points to. |
Hmmm ok |
No idea. I find it strange, but maybe it was a use case in the past. |
Maybe. Anyway, I guess resolving the parent only is ok, though it might still result in very surprising behavior in some very specific cases. E.g. if there is a symlink in the given path and this symlink is changed during runtime (which is very unlikely ofc), the result will be different if the symlink is in the parents or if it is the actual target. |
* Mixed subtree processing (#981) * Refactor tests for test_mixed.py (#1027) * Remove deprecated modules and functions/classes & warnings (#1026, #1032) * Use readonly morphio Morphology by default (#979) * Morphology level radial distance features use the soma as reference point (#1030) * Expose subtree processing from the morph_stats api (#1034) * Remove pyXX prefix for lint, docs, and coverage (#1038) * Fix tutorials and add tutorial testenv (#1039) * Add isort for formatting/linting (#1040) * Add testing of example scripts (#1041) * Make documentation/docstrings testable (#1035) * Add black to neurom, format everything, and add to lint (#1042) * Fix load_morpholgies to always resolve paths (#1047) * allow Morphology objects to be either mut or immut (#1049) * Replace iter_* methods by properties in core objects and improve iter_segments (#1054) * Decouple Morphology constructor from io (#1120) * Move soma methods to functions (#1118)
Issue: If a relative morphology directory is passed into
neurom.load_morphologies
, a Population object is created with relative paths to the morphologies. If the directory is changed after the Population is created, the paths will not be valid anymore.Changes: Population makes paths absolute. Note that it does not resolve symlinks.
Fixes #1046