From e671d61246ebc9edad0f2938bb602951f7f295cb Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 20 Apr 2020 11:50:30 -0400 Subject: [PATCH 1/4] RF: use sys.executable not hardcoded "python" this would allow to consistently use the same python (which might be python3 with python corresponding to python v 2) --- doc/conf.py | 5 +++-- tools/toollib.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index cef6952782..9a4f050572 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -16,6 +16,7 @@ from pathlib import Path from tempfile import TemporaryDirectory import shutil +import sys from packaging.version import Version import nipype import subprocess as sp @@ -54,7 +55,7 @@ sp.run( [ - "python", + sys.executable, ex2rst, "--outdir", str(example_dir), @@ -70,7 +71,7 @@ ) sp.run( [ - "python", + sys.executable, ex2rst, "--outdir", str(example_dir), diff --git a/tools/toollib.py b/tools/toollib.py index 979f89c97f..77d864f142 100644 --- a/tools/toollib.py +++ b/tools/toollib.py @@ -31,7 +31,7 @@ def sh(cmd): def compile_tree(): """Compile all Python files below current directory.""" vstr = ".".join(map(str, sys.version_info[:2])) - stat = os.system("python %s/lib/python%s/compileall.py ." % (sys.prefix, vstr)) + stat = os.system("%s %s/lib/python%s/compileall.py ." % (sys.executable, sys.prefix, vstr)) if stat: msg = "*** ERROR: Some Python files in tree do NOT compile! ***\n" msg += "See messages above for the actual file that produced it.\n" From 02e32dc9ad96912bb3327120a532814b63d90d5e Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 20 Apr 2020 11:51:29 -0400 Subject: [PATCH 2/4] RF: DICOMConvert - use the same (basename of) python as of the host process May be basename is not desired? but it might not exist exactly the same on execution box, so decided to go with basename --- nipype/interfaces/freesurfer/preprocess.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nipype/interfaces/freesurfer/preprocess.py b/nipype/interfaces/freesurfer/preprocess.py index 39a444495c..92fbe7d7f7 100644 --- a/nipype/interfaces/freesurfer/preprocess.py +++ b/nipype/interfaces/freesurfer/preprocess.py @@ -7,6 +7,7 @@ import os.path as op from glob import glob import shutil +import sys import numpy as np from nibabel import load @@ -726,7 +727,7 @@ def cmdline(self): outdir = self._get_outdir() cmd = [] if not os.path.exists(outdir): - cmdstr = "python -c \"import os; os.makedirs('%s')\"" % outdir + cmdstr = "%s -c \"import os; os.makedirs('%s')\"" % (op.basename(sys.executable), outdir) cmd.extend([cmdstr]) infofile = os.path.join(outdir, "shortinfo.txt") if not os.path.exists(infofile): From f8447343d04274032ea99313c2723e900319f576 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 20 Apr 2020 11:53:13 -0400 Subject: [PATCH 3/4] RF: Makefile - use $(PYTHON) consistently to centralize choice of Python to use --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 48f2c112c2..b7107f31f0 100644 --- a/Makefile +++ b/Makefile @@ -11,18 +11,18 @@ zipdoc: html sdist: zipdoc @echo "Building source distribution..." - python setup.py sdist + $(PYTHON) setup.py sdist @echo "Done building source distribution." # XXX copy documentation.zip to dist directory. egg: zipdoc @echo "Building egg..." - python setup.py bdist_egg + $(PYTHON) setup.py bdist_egg @echo "Done building egg." upload_to_pypi: zipdoc @echo "Uploading to PyPi..." - python setup.py sdist --formats=zip,gztar upload + $(PYTHON) setup.py sdist --formats=zip,gztar upload trailing-spaces: find . -name "*[.py|.rst]" -type f | xargs perl -pi -e 's/[ \t]*$$//' @@ -70,7 +70,7 @@ html: specs: @echo "Checking specs and autogenerating spec tests" - env PYTHONPATH=".:$(PYTHONPATH)" python tools/checkspecs.py + env PYTHONPATH=".:$(PYTHONPATH)" $(PYTHON) tools/checkspecs.py check: check-before-commit # just a shortcut check-before-commit: specs trailing-spaces html test From c7efd5b79d3b7c3d88795cda4602615f7fc7ae96 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 20 Apr 2020 11:53:42 -0400 Subject: [PATCH 4/4] RF: py.test -> $(PYTHON) -m pytest To assure use of consistent with chosen python pytest. py-test might correspond to python2 whenever python3 is used. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b7107f31f0..03c1152053 100644 --- a/Makefile +++ b/Makefile @@ -56,10 +56,10 @@ inplace: $(PYTHON) setup.py build_ext -i test-code: in - py.test --doctest-modules nipype + $(PYTHON) -m pytest --doctest-modules nipype test-coverage: clean-tests in - py.test --doctest-modules --cov-config .coveragerc --cov=nipype nipype + $(PYTHON) -m pytest --doctest-modules --cov-config .coveragerc --cov=nipype nipype test: tests # just another name tests: clean test-code