diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index fb26ecb0..187cd3d2 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -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 $? @@ -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 $? @@ -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 $? 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, - }, ) diff --git a/templateflow/__init__.py b/templateflow/__init__.py index ce02f9dc..a99c1cf6 100644 --- a/templateflow/__init__.py +++ b/templateflow/__init__.py @@ -14,8 +14,20 @@ del get_distribution del DistributionNotFound +import os from . import api -from .conf import update +from .conf import update, TF_USE_DATALAD + + +if not TF_USE_DATALAD and os.getenv("TEMPLATEFLOW_AUTOUPDATE", "1") not in ( + "false", + "off", + "0", + "no", + "n", +): + # trigger skeleton autoupdate + 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