Skip to content

[Python] Set the current cwd to the scene's path#617

Closed
fredroy wants to merge 1 commit into
sofa-framework:masterfrom
fredroy:set_cwd_pythonenv
Closed

[Python] Set the current cwd to the scene's path#617
fredroy wants to merge 1 commit into
sofa-framework:masterfrom
fredroy:set_cwd_pythonenv

Conversation

@fredroy

@fredroy fredroy commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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:

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.py it wont work
  • cd ${dir_of_your_scene} ; python3 blabla.py it will work

which is... problematic in my opinion.

Fix

So this PR sets the CWD from the directory of the script when doing import Sofa


NB1: 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: SetDirectory is such a bad name for the CWD changer in SOFA (plus it is doing other useful filesystem things and not really related to CWD)

@hugtalbot

Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants