Skip to content

Commit

Permalink
Bump Python minor version to 3.8 (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored Aug 12, 2022
1 parent 50f0d20 commit 2d2b411
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 139 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/webviz-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="https://github.com/equinor/webviz-config/actions?query=branch%3Amaster"><img src="https://github.com/equinor/webviz-config/workflows/webviz-config/badge.svg"></a>
<a href="https://lgtm.com/projects/g/equinor/webviz-config/alerts/"><img alt="Total alerts" src="https://img.shields.io/lgtm/alerts/g/equinor/webviz-config.svg?logo=lgtm&logoWidth=18"/></a>
<a href="https://lgtm.com/projects/g/equinor/webviz-config/context:python"><img alt="Language grade: Python" src="https://img.shields.io/lgtm/grade/python/g/equinor/webviz-config.svg?logo=lgtm&logoWidth=18"/></a>
<a href="https://www.python.org/"><img src="https://img.shields.io/badge/python-3.6%20|%203.7%20|%203.8%20|%203.9%20|%203.10-blue.svg"></a>
<a href="https://www.python.org/"><img src="https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10-blue.svg"></a>
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>
<br/>
Expand Down
8 changes: 2 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
],
Expand All @@ -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={
Expand Down
12 changes: 3 additions & 9 deletions tests/test_plugin_init.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 = {}
Expand All @@ -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 = {}
Expand Down
7 changes: 1 addition & 6 deletions webviz_config/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 12 additions & 16 deletions webviz_config/_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
4 changes: 2 additions & 2 deletions webviz_config/_deployment/azure_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
22 changes: 6 additions & 16 deletions webviz_config/_deployment/github_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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,
)
Expand Down Expand Up @@ -128,9 +122,7 @@ def read_file_in_repository(github_slug: str, filename: str) -> str:
["git", "clone", f"[email protected]:{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]

Expand All @@ -150,8 +142,7 @@ def commit_portable_webviz(
["git", "clone", f"[email protected]:{github_slug}"],
check=True,
cwd=temp_dir,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
capture_output=True,
)

clone_path = temp_dir / github_slug.split("/")[1]
Expand All @@ -174,6 +165,5 @@ def commit_portable_webviz(
command,
check=True,
cwd=clone_path,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
capture_output=True,
)
4 changes: 0 additions & 4 deletions webviz_config/_deployment/radix.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import json
import time
import secrets
Expand Down Expand Up @@ -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.")

Expand Down
16 changes: 4 additions & 12 deletions webviz_config/_deployment/radix_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -98,9 +94,7 @@ def create_application(
"--context",
context,
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
# capture_output=True,
capture_output=True,
check=True,
)

Expand Down Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions webviz_config/_docs/_build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions webviz_config/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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.",
Expand Down
31 changes: 8 additions & 23 deletions webviz_config/generic_plugins/_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <tag> to <tag/>.
Expand Down
7 changes: 1 addition & 6 deletions webviz_config/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 2d2b411

Please sign in to comment.