From 2d2b41153d000efef1cf86c281f59fcfac799bce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anders=20Fredrik=20Ki=C3=A6r?=
<31612826+anders-kiaer@users.noreply.github.com>
Date: Fri, 12 Aug 2022 12:37:05 +0200
Subject: [PATCH] Bump Python minor version to `3.8` (#610)
---
.github/workflows/webviz-config.yml | 6 ++--
README.md | 2 +-
setup.py | 8 ++---
tests/test_plugin_init.py | 12 ++-----
webviz_config/__init__.py | 7 +----
webviz_config/_config_parser.py | 28 +++++++----------
webviz_config/_deployment/azure_cli.py | 4 +--
webviz_config/_deployment/github_cli.py | 22 ++++---------
webviz_config/_deployment/radix.py | 4 ---
webviz_config/_deployment/radix_cli.py | 16 +++-------
webviz_config/_docs/_build_docs.py | 10 +-----
webviz_config/command_line.py | 7 ++---
webviz_config/generic_plugins/_markdown.py | 31 +++++--------------
webviz_config/plugins/__init__.py | 7 +----
webviz_config/plugins/_utils.py | 13 ++------
.../templates/copy_data_template.py.jinja2 | 5 ---
webviz_config/themes/__init__.py | 7 +----
17 files changed, 50 insertions(+), 139 deletions(-)
diff --git a/.github/workflows/webviz-config.yml b/.github/workflows/webviz-config.yml
index 4b6e7955..394f9431 100644
--- a/.github/workflows/webviz-config.yml
+++ b/.github/workflows/webviz-config.yml
@@ -21,7 +21,7 @@ jobs:
PYTHONWARNINGS: default # We want to see e.g. DeprecationWarnings
strategy:
matrix:
- python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
+ python-version: ["3.8", "3.9", "3.10"]
steps:
- name: 📖 Checkout commit locally
@@ -49,7 +49,7 @@ jobs:
pip install --pre --upgrade webviz-core-components # Testing against our latest release (including pre-releases)
- name: 📦 Install extra deployment dependencies
- if: matrix.python-version != '3.6' # Check tests pass also without optional dependencies
+ if: matrix.python-version != '3.10' # Check tests pass also without optional dependencies
run: |
pip install .[deployment]
@@ -96,7 +96,7 @@ jobs:
twine upload dist/*
- name: 📚 Update GitHub pages
- if: github.event_name == 'release' && matrix.python-version == '3.6'
+ if: github.event_name == 'release' && matrix.python-version == '3.8'
run: |
cp -R ./docs_build ../docs_build
diff --git a/README.md b/README.md
index 26ee0ff3..1ff7cd88 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@
-
+
diff --git a/setup.py b/setup.py
index 05bb7b61..6f36dadc 100644
--- a/setup.py
+++ b/setup.py
@@ -79,16 +79,13 @@ def get_long_description() -> str:
],
},
install_requires=[
- "bleach>=3.1; python_version<'3.7'",
- "bleach[css]>=5; python_version>='3.7'",
+ "bleach[css]>=5",
"cryptography>=2.4",
"dash>=2.0",
"dash-pivottable>=0.0.2",
- "dataclasses>=0.8; python_version<'3.7'",
"flask>=2.0",
"flask-caching>=1.4,<1.11", # https://github.com/equinor/webviz-config/issues/595
"flask-talisman>=0.6",
- "importlib-metadata>=1.7; python_version<'3.8'",
"jinja2>=2.10",
"markdown>=3.0",
"msal>=1.5.0",
@@ -98,7 +95,6 @@ def get_long_description() -> str:
"pyyaml>=5.1",
"requests>=2.20",
"tqdm>=4.8",
- "typing-extensions>=3.7; python_version<'3.8'",
"webviz-core-components>=0.5.4",
"werkzeug>=2.0",
],
@@ -114,7 +110,7 @@ def get_long_description() -> str:
],
},
setup_requires=["setuptools_scm~=3.2"],
- python_requires="~=3.6",
+ python_requires="~=3.8",
use_scm_version=True,
zip_safe=False,
project_urls={
diff --git a/tests/test_plugin_init.py b/tests/test_plugin_init.py
index 95347808..3098e84e 100644
--- a/tests/test_plugin_init.py
+++ b/tests/test_plugin_init.py
@@ -1,13 +1,7 @@
import warnings
from unittest import mock
import importlib
-
-try:
- # Python 3.8+
- import importlib.metadata as importlib_metadata
-except ImportError:
- # Python < 3.8
- import importlib_metadata
+import importlib.metadata
import webviz_config.plugins._utils
@@ -36,7 +30,7 @@ def __init__(self, entry_points, name):
def test_no_warning(monkeypatch):
# pylint: disable=protected-access
- monkeypatch.setattr(importlib_metadata, "requires", lambda x: [])
+ monkeypatch.setattr(importlib.metadata, "requires", lambda x: [])
importlib.reload(webviz_config.plugins._utils)
globals_mock = {}
@@ -53,7 +47,7 @@ def test_no_warning(monkeypatch):
def test_warning_multiple(monkeypatch):
# pylint: disable=protected-access
- monkeypatch.setattr(importlib_metadata, "requires", lambda x: [])
+ monkeypatch.setattr(importlib.metadata, "requires", lambda x: [])
importlib.reload(webviz_config.plugins._utils)
globals_mock = {}
diff --git a/webviz_config/__init__.py b/webviz_config/__init__.py
index 1a3b3113..1a19c8a1 100644
--- a/webviz_config/__init__.py
+++ b/webviz_config/__init__.py
@@ -1,9 +1,4 @@
-try:
- # Python 3.8+
- from importlib.metadata import version, PackageNotFoundError
-except ModuleNotFoundError:
- # Python < 3.8
- from importlib_metadata import version, PackageNotFoundError # type: ignore
+from importlib.metadata import version, PackageNotFoundError
from ._theme_class import WebvizConfigTheme
from ._webviz_settings_class import WebvizSettings
diff --git a/webviz_config/_config_parser.py b/webviz_config/_config_parser.py
index 94bd0841..1e74c0ec 100644
--- a/webviz_config/_config_parser.py
+++ b/webviz_config/_config_parser.py
@@ -103,22 +103,18 @@ def _call_signature(
(config_folder / pathlib.Path(patharg)).resolve()
for patharg in kwargs[arg]
]
- try:
- if not isinstance(kwargs[arg], expected_type):
- raise ParserError(
- f"{terminal_colors.RED}{terminal_colors.BOLD}"
- f"The value provided for argument `{arg}` "
- f"given to `{plugin_name}` is "
- f"of type `{type(kwargs[arg]).__name__}`. "
- f"Expected type "
- f"`{argspec.annotations[arg].__name__}`. "
- "Run the command `webviz docs` if you want "
- "to see documentation of the plugin."
- f"{terminal_colors.END}"
- )
- # Typechecking typing classes does not work in python 3.7
- except TypeError:
- pass
+ if not isinstance(kwargs[arg], expected_type):
+ raise ParserError(
+ f"{terminal_colors.RED}{terminal_colors.BOLD}"
+ f"The value provided for argument `{arg}` "
+ f"given to `{plugin_name}` is "
+ f"of type `{type(kwargs[arg]).__name__}`. "
+ f"Expected type "
+ f"`{argspec.annotations[arg].__name__}`. "
+ "Run the command `webviz docs` if you want "
+ "to see documentation of the plugin."
+ f"{terminal_colors.END}"
+ )
kwargs_including_defaults = kwargs
plugin_deprecation_warnings = []
diff --git a/webviz_config/_deployment/azure_cli.py b/webviz_config/_deployment/azure_cli.py
index df8c7c89..d89c3b71 100644
--- a/webviz_config/_deployment/azure_cli.py
+++ b/webviz_config/_deployment/azure_cli.py
@@ -30,8 +30,8 @@
)
-@functools.lru_cache() # paranthesis required on python < 3.8
-def _credential() -> "InteractiveBrowserCredential": # Python 3.7+ can have forward reference
+@functools.lru_cache
+def _credential(): # type: ignore[no-untyped-def]
if not AZURE_CLI_INSTALLED:
raise RuntimeError(
"In order to use webviz deploy features, you need to first install "
diff --git a/webviz_config/_deployment/github_cli.py b/webviz_config/_deployment/github_cli.py
index 778302a4..b8142ce9 100644
--- a/webviz_config/_deployment/github_cli.py
+++ b/webviz_config/_deployment/github_cli.py
@@ -16,9 +16,7 @@ def logged_in() -> bool:
# pylint: disable=subprocess-run-check
result = subprocess.run(
["gh", "auth", "status"],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- # capture_output=True, <-- Added in Python 3.7
+ capture_output=True,
)
return b"Logged in to github.com" in result.stderr
@@ -34,9 +32,7 @@ def repo_exists(github_slug: str) -> bool:
# pylint: disable=subprocess-run-check
result = subprocess.run(
["gh", "repo", "view", github_slug],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- # capture_output=True <-- Added in Python 3.7
+ capture_output=True,
)
if not result.stderr:
@@ -55,9 +51,7 @@ def create_github_repository(github_slug: str, directory: Path) -> Path:
subprocess.run(
["gh", "repo", "create", github_slug, "--private", "--confirm"],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- # capture_output=True, <-- Added in Python 3.7
+ capture_output=True,
check=True,
cwd=directory,
)
@@ -128,9 +122,7 @@ def read_file_in_repository(github_slug: str, filename: str) -> str:
["git", "clone", f"git@github.com:{github_slug}"],
check=True,
cwd=temp_dir,
- stdout=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
- # capture_output=True, <-- Added in Python 3.7
+ capture_output=True,
)
clone_path = temp_dir / github_slug.split("/")[1]
@@ -150,8 +142,7 @@ def commit_portable_webviz(
["git", "clone", f"git@github.com:{github_slug}"],
check=True,
cwd=temp_dir,
- stdout=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
+ capture_output=True,
)
clone_path = temp_dir / github_slug.split("/")[1]
@@ -174,6 +165,5 @@ def commit_portable_webviz(
command,
check=True,
cwd=clone_path,
- stdout=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL,
+ capture_output=True,
)
diff --git a/webviz_config/_deployment/radix.py b/webviz_config/_deployment/radix.py
index 4903eb28..65cb4e71 100644
--- a/webviz_config/_deployment/radix.py
+++ b/webviz_config/_deployment/radix.py
@@ -1,4 +1,3 @@
-import sys
import json
import time
import secrets
@@ -272,9 +271,6 @@ def radix_redeploy(github_slug: str, build_directory: pathlib.Path) -> None:
def main_radix_deployment(args: argparse.Namespace) -> None:
- if sys.version_info < (3, 8):
- raise RuntimeError("Radix deployment workflow requires at least Python 3.8")
-
if not args.portable_app.is_dir():
raise ValueError(f"{args.portable_app} is not a directory.")
diff --git a/webviz_config/_deployment/radix_cli.py b/webviz_config/_deployment/radix_cli.py
index 47049e1d..a2526760 100644
--- a/webviz_config/_deployment/radix_cli.py
+++ b/webviz_config/_deployment/radix_cli.py
@@ -27,9 +27,7 @@ def _trigger_token_aquisition(update_only: bool = False) -> None:
"dummy_context",
],
timeout=15 if update_only else None,
- stdout=subprocess.PIPE if update_only else None,
- stderr=subprocess.PIPE if update_only else None,
- # capture_output=update_only <-- Added in Python 3.7
+ capture_output=update_only,
)
@@ -62,9 +60,7 @@ def application_exists(application_name: str, context: str) -> bool:
"--context",
context,
],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- # capture_output=True, <-- Added in Python 3.7
+ capture_output=True,
check=True,
)
return not result.stderr
@@ -98,9 +94,7 @@ def create_application(
"--context",
context,
],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- # capture_output=True,
+ capture_output=True,
check=True,
)
@@ -167,9 +161,7 @@ def set_radix_secret(
"--context",
context,
],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- # capture_output=True, <-- First vailable in Python 3.7
+ capture_output=True,
check=True,
)
return
diff --git a/webviz_config/_docs/_build_docs.py b/webviz_config/_docs/_build_docs.py
index 10f491c6..6313ebdf 100644
--- a/webviz_config/_docs/_build_docs.py
+++ b/webviz_config/_docs/_build_docs.py
@@ -16,15 +16,7 @@
import pathlib
from importlib import import_module
from collections import defaultdict
-from typing import Any, Dict, Optional, Tuple, List
-
-
-try:
- # Python 3.8+
- from typing import TypedDict
-except (ImportError, ModuleNotFoundError):
- # Python < 3.8
- from typing_extensions import TypedDict
+from typing import Any, Dict, Optional, Tuple, List, TypedDict
import jinja2
diff --git a/webviz_config/command_line.py b/webviz_config/command_line.py
index 80bb01ed..ccada925 100644
--- a/webviz_config/command_line.py
+++ b/webviz_config/command_line.py
@@ -22,13 +22,12 @@ def main() -> None: # pylint: disable=too-many-statements
subparsers = parser.add_subparsers(
metavar="SUBCOMMAND",
+ required=True,
help="Below are the available subcommands listed. "
"Type e.g. 'webviz build --help' "
"to get help on one particular "
"subcommand.",
)
- # When dropping Python 3.6 support, 'required' can be given as an argument to add_subparsers.
- subparsers.required = True
# Add "build" argument parser:
@@ -111,15 +110,13 @@ def main() -> None: # pylint: disable=too-many-statements
deployment_subparsers = parser_deploy.add_subparsers(
metavar="DEPLOYMENT_METHOD",
+ required=True,
help="Below are the available deployment subcommands listed. "
"Type e.g. 'webviz deploy radix --help' "
"to get help on one particular "
"subcommand.",
)
- # When dropping Python 3.6 support, 'required' can be given as an argument to add_subparsers.
- deployment_subparsers.required = True
-
parser_radix_deploy = deployment_subparsers.add_parser(
"radix",
help="Deploy the app using Radix.",
diff --git a/webviz_config/generic_plugins/_markdown.py b/webviz_config/generic_plugins/_markdown.py
index 66956841..92e28f9e 100644
--- a/webviz_config/generic_plugins/_markdown.py
+++ b/webviz_config/generic_plugins/_markdown.py
@@ -4,6 +4,7 @@
from xml.etree import ElementTree # nosec
import bleach
+from bleach.css_sanitizer import CSSSanitizer
import markdown
from markdown.extensions import Extension
from markdown.inlinepatterns import ImageInlineProcessor, IMAGE_LINK_RE
@@ -176,30 +177,14 @@ def __init__(self, markdown_file: Path):
],
)
- try:
- self.html = (
- bleach.clean( # type: ignore # pylint: disable=unexpected-keyword-arg
- html_from_markdown,
- tags=Markdown.ALLOWED_TAGS,
- attributes=Markdown.ALLOWED_ATTRIBUTES,
- styles=Markdown.ALLOWED_STYLES,
- )
- )
- except TypeError:
- # styles not present in bleach >= 5. We can remove
- # this try/except when dropping Python 3.6 support.
- from bleach.css_sanitizer import ( # pylint: disable=import-outside-toplevel
- CSSSanitizer,
- )
-
- css_sanitizer = CSSSanitizer(allowed_css_properties=Markdown.ALLOWED_STYLES)
+ css_sanitizer = CSSSanitizer(allowed_css_properties=Markdown.ALLOWED_STYLES)
- self.html = bleach.clean(
- html_from_markdown,
- tags=Markdown.ALLOWED_TAGS,
- attributes=Markdown.ALLOWED_ATTRIBUTES,
- css_sanitizer=css_sanitizer,
- )
+ self.html = bleach.clean(
+ html_from_markdown,
+ tags=Markdown.ALLOWED_TAGS,
+ attributes=Markdown.ALLOWED_ATTRIBUTES,
+ css_sanitizer=css_sanitizer,
+ )
# Workaround for upstream issue https://github.com/plotly/dash-core-components/issues/746,
# where we convert void html tags from to .
diff --git a/webviz_config/plugins/__init__.py b/webviz_config/plugins/__init__.py
index 4a372c3d..89333bc5 100644
--- a/webviz_config/plugins/__init__.py
+++ b/webviz_config/plugins/__init__.py
@@ -2,12 +2,7 @@
the utility itself.
"""
-try:
- # Python 3.8+
- from importlib.metadata import distributions
-except ModuleNotFoundError:
- # Python < 3.8
- from importlib_metadata import distributions # type: ignore
+from importlib.metadata import distributions
from ._utils import load_webviz_plugins_with_metadata, PluginProjectMetaData
diff --git a/webviz_config/plugins/_utils.py b/webviz_config/plugins/_utils.py
index 6386455c..53971fbb 100644
--- a/webviz_config/plugins/_utils.py
+++ b/webviz_config/plugins/_utils.py
@@ -1,15 +1,8 @@
import re
import warnings
-from typing import Any, Dict, Iterable, Optional, Tuple
-
-try:
- # Python 3.8+
- from typing import TypedDict
- from importlib.metadata import requires, version, PackageNotFoundError
-except ImportError:
- # Python < 3.8
- from typing_extensions import TypedDict
- from importlib_metadata import requires, version, PackageNotFoundError # type: ignore
+from typing import Any, Dict, Iterable, Optional, Tuple, TypedDict
+
+from importlib.metadata import requires, version, PackageNotFoundError
class PluginProjectMetaData(TypedDict):
diff --git a/webviz_config/templates/copy_data_template.py.jinja2 b/webviz_config/templates/copy_data_template.py.jinja2
index 2b2fd2e1..8cdda948 100644
--- a/webviz_config/templates/copy_data_template.py.jinja2
+++ b/webviz_config/templates/copy_data_template.py.jinja2
@@ -64,11 +64,6 @@ WEBVIZ_INSTANCE_INFO.initialize(
WEBVIZ_FACTORY_REGISTRY.initialize({{ internal_factory_settings if internal_factory_settings is defined else None }})
-
-# The lines below can be simplified when assignment
-# expressions become available in Python 3.8
-# (https://www.python.org/dev/peps/pep-0572)
-
plugins = []
{% for page in pageContents %}
diff --git a/webviz_config/themes/__init__.py b/webviz_config/themes/__init__.py
index ba6280da..b0bfb492 100644
--- a/webviz_config/themes/__init__.py
+++ b/webviz_config/themes/__init__.py
@@ -1,9 +1,4 @@
-try:
- # Python 3.8+
- from importlib.metadata import entry_points
-except ModuleNotFoundError:
- # Python < 3.8
- from importlib_metadata import entry_points # type: ignore
+from importlib.metadata import entry_points
from .. import WebvizConfigTheme
from ._default_theme import default_theme