From a82d69168c05e453c062320931899a0c1194afa8 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 13 Apr 2020 09:45:52 -0400 Subject: [PATCH 1/7] ENH: auto-update on import --- templateflow/__init__.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/templateflow/__init__.py b/templateflow/__init__.py index ce02f9dc..0cc9bb42 100644 --- a/templateflow/__init__.py +++ b/templateflow/__init__.py @@ -14,8 +14,21 @@ del get_distribution del DistributionNotFound +import os from . import api -from .conf import update +from .conf import update, setup_home + + +if os.getenv("TEMPLATEFLOW_AUTOUPDATE", "1") not in ( + "false", + "off", + "0", + "no", + "n", +): + # trigger skeleton autoupdate + update(local=True, overwrite=False) + __all__ = [ '__copyright__', From 9c38a5942012a7099ffb8eb71aa4ed59333e21a4 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 13 Apr 2020 09:46:17 -0400 Subject: [PATCH 2/7] MAINT: remove post-installation hook --- setup.py | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/setup.py b/setup.py index dd0fa7cf..aeb5d8c8 100644 --- a/setup.py +++ b/setup.py @@ -2,8 +2,6 @@ """Templateflow's setup script.""" import sys from setuptools import setup -from setuptools.command.install import install -from setuptools.command.develop import develop # Give setuptools a hint to complain if it's too old a version @@ -18,38 +16,9 @@ # This enables setuptools to install wheel on-the-fly SETUP_REQUIRES += ["wheel"] if "bdist_wheel" in sys.argv else [] - -def make_cmdclass(basecmd): - """Decorate setuptools commands.""" - base_run = basecmd.run - - def new_run(self): - from templateflow.conf import setup_home - - setup_home() - base_run(self) - - basecmd.run = new_run - return basecmd - - -@make_cmdclass -class CheckHomeDevCommand(develop): - """Setuptools command.""" - - -@make_cmdclass -class CheckHomeProdCommand(install): - """Setuptools command.""" - - if __name__ == "__main__": """ Install entry-point """ setup( name="templateflow", setup_requires=SETUP_REQUIRES, - cmdclass={ - "develop": CheckHomeDevCommand, - "install": CheckHomeProdCommand, - }, ) From 14bf7a9484cc2757ae4e457c82940e5a2d5e25ab Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 13 Apr 2020 11:27:32 -0400 Subject: [PATCH 3/7] FIX: grab version info only --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4da3ee4b..7c8a089c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,7 +66,7 @@ script: INTENDED_VERSION="$(python setup.py --version)" mkdir for_testing cd for_testing - INSTALLED_VERSION="$(python -c 'import templateflow; print(templateflow.__version__)')" + INSTALLED_VERSION="$(python -c 'import templateflow; print(templateflow.__version__)' | tail -1)" python -c 'import templateflow; print(templateflow.__file__)' echo "Intended: $INTENDED_VERSION" echo "Installed: $INSTALLED_VERSION" From 005081ce565d822ea420d357122dca2b2163017b Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 13 Apr 2020 11:27:46 -0400 Subject: [PATCH 4/7] STY: unused import --- templateflow/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templateflow/__init__.py b/templateflow/__init__.py index 0cc9bb42..180e3f3e 100644 --- a/templateflow/__init__.py +++ b/templateflow/__init__.py @@ -16,7 +16,7 @@ import os from . import api -from .conf import update, setup_home +from .conf import update if os.getenv("TEMPLATEFLOW_AUTOUPDATE", "1") not in ( From 5329ae8a7e77d0579dfc8c44b0835e5db0d0bed2 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 13 Apr 2020 13:17:34 -0400 Subject: [PATCH 5/7] FIX: update gh workflow --- .github/workflows/pythonpackage.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index fb26ecb0..5a272fde 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -55,7 +55,7 @@ jobs: source /tmp/install_sdist/bin/activate python -m pip install "setuptools ~= 42.0" "pip>=10.0.1" python -m pip install dist/templateflow*.tar.gz - INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")') + INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")' | tail -1) echo "VERSION: \"${THISVERSION}\"" echo "INSTALLED: \"${INSTALLED_VERSION}\"" test "${INSTALLED_VERSION}" = "${THISVERSION}" @@ -74,6 +74,7 @@ jobs: rm -rf ${TEMPLATEFLOW_HOME}/tpl-MNI152NLin2009cAsym source /tmp/install_sdist/bin/activate python -m pip install dist/templateflow*.tar.gz + python -c "import templateflow; templateflow.update(overwrite=False)" find ${TEMPLATEFLOW_HOME} >> /tmp/.sdist-install-2.txt diff /tmp/.sdist-install.txt /tmp/.sdist-install-2.txt exit $? @@ -86,7 +87,7 @@ jobs: source /tmp/install_wheel/bin/activate python -m pip install "setuptools ~= 42.0" "pip>=10.0.1" python -m pip install dist/templateflow*.whl - INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")') + INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")' | tail -1) echo "INSTALLED: \"${INSTALLED_VERSION}\"" test "${INSTALLED_VERSION}" = "${THISVERSION}" @@ -120,7 +121,7 @@ jobs: python -m pip install "setuptools ~= 42.0" wheel "setuptools_scm[toml] >= 3.4" \ setuptools_scm_git_archive "pip>=10.0.1" python setup.py install - INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")') + INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")' | tail -1) echo "INSTALLED: \"${INSTALLED_VERSION}\"" test "${INSTALLED_VERSION}" = "${THISVERSION}" @@ -138,6 +139,7 @@ jobs: rm -rf ${TEMPLATEFLOW_HOME}/tpl-MNI152NLin2009cAsym source /tmp/setup_install/bin/activate python setup.py install + python -c "import templateflow; templateflow.update(overwrite=False)" find ${TEMPLATEFLOW_HOME} >> /tmp/.setup-install-2.txt diff /tmp/.setup-install.txt /tmp/.setup-install-2.txt exit $? @@ -151,7 +153,7 @@ jobs: python -m pip install "setuptools ~= 42.0" wheel "setuptools_scm[toml] >= 3.4" \ setuptools_scm_git_archive "pip>=10.0.1" python setup.py develop - INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")') + INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")' | tail -1) echo "INSTALLED: \"${INSTALLED_VERSION}\"" test "${INSTALLED_VERSION}" = "${THISVERSION}" @@ -170,6 +172,7 @@ jobs: rm -rf ${TEMPLATEFLOW_HOME}/tpl-MNI152NLin2009cAsym source /tmp/setup_develop/bin/activate python setup.py develop + python -c "import templateflow; templateflow.update(overwrite=False)" find ${TEMPLATEFLOW_HOME} >> /tmp/.setup-develop-2.txt diff /tmp/.setup-develop.txt /tmp/.setup-develop-2.txt exit $? From 67e7ffcacdd2bc4e04373f2525ac37b557f64842 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Tue, 21 Apr 2020 16:12:10 -0400 Subject: [PATCH 6/7] ENH: add option to silence printing --- .github/workflows/pythonpackage.yml | 8 ++++---- .travis.yml | 2 +- templateflow/__init__.py | 3 +-- templateflow/conf/__init__.py | 4 ++-- templateflow/conf/_s3.py | 17 +++++++++-------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 5a272fde..187cd3d2 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -55,7 +55,7 @@ jobs: source /tmp/install_sdist/bin/activate python -m pip install "setuptools ~= 42.0" "pip>=10.0.1" python -m pip install dist/templateflow*.tar.gz - INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")' | tail -1) + INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")') echo "VERSION: \"${THISVERSION}\"" echo "INSTALLED: \"${INSTALLED_VERSION}\"" test "${INSTALLED_VERSION}" = "${THISVERSION}" @@ -87,7 +87,7 @@ jobs: source /tmp/install_wheel/bin/activate python -m pip install "setuptools ~= 42.0" "pip>=10.0.1" python -m pip install dist/templateflow*.whl - INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")' | tail -1) + INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")') echo "INSTALLED: \"${INSTALLED_VERSION}\"" test "${INSTALLED_VERSION}" = "${THISVERSION}" @@ -121,7 +121,7 @@ jobs: python -m pip install "setuptools ~= 42.0" wheel "setuptools_scm[toml] >= 3.4" \ setuptools_scm_git_archive "pip>=10.0.1" python setup.py install - INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")' | tail -1) + INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")') echo "INSTALLED: \"${INSTALLED_VERSION}\"" test "${INSTALLED_VERSION}" = "${THISVERSION}" @@ -153,7 +153,7 @@ jobs: python -m pip install "setuptools ~= 42.0" wheel "setuptools_scm[toml] >= 3.4" \ setuptools_scm_git_archive "pip>=10.0.1" python setup.py develop - INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")' | tail -1) + INSTALLED_VERSION=$(python -c 'import templateflow as tf; print(tf.__version__, end="")') echo "INSTALLED: \"${INSTALLED_VERSION}\"" test "${INSTALLED_VERSION}" = "${THISVERSION}" diff --git a/.travis.yml b/.travis.yml index 7c8a089c..4da3ee4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,7 +66,7 @@ script: INTENDED_VERSION="$(python setup.py --version)" mkdir for_testing cd for_testing - INSTALLED_VERSION="$(python -c 'import templateflow; print(templateflow.__version__)' | tail -1)" + INSTALLED_VERSION="$(python -c 'import templateflow; print(templateflow.__version__)')" python -c 'import templateflow; print(templateflow.__file__)' echo "Intended: $INTENDED_VERSION" echo "Installed: $INSTALLED_VERSION" diff --git a/templateflow/__init__.py b/templateflow/__init__.py index 180e3f3e..e7833418 100644 --- a/templateflow/__init__.py +++ b/templateflow/__init__.py @@ -27,8 +27,7 @@ "n", ): # trigger skeleton autoupdate - update(local=True, overwrite=False) - + update(local=True, overwrite=False, silent=True) __all__ = [ '__copyright__', diff --git a/templateflow/conf/__init__.py b/templateflow/conf/__init__.py index 74a13617..f0ca9126 100644 --- a/templateflow/conf/__init__.py +++ b/templateflow/conf/__init__.py @@ -42,14 +42,14 @@ _update_s3(TF_HOME, local=True, overwrite=True) -def update(local=False, overwrite=True): +def update(local=False, overwrite=True, silent=False): """Update an existing DataLad or S3 home.""" if TF_USE_DATALAD and _update_datalad(): return True from ._s3 import update as _update_s3 - return _update_s3(TF_HOME, local=local, overwrite=overwrite) + return _update_s3(TF_HOME, local=local, overwrite=overwrite, silent=silent) def setup_home(force=False): diff --git a/templateflow/conf/_s3.py b/templateflow/conf/_s3.py index 2a76fed0..876c4500 100644 --- a/templateflow/conf/_s3.py +++ b/templateflow/conf/_s3.py @@ -13,11 +13,11 @@ ).read_text() -def update(dest, local=True, overwrite=True): +def update(dest, local=True, overwrite=True, silent=False): """Update an S3-backed TEMPLATEFLOW_HOME repository.""" skel_file = Path((_get_skeleton_file() if not local else None) or TF_SKEL_PATH) - retval = _update_skeleton(skel_file, dest, overwrite=overwrite) + retval = _update_skeleton(skel_file, dest, overwrite=overwrite, silent=silent) if skel_file != TF_SKEL_PATH: skel_file.unlink() return retval @@ -45,7 +45,7 @@ def _get_skeleton_file(): return skel_file -def _update_skeleton(skel_file, dest, overwrite=True): +def _update_skeleton(skel_file, dest, overwrite=True, silent=False): from zipfile import ZipFile dest = Path(dest) @@ -62,11 +62,12 @@ def _update_skeleton(skel_file, dest, overwrite=True): ] newfiles = sorted(set(allfiles) - set(existing)) if newfiles: - print( - "Updating TEMPLATEFLOW_HOME using S3. " - "Adding: \n%s" % "\n".join(newfiles) - ) + if not silent: + print( + "Updating TEMPLATEFLOW_HOME using S3. Adding:\n%s" % '\n'.join(newfiles) + ) zipref.extractall(str(dest), members=newfiles) return True - print("TEMPLATEFLOW_HOME directory (S3 type) was up-to-date.") + if not silent: + print("TEMPLATEFLOW_HOME directory (S3 type) was up-to-date.") return False From ea7dd5c745980b4ddd491bd1656991e50648ed9b Mon Sep 17 00:00:00 2001 From: Mathias Goncalves Date: Wed, 29 Apr 2020 12:22:03 -0400 Subject: [PATCH 7/7] Apply suggestions from code review Co-Authored-By: Oscar Esteban --- templateflow/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templateflow/__init__.py b/templateflow/__init__.py index e7833418..a99c1cf6 100644 --- a/templateflow/__init__.py +++ b/templateflow/__init__.py @@ -16,10 +16,10 @@ import os from . import api -from .conf import update +from .conf import update, TF_USE_DATALAD -if os.getenv("TEMPLATEFLOW_AUTOUPDATE", "1") not in ( +if not TF_USE_DATALAD and os.getenv("TEMPLATEFLOW_AUTOUPDATE", "1") not in ( "false", "off", "0",