// Remove leading and trailing white space from example names
validated_examples = [line.strip() for line in validated_examples]
// Remove blank lines
validated_examples = filter(None, validated_examples)
for example in validated_examples:
fullpath = pjoin(EG_SRC_DIR, example)
if not example.endswith(".py"):
print ("%s not a python file, skipping." % example)
continue
elif not os.path.isfile(fullpath):
print ("Cannot find file, %s, skipping." % example)
continue
shutil.copyfile(fullpath, example)
// Check that example file is included in the docs
file_root = example[:-3]
if file_root not in eg_index_contents:
msg = "Example, %s, not in index file %s."
msg = msg % (example, EG_INDEX_FNAME)
print(msg)
// Run the conversion from .py to rst file
check_call("python ../../tools/ex2rst --project dipy --outdir . .", shell=True)
// added the path so that scripts can import other scripts on the same directory
sys.path.insert(0, os.getcwd())
// Execute each python script in the directory.
if not os.path.isdir("fig"):
os.mkdir("fig")
use_xvfb = os.environ.get("TEST_WITH_XVFB", False)
if use_xvfb:
from xvfbwrapper import Xvfb
display = Xvfb(width=1920, height=1080)
display.start()
for script in validated_examples:
namespace = {}
figure_basename = os.path.join("fig", os.path.splitext(script)[0])
print(script)
execfile(script, namespace)
del namespace
After Change
// Remove leading and trailing white space from example names
validated_examples = [line.strip() for line in validated_examples]
// Remove blank lines
validated_examples = list(filter(None, validated_examples))
for example in validated_examples:
fullpath = pjoin(EG_SRC_DIR, example)
if not example.endswith(".py"):
print("%s not a python file, skipping." % example)
continue
elif not os.path.isfile(fullpath):
print("Cannot find file, %s, skipping." % example)
continue
shutil.copyfile(fullpath, example)
// Check that example file is included in the docs
file_root = example[:-3]
if file_root not in eg_index_contents:
msg = "Example, %s, not in index file %s."
msg = msg % (example, EG_INDEX_FNAME)
print(msg)
// Run the conversion from .py to rst file
check_call("python ../../tools/ex2rst --project dipy --outdir . .", shell=True)
// added the path so that scripts can import other scripts on the same directory
sys.path.insert(0, os.getcwd())
// Execute each python script in the directory.
if not os.path.isdir("fig"):
os.mkdir("fig")
use_xvfb = os.environ.get("TEST_WITH_XVFB", False)
if use_xvfb:
from xvfbwrapper import Xvfb
display = Xvfb(width=1920, height=1080)
display.start()
for script in validated_examples:
namespace = {}
figure_basename = os.path.join("fig", os.path.splitext(script)[0])
print(script)
exec(open(script).read(), namespace)
del namespace