diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 62cfaacba..f61b5143d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,7 @@ jobs: name: ๐Ÿงช Unit tests strategy: matrix: - python: ["3.7", "3.8"] + python: ["3.7", "3.8", "3.9"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -70,7 +70,7 @@ jobs: needs: build strategy: matrix: - python: ["3.7", "3.8"] + python: ["3.7", "3.8", "3.9"] installable: ["wheel", "sdist"] runs-on: ubuntu-latest steps: diff --git a/.github/workflows/test_install.yml b/.github/workflows/test_install.yml index b1a0bc8ec..aae343c08 100644 --- a/.github/workflows/test_install.yml +++ b/.github/workflows/test_install.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: os: ["ubuntu-latest"] - python: ["3.7", "3.8"] + python: ["3.7", "3.8", "3.9"] branch: ["master"] runs-on: ${{ matrix.os }} steps: @@ -49,7 +49,7 @@ jobs: strategy: matrix: os: ["ubuntu-latest"] - python: ["3.7", "3.8"] + python: ["3.7", "3.8", "3.9"] runs-on: ${{ matrix.os }} steps: - name: ๐Ÿ‘€ Determine latest release diff --git a/setup.py b/setup.py index 04aa9ae42..8fcd2a705 100644 --- a/setup.py +++ b/setup.py @@ -57,7 +57,7 @@ INSTALL_REQUIRES = [ "websocket-client>=0.57,<1", "wrapt>=1.12.1,<2", "emoji>=0.5.4,<1", - "frozendict>=1.2,<2", + "immutabledict>=1.2.0,<2", "sentry-sdk>=0.15.1,<1", "filetype>=1.0.7,<2", "zeroconf>=0.24,<0.25", diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 8adc36a53..9f71fdb21 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -12,7 +12,7 @@ import os import threading import time -from frozendict import frozendict +from immutabledict import immutabledict import octoprint.util.json from octoprint import util as util @@ -47,7 +47,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._logger_job = logging.getLogger(f"{__name__}.job") self._dict = ( - frozendict + immutabledict if settings().getBoolean(["devel", "useFrozenDictForPrinterState"]) else dict ) @@ -188,7 +188,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): @property def firmware_info(self): - return frozendict(self._firmware_info) if self._firmware_info else None + return immutabledict(self._firmware_info) if self._firmware_info else None # ~~ handling of PrinterCallbacks @@ -802,11 +802,11 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): return self._comm.getErrorString() def get_current_data(self, *args, **kwargs): - return util.thaw_frozendict(self._stateMonitor.get_current_data()) + return util.thaw_immutabledict(self._stateMonitor.get_current_data()) def get_current_job(self, *args, **kwargs): currentData = self._stateMonitor.get_current_data() - return util.thaw_frozendict(currentData["job"]) + return util.thaw_immutabledict(currentData["job"]) def get_current_temperatures(self, *args, **kwargs): if self._comm is not None: diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index 681de5b9c..0863b3169 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -25,7 +25,7 @@ from collections.abc import Iterable, MutableMapping, Set from functools import wraps from typing import Union -import frozendict +from immutabledict import immutabledict from octoprint import UMASK from octoprint.util.connectivity import ConnectivityChecker # noqa: F401 @@ -1323,20 +1323,25 @@ glob_escape = deprecated( )(glob.escape) -def thaw_frozendict(obj): - if not isinstance(obj, (dict, frozendict.frozendict)): - raise ValueError("obj must be a dict or frozendict instance") +def thaw_immutabledict(obj): + if not isinstance(obj, (dict, immutabledict)): + raise ValueError("obj must be a dict or immutabledict instance") # only true love can thaw a frozen dict letitgo = {} for key, value in obj.items(): - if isinstance(value, (dict, frozendict.frozendict)): - letitgo[key] = thaw_frozendict(value) + if isinstance(value, (dict, immutabledict)): + letitgo[key] = thaw_immutabledict(value) else: letitgo[key] = copy.deepcopy(value) return letitgo +thaw_frozendict = deprecated( + "thaw_frozendict has been renamed to thaw_immutabledict", since="1.6.0" +)(thaw_immutabledict) + + def utmify(link, source=None, medium=None, name=None, term=None, content=None): if source is None: return link diff --git a/src/octoprint/util/json/__init__.py b/src/octoprint/util/json/__init__.py index 5272c01a6..1d60b6b9a 100644 --- a/src/octoprint/util/json/__init__.py +++ b/src/octoprint/util/json/__init__.py @@ -5,7 +5,11 @@ __copyright__ = "Copyright (C) 2018 The OctoPrint Project - Released under terms import collections import json -import frozendict +try: + from immutabledict import immutabledict +except ImportError: + # Python 2 + from frozendict import frozendict as immutabledict from octoprint.util import to_unicode @@ -42,5 +46,5 @@ class JsonEncoding: raise TypeError -JsonEncoding.add_encoder(frozendict.frozendict, lambda obj: dict(obj)) +JsonEncoding.add_encoder(immutabledict, lambda obj: dict(obj)) JsonEncoding.add_encoder(bytes, lambda obj: to_unicode(obj)) diff --git a/tests/util/test_misc.py b/tests/util/test_misc.py index 194fff0e5..07bfe6bdb 100644 --- a/tests/util/test_misc.py +++ b/tests/util/test_misc.py @@ -5,7 +5,12 @@ __copyright__ = "Copyright (C) 2017 The OctoPrint Project - Released under terms import unittest import ddt -from frozendict import frozendict + +try: + from immutabledict import immutabledict +except ImportError: + # Python 2 + from frozendict import frozendict as immutabledict import octoprint.util @@ -63,31 +68,35 @@ class MiscTestCase(unittest.TestCase): self.assertEqual(actual, expected) @ddt.data( - (frozendict(a=1, b=2, c=3), {"a": 1, "b": 2, "c": 3}), + (immutabledict(a=1, b=2, c=3), {"a": 1, "b": 2, "c": 3}), ( - frozendict(a=1, b=2, c=frozendict(c1=1, c2=2)), + immutabledict(a=1, b=2, c=immutabledict(c1=1, c2=2)), {"a": 1, "b": 2, "c": {"c1": 1, "c2": 2}}, ), ({"a": 1, "b": 2, "c": 3}, {"a": 1, "b": 2, "c": 3}), ( - {"a": 1, "b": 2, "c": frozendict(c1=1, c2=2)}, + {"a": 1, "b": 2, "c": immutabledict(c1=1, c2=2)}, {"a": 1, "b": 2, "c": {"c1": 1, "c2": 2}}, ), ( - {"a": 1, "b": 2, "c": {"c1": 1, "c2": 2, "c3": frozendict(c11=11, c12=12)}}, + { + "a": 1, + "b": 2, + "c": {"c1": 1, "c2": 2, "c3": immutabledict(c11=11, c12=12)}, + }, {"a": 1, "b": 2, "c": {"c1": 1, "c2": 2, "c3": {"c11": 11, "c12": 12}}}, ), ) @ddt.unpack - def test_unfreeze_frozendict(self, input, expected): - result = octoprint.util.thaw_frozendict(input) + def test_unfreeze_immutabledict(self, input, expected): + result = octoprint.util.thaw_immutabledict(input) self.assertIsInstance(result, dict) self.assertDictEqual(result, expected) @ddt.data(None, "invalid", 3, [1, 2], (3, 4)) - def test_unfreeze_frozendict_invalid(self, input): + def test_unfreeze_immutabledict_invalid(self, input): try: - octoprint.util.thaw_frozendict(input) + octoprint.util.thaw_immutabledict(input) self.fail("expected ValueError") except ValueError: # expected