-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
66 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,34 @@ | ||
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- | ||
# vi: set ft=python sts=4 ts=4 sw=4 et: | ||
# | ||
# Copyright The NiPreps Developers <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We support and encourage derived works from this project, please read | ||
# about our expectations at | ||
# | ||
# https://www.nipreps.org/community/licensing/ | ||
# | ||
"""Version CLI helpers.""" | ||
|
||
from datetime import datetime | ||
from contextlib import suppress | ||
from datetime import datetime, timezone | ||
from pathlib import Path | ||
|
||
import requests | ||
|
||
from .. import __version__ | ||
from qsiprep import __version__ | ||
|
||
RELEASE_EXPIRY_DAYS = 14 | ||
DATE_FMT = '%Y%m%d' | ||
|
@@ -20,6 +41,7 @@ def check_latest(): | |
latest = None | ||
date = None | ||
outdated = None | ||
now = datetime.now(tz=timezone.utc) | ||
cachefile = Path.home() / '.cache' / 'qsiprep' / 'latest' | ||
try: | ||
cachefile.parent.mkdir(parents=True, exist_ok=True) | ||
|
@@ -29,23 +51,22 @@ def check_latest(): | |
if cachefile and cachefile.exists(): | ||
try: | ||
latest, date = cachefile.read_text().split('|') | ||
except Exception: | ||
except Exception: # noqa: S110, BLE001 | ||
pass | ||
else: | ||
try: | ||
latest = Version(latest) | ||
date = datetime.strptime(date, DATE_FMT) | ||
date = datetime.strptime(date, DATE_FMT).astimezone(timezone.utc) | ||
except (InvalidVersion, ValueError): | ||
latest = None | ||
else: | ||
if abs((datetime.now() - date).days) > RELEASE_EXPIRY_DAYS: | ||
if abs((now - date).days) > RELEASE_EXPIRY_DAYS: | ||
outdated = True | ||
|
||
if latest is None or outdated is True: | ||
try: | ||
response = None | ||
with suppress(Exception): | ||
response = requests.get(url='https://pypi.org/pypi/qsiprep/json', timeout=1.0) | ||
except Exception: | ||
response = None | ||
|
||
if response and response.status_code == 200: | ||
versions = [Version(rel) for rel in response.json()['releases'].keys()] | ||
|
@@ -56,26 +77,23 @@ def check_latest(): | |
latest = None | ||
|
||
if cachefile is not None and latest is not None: | ||
try: | ||
cachefile.write_text('|'.join(('%s' % latest, datetime.now().strftime(DATE_FMT)))) | ||
except Exception: | ||
pass | ||
with suppress(OSError): | ||
cachefile.write_text(f'{latest}|{now.strftime(DATE_FMT)}') | ||
|
||
return latest | ||
|
||
|
||
def is_flagged(): | ||
"""Check whether current version is flagged.""" | ||
# https://raw.githubusercontent.com/pennlinc/qsiprep/master/.versions.json | ||
flagged = tuple() | ||
try: | ||
flagged = () | ||
response = None | ||
with suppress(Exception): | ||
response = requests.get( | ||
url="""\ | ||
https://raw.githubusercontent.com/pennlinc/qsiprep/master/.versions.json""", | ||
timeout=1.0, | ||
) | ||
except Exception: | ||
response = None | ||
|
||
if response and response.status_code == 200: | ||
flagged = response.json().get('flagged', {}) or {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from .volume import init_anat_preproc_wf, init_synthseg_wf, init_synthstrip_wf | ||
|
||
__all__ = ['init_anat_preproc_wf', 'init_synthseg_wf', 'init_synthstrip_wf'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters