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

[noetic] wrap rostest call to add python pointing to sys.executable in PATH #1879

Merged
merged 5 commits into from
Feb 21, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion tools/rostest/scripts/rostest
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,39 @@

from rostest import rostestmain

rostestmain()
import os
import sys
import tempfile


class PythonPathOverride:
"""Replace python so test scripts with unmodified shebangs use correct python version."""

def _skip(self):
# skip this hack on windows
if 'nt' == os.name:
return True
try:
# Skip pre python 3.2
tempfile.TemporaryDirectory
except AttributeError:
return True
return False

def __enter__(self):
if self._skip():
return

self.dir = tempfile.TemporaryDirectory(prefix="rostest_bin_hook")
os.symlink(sys.executable, os.path.join(self.dir.name, "python"))
os.environ['PATH'] = self.dir.name + ":" + os.environ['PATH']

def __exit__(self, t, v, tb):
if self._skip():
return

self.dir.cleanup()


with PythonPathOverride():
rostestmain()