Skip to content
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

Don't resolve Python executable path for subprocess calls #23

Open
schafdav opened this issue Sep 6, 2020 · 3 comments
Open

Don't resolve Python executable path for subprocess calls #23

schafdav opened this issue Sep 6, 2020 · 3 comments

Comments

@schafdav
Copy link

schafdav commented Sep 6, 2020

When resolving the path of the Python executable for a subprocess call, the sys.prefix can be different from the one that would be used when not resolving it. Python Virtual Environments work by relying on the module search paths being determined by the sys.prefix . Thus in the default case, in which the Python executable of the virtual environment is just a symbolic link to the system's executable, the resolving of the path will cause the wrong environment to be used (aka one in which anasymod might not even be installed).
Thus it would be nice if either Python executables could be special-cased for this, or the call to get_full_path (used also from within the which function inside files.py) can be omitted in respective use-cases.

@sgherbst
Copy link
Owner

sgherbst commented Sep 6, 2020

Thanks for raising this issue! May I ask which function is invoking the Python executable? The main one that comes to mind is when msdsl is used to generate models. In that case, the current workaround is to set the environment variable PYTHON_MSDSL to the full path of the Python executable that you want to use. (We could modify msdsl as you suggest in the future.)

Relevant code:

# run generator script
if 'PYTHON_MSDSL' in os.environ:
python_name = os.environ['PYTHON_MSDSL']
else:
python_name = which('python')
for generator_source in self.generator_sources:
# make model directory if necessary
mkdir_p(os.path.join(self._build_root, generator_source.fileset, generator_source.name))
for file in generator_source.files:
call([python_name, file, '-o', os.path.join(self._build_root, generator_source.fileset, generator_source.name), '--dt', str(self.dt)])

@schafdav
Copy link
Author

schafdav commented Sep 7, 2020

I encountered it when running anasymod -i mymodel --models, the code snippet you linked shows the origin of the call, which is indeed part of msdsl. Setting PYTHON_MSDSL works also fine.
Please feel free to close this issue and open one for msdsl instead.

@sgherbst
Copy link
Owner

sgherbst commented Sep 7, 2020

OK, thanks for letting me know. I'll move the issue to msdsl.

@sgherbst sgherbst transferred this issue from sgherbst/anasymod Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants