Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
Expand Down Expand Up @@ -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 $?
Expand Down Expand Up @@ -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 $?
31 changes: 0 additions & 31 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
)
14 changes: 13 additions & 1 deletion templateflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__',
Expand Down
4 changes: 2 additions & 2 deletions templateflow/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you checked this update thing with the datalad operation mode? - possibly for a further PR of refinements of that use-case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope - though just did and:

Updating TEMPLATEFLOW_HOME using DataLad ...
[ERROR  ] path not associated with any dataset [update(/Users/mathiasg/.cache/templateflow)] 
/Users/mathiasg/code/templateflow/templateflow/conf/__init__.py:74: UserWarning: Error updating TemplateFlow's home directory (using DataLad): Command did not complete successfully [{'action': 'update', 'path': '/Users/mathiasg/.cache/templateflow', 'type': 'directory', 'raw_input': True, 'orig_request': '/Users/mathiasg/.cache/templateflow', 'status': 'error', 'message': 'path not associated with any dataset'}]
  warn(f"Error updating TemplateFlow's home directory (using DataLad): {e}")

so I'll commit your changes to avoid the auto-update if the user prefers 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):
Expand Down
17 changes: 9 additions & 8 deletions templateflow/conf/_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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