From 79e3bb975c1da600cb789b74a61e944ba95d5f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Wed, 28 Jun 2023 09:27:57 +0200 Subject: [PATCH] Drop support for Python 3.7 (end-of-life) --- .github/workflows/run-tests.yml | 2 +- CHANGES.md | 3 ++- openneuro/__init__.py | 6 +---- openneuro/_download.py | 5 +--- openneuro/config.py | 44 ++++++++++++++++----------------- pyproject.toml | 4 +-- 6 files changed, 28 insertions(+), 36 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0c7dbad..f522feb 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -27,7 +27,7 @@ jobs: python-version: ["3.11"] os: [ubuntu-latest, windows-latest, macos-latest] include: - - python-version: "3.7" + - python-version: "3.8" os: ubuntu-latest runs-on: ${{ matrix.os }} defaults: diff --git a/CHANGES.md b/CHANGES.md index c99527d..75b8090 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,8 +1,9 @@ # Changelog -## unreleased +## 2023.1.0 (unreleased) - Better handling of server response errors. +- Drop support for Python 3.7. `openneuro-py` now requires Python 3.8 or newer. ## 2022.2.0 diff --git a/openneuro/__init__.py b/openneuro/__init__.py index c6d8241..0e05d0b 100644 --- a/openneuro/__init__.py +++ b/openneuro/__init__.py @@ -1,8 +1,4 @@ -try: - from importlib import metadata -except ImportError: - # Running on pre-3.8 Python; use importlib-metadata package - import importlib_metadata as metadata +from importlib import metadata try: __version__ = metadata.version("openneuro-py") diff --git a/openneuro/_download.py b/openneuro/_download.py index a644861..4de8d02 100644 --- a/openneuro/_download.py +++ b/openneuro/_download.py @@ -8,10 +8,7 @@ import string import json from typing import Optional, Union -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal +from typing import Literal if sys.version_info >= (3, 9): from collections.abc import Iterable, Generator diff --git a/openneuro/config.py b/openneuro/config.py index 99a9c09..9bc9899 100644 --- a/openneuro/config.py +++ b/openneuro/config.py @@ -4,21 +4,18 @@ import stat import json import getpass -if sys.version_info >= (3, 8): - from typing import TypedDict -else: - from typing_extensions import TypedDict +from typing import TypedDict import appdirs from tqdm.auto import tqdm CONFIG_DIR = Path( - appdirs.user_config_dir(appname='openneuro-py', appauthor=False, roaming=True) + appdirs.user_config_dir(appname="openneuro-py", appauthor=False, roaming=True) ) CONFIG_DIR.mkdir(parents=True, exist_ok=True) -CONFIG_PATH = CONFIG_DIR / 'config.json' -BASE_URL = 'https://openneuro.org/' +CONFIG_PATH = CONFIG_DIR / "config.json" +BASE_URL = "https://openneuro.org/" class Config(TypedDict): @@ -27,18 +24,19 @@ class Config(TypedDict): def init_config() -> None: - """Initialize a new OpenNeuro configuration file. - """ - tqdm.write('🙏 Please login to your OpenNeuro account and go to: ' - 'My Account → Obtain an API Key') - api_key = getpass.getpass('OpenNeuro API key (input hidden): ') + """Initialize a new OpenNeuro configuration file.""" + tqdm.write( + "🙏 Please login to your OpenNeuro account and go to: " + "My Account → Obtain an API Key" + ) + api_key = getpass.getpass("OpenNeuro API key (input hidden): ") config: Config = { - 'endpoint': BASE_URL, - 'apikey': api_key, + "endpoint": BASE_URL, + "apikey": api_key, } - with open(CONFIG_PATH, 'w', encoding='utf-8') as f: + with open(CONFIG_PATH, "w", encoding="utf-8") as f: json.dump(config, f, indent=2) os.chmod(CONFIG_PATH, stat.S_IRUSR | stat.S_IWUSR) @@ -51,7 +49,7 @@ def load_config() -> dict: dict The configuration options. """ - with open(CONFIG_PATH, 'r', encoding='utf-8') as f: + with open(CONFIG_PATH, "r", encoding="utf-8") as f: config = json.load(f) return config @@ -70,12 +68,14 @@ def get_token() -> str: """ if not CONFIG_PATH.exists(): raise ValueError( - 'Could not read API token as no openneuro-py configuration ' + "Could not read API token as no openneuro-py configuration " 'file exists. Run "openneuro login" to generate it.' ) config = load_config() - if 'apikey' not in config: - raise ValueError('An openneuro-py configuration file was found, but did not ' - 'contain an "apikey" entry. Run "openneuro login" to ' - 'add such an entry.') - return config['apikey'] + if "apikey" not in config: + raise ValueError( + "An openneuro-py configuration file was found, but did not " + 'contain an "apikey" entry. Run "openneuro login" to ' + "add such an entry." + ) + return config["apikey"] diff --git a/pyproject.toml b/pyproject.toml index 84e8492..5d9e2ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "openneuro-py" description = "A Python client for OpenNeuro." readme = "README.md" -requires-python = ">=3.7" +requires-python = ">=3.8" license = {file = "LICENSE"} keywords = ["science", "neuroscience"] authors = [ @@ -19,8 +19,6 @@ dependencies = [ "click", "aiofiles", "sgqlc", - "importlib-metadata; python_version < '3.8'", - "typing-extensions; python_version < '3.8'", "appdirs", ] dynamic = ["version"]