[Python] Set the current cwd to the scene's path#617
Closed
fredroy wants to merge 1 commit into
Closed
Conversation
Contributor
|
we should avoid changing the current working directory. The path of the scene file should be added to the list of path. This PR is too breaking and we should merge the PR in SOFA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Status
1️⃣ lots of calls to load resources (like MeshOBJLoader, image, etc) using FileRepository::findFiles() need the Current Working Directory (CWD) to be set to the scene's (see sofa-framework/sofa#6135 )
2️⃣ with runSofa, this is set:
in XML: through SceneLoaderXML :
https://github.com/sofa-framework/sofa/blob/bc64d21b6961e2f80af0f0b43d8f46cd1249f618/Sofa/framework/Simulation/Common/src/sofa/simulation/common/SceneLoaderXML.cpp#L114
in Python3: with SceneLoaderPY3:
SofaPython3/Plugin/src/SofaPython3/SceneLoaderPY3.cpp
Line 112 in e6fb484
Problem
When running directly with python (the process), the CWD is never changed and is set from where you launch it.
So it means that if you do, with a scene using relative paths:
cd ${HOME} ; python3 <dir_of_your_scene>/blabla.pyit wont workcd ${dir_of_your_scene} ; python3 blabla.pyit will workwhich is... problematic in my opinion.
Fix
So this PR sets the CWD from the directory of the script when doing
import SofaNB1: I dont really like that things in the scene depends of the CWD anyway (but I wont obviously not change anything in the Sofa code base 🥴)
NB2:
SetDirectoryis such a bad name for the CWD changer in SOFA (plus it is doing other useful filesystem things and not really related to CWD)