|
5 | 5 |
|
6 | 6 | from .engine import Submitter, Workflow, AuditFlag, ShellCommandTask, DockerTask, specs |
7 | 7 | from . import mark |
| 8 | + |
| 9 | + |
| 10 | +def check_latest_version(raise_exception=False): |
| 11 | + """Check for the latest version of the library |
| 12 | +
|
| 13 | + parameters: |
| 14 | + raise_exception: boolean |
| 15 | + Raise a RuntimeError if a bad version is being used |
| 16 | + """ |
| 17 | + import etelemetry |
| 18 | + import logging |
| 19 | + from pkg_resources import parse_version |
| 20 | + |
| 21 | + logger = logging.getLogger("pydra") |
| 22 | + |
| 23 | + INIT_MSG = "Running {packname} version {version} (latest: {latest})".format |
| 24 | + |
| 25 | + latest = {"version": "Unknown", "bad_versions": []} |
| 26 | + result = None |
| 27 | + try: |
| 28 | + result = etelemetry.get_project("nipype/pydra") |
| 29 | + except Exception as e: |
| 30 | + logger.warning("Could not check for version updates: \n%s", e) |
| 31 | + finally: |
| 32 | + if result: |
| 33 | + latest.update(**result) |
| 34 | + if parse_version(__version__) != parse_version(latest["version"]): |
| 35 | + logger.info( |
| 36 | + INIT_MSG( |
| 37 | + packname="pydra", version=__version__, latest=latest["version"] |
| 38 | + ) |
| 39 | + ) |
| 40 | + if latest["bad_versions"] and any( |
| 41 | + [ |
| 42 | + parse_version(__version__) == parse_version(ver) |
| 43 | + for ver in latest["bad_versions"] |
| 44 | + ] |
| 45 | + ): |
| 46 | + message = ( |
| 47 | + "You are using a version of Pydra with a critical " |
| 48 | + "bug. Please use a different version." |
| 49 | + ) |
| 50 | + if raise_exception: |
| 51 | + raise RuntimeError(message) |
| 52 | + else: |
| 53 | + logger.critical(message) |
| 54 | + return latest |
| 55 | + |
| 56 | + |
| 57 | +# Run telemetry on import for interactive sessions, such as IPython, Jupyter notebooks, Python REPL |
| 58 | +import __main__ |
| 59 | + |
| 60 | +if not hasattr(__main__, "__file__"): |
| 61 | + from .engine.core import TaskBase |
| 62 | + |
| 63 | + if TaskBase._etelemetry_version_data is None: |
| 64 | + TaskBase._etelemetry_version_data = check_latest_version() |
0 commit comments