diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c8f851c04..66bbab9fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: name: ๐Ÿ”จ Build distribution runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: ๐Ÿ— Set up Python 3.7 @@ -34,7 +34,7 @@ jobs: name: ๐Ÿงน Pre-commit runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: ๐Ÿ— Set up Python 3.7 uses: actions/setup-python@v4 with: @@ -50,10 +50,10 @@ jobs: name: ๐Ÿงช Unit tests strategy: matrix: - python: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: ๐Ÿ— Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: @@ -70,7 +70,7 @@ jobs: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: ๐Ÿ— Set up test dependencies run: | npm -g install node-qunit-puppeteer@2.1.2 @@ -84,7 +84,7 @@ jobs: needs: build strategy: matrix: - python: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] installable: ["wheel", "sdist"] runs-on: ubuntu-latest steps: @@ -110,9 +110,12 @@ jobs: name: ๐Ÿงช E2E tests needs: build runs-on: ubuntu-latest + strategy: + matrix: + python: ["3.7", "3.12"] steps: - name: โฌ‡ Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: โฌ‡ Download build result uses: actions/download-artifact@v3 @@ -120,10 +123,10 @@ jobs: name: dist path: dist - - name: ๐Ÿ— Set up Python 3.7 + - name: ๐Ÿ— Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: ${{ matrix.python }} - name: ๐Ÿ— Install OctoPrint build run: | diff --git a/.github/workflows/nightly_merge.yml b/.github/workflows/nightly_merge.yml index d12689240..d971ab841 100644 --- a/.github/workflows/nightly_merge.yml +++ b/.github/workflows/nightly_merge.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: โฌ‡ Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/test_install.yml b/.github/workflows/test_install.yml index 7976d1be2..a908de3c6 100644 --- a/.github/workflows/test_install.yml +++ b/.github/workflows/test_install.yml @@ -23,7 +23,7 @@ jobs: with: python-version: ${{ matrix.python }} - name: โฌ‡ Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ matrix.branch }} fetch-depth: 0 diff --git a/AUTHORS.md b/AUTHORS.md index 5edba0f32..3a8f3f5ec 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -179,6 +179,7 @@ date of first contribution): * [Shyam Sunder](https://github.com/sgsunder) * [Conny Rasch](https://github.com/CMR-DEV) * [Christopher Perrin](https://github.com/cperrin88) + * [Jatin Saini](https://github.com/jatin-47) * [Martin Bartsch](https://github.com/kaenguruhs) * [Matthias Weis](https://github.com/mad73923) diff --git a/README.md b/README.md index de841841b..a533954b5 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ access control as necessary. OctoPrint depends on a few python modules to do its job. Those are automatically installed when installing OctoPrint via `pip`. -OctoPrint currently supports Python 3.7, 3.8, 3.9, 3.10 and 3.11. +OctoPrint currently supports Python 3.7, 3.8, 3.9, 3.10, 3.11 and 3.12. ## Usage diff --git a/setup.py b/setup.py index 76bb69c91..d2c7a08c7 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ import versioneer # noqa: F401 # ---------------------------------------------------------------------------------------- # Supported python versions -PYTHON_REQUIRES = ">=3.7, <3.12" +PYTHON_REQUIRES = ">=3.7, <3.13" # Requirements for setup.py SETUP_REQUIRES = [] @@ -69,6 +69,7 @@ core_deps = [ "sarge==0.1.7.post1", "semantic_version>=2.10.0,<3", "sentry-sdk>=1.19.1,<2", + "setuptools", "tornado>=6.2,<7", "watchdog>=2.3.1,<3", "websocket-client>=1.5.1,<2", @@ -350,6 +351,7 @@ def params(): "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: JavaScript", diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py index 297386e4a..b793f401d 100644 --- a/src/octoprint/plugin/core.py +++ b/src/octoprint/plugin/core.py @@ -115,7 +115,10 @@ def parse_plugin_metadata(path): for a in reversed(assignments): targets = extract_target_ids(a) if key in targets: - if isinstance(a.value, ast.Str): + if isinstance(a.value, ast.Constant): + result[key] = a.value.value + + elif isinstance(a.value, ast.Str): result[key] = a.value.s elif ( diff --git a/src/octoprint/plugins/action_command_notification/__init__.py b/src/octoprint/plugins/action_command_notification/__init__.py index 9ed83c20f..282a8ecb8 100644 --- a/src/octoprint/plugins/action_command_notification/__init__.py +++ b/src/octoprint/plugins/action_command_notification/__init__.py @@ -1,6 +1,7 @@ __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" __copyright__ = "Copyright (C) 2020 The OctoPrint Project - Released under terms of the AGPLv3 License" +import re import time import flask @@ -21,6 +22,7 @@ class ActionCommandNotificationPlugin( ): def __init__(self): self._notifications = [] + self._filter = "" # Additional permissions hook @@ -60,7 +62,20 @@ class ActionCommandNotificationPlugin( # ~ SettingsPlugin def get_settings_defaults(self): - return {"enable": True, "enable_popups": False} + return {"enable": True, "enable_popups": False, "filter": ""} + + def on_settings_initialized(self): + try: + self._filter = re.compile(self._settings.get(["filter"])) + except re.error: + self._filter = "" + + def on_settings_save(self, data): + octoprint.plugin.SettingsPlugin.on_settings_save(self, data) + try: + self._filter = re.compile(self._settings.get(["filter"])) + except re.error: + self._filter = "" # ~ SimpleApiPlugin @@ -90,7 +105,7 @@ class ActionCommandNotificationPlugin( { "type": "settings", "name": gettext("Printer Notifications"), - "custom_bindings": False, + "custom_bindings": True, }, { "type": "sidebar", @@ -120,6 +135,11 @@ class ActionCommandNotificationPlugin( return message = parameter.strip() + + if self._filter.search(message): + self._logger.debug(f"Notification matches filter regex: {message}") + return + self._notifications.append((time.time(), message)) self._plugin_manager.send_plugin_message(self._identifier, {"message": message}) diff --git a/src/octoprint/plugins/action_command_notification/static/js/action_command_notification.js b/src/octoprint/plugins/action_command_notification/static/js/action_command_notification.js index 1e7dd8441..8a00592db 100644 --- a/src/octoprint/plugins/action_command_notification/static/js/action_command_notification.js +++ b/src/octoprint/plugins/action_command_notification/static/js/action_command_notification.js @@ -12,6 +12,17 @@ $(function () { self._toLocalStorage(); }); + self.regexValid = function () { + try { + new RegExp( + self.settings.settings.plugins.action_command_notification.filter() + ); + return true; + } catch (e) { + return false; + } + }; + self.toDateTimeString = function (timestamp) { return formatDate(timestamp); }; @@ -106,6 +117,9 @@ $(function () { OCTOPRINT_VIEWMODELS.push({ construct: ActionCommandNotificationViewModel, dependencies: ["loginStateViewModel", "accessViewModel", "settingsViewModel"], - elements: ["#sidebar_plugin_action_command_notification_wrapper"] + elements: [ + "#sidebar_plugin_action_command_notification_wrapper", + "#settings_plugin_action_command_notification" + ] }); }); diff --git a/src/octoprint/plugins/action_command_notification/templates/action_command_notification_settings.jinja2 b/src/octoprint/plugins/action_command_notification/templates/action_command_notification_settings.jinja2 index a5d079b9b..ffa07b888 100644 --- a/src/octoprint/plugins/action_command_notification/templates/action_command_notification_settings.jinja2 +++ b/src/octoprint/plugins/action_command_notification/templates/action_command_notification_settings.jinja2 @@ -4,16 +4,23 @@
+
+ +
+ + {{ _('Use this to write a valid regular expression to hide notifications having the pattern defined in it. Chain multiple filters using "|". For more information, please see the Python docs on regular expressions')|format(tut_url="https://docs.python.org/3/library/re.html") }} +
+
diff --git a/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js b/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js index 6acb249a2..32e1122ed 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js @@ -357,21 +357,20 @@ var gCodeLineGenerator = async function* (fileURL) { // the download failed. if (!response.ok) return; - // create a reader object that will read the incoming data - const reader = response.body.getReader(); - // we use these two variables to calculate the percentage. var totalDownloadLength = response.headers.get("X-Original-Content-Length"); var currentDownloadLength = 0; - // lets read a first data chunk - let {value: chunk, done: readerDone} = await reader.read(); - chunk = chunk ? utf8Decoder.decode(chunk) : ""; - // some init const re = /\n|\r|\r\n/gm; let startIndex = 0; - let result; + + // create a reader object that will read the incoming data + const reader = response.body.getReader(); + + // lets read a first data chunk + let {value: chunk, done: readerDone} = await reader.read(); + chunk = chunk ? utf8Decoder.decode(chunk) : ""; // now continue until all the downloaded data is processed. for (;;) { @@ -386,7 +385,11 @@ var gCodeLineGenerator = async function* (fileURL) { } // lets read a new chunk let remainder = chunk.substr(startIndex); + + //console.log("reading chunk..."); // debug for #4879 ({value: chunk, done: readerDone} = await reader.read()); + //console.log("read chunk"); // debug for #4879 + // concatenate with our leftovers from the previous chunk chunk = remainder + (chunk ? utf8Decoder.decode(chunk) : ""); // reset the indexes @@ -405,6 +408,7 @@ var gCodeLineGenerator = async function* (fileURL) { // move to after the line we just returned startIndex = re.lastIndex; } + if (startIndex < chunk.length) { // last line didn't end in a newline char currentDownloadLength += chunk.length - startIndex; diff --git a/src/octoprint/settings/__init__.py b/src/octoprint/settings/__init__.py index 68ff2d290..c281d8969 100644 --- a/src/octoprint/settings/__init__.py +++ b/src/octoprint/settings/__init__.py @@ -253,10 +253,10 @@ class HierarchicalChainMap: def _cached_prefixed_keys(self, prefix): if prefix not in self._prefixed_keys: - self._prefixed_keys[prefix] = [ - k for k in self._chainmap.keys() if k.startswith(prefix) - ] - return self._prefixed_keys[prefix] + keys = [k for k in self._chainmap.keys() if k.startswith(prefix)] + if keys: + self._prefixed_keys[prefix] = keys + return self._prefixed_keys.get(prefix, []) def _invalidate_prefixed_keys(self, prefix): seps = [] @@ -270,6 +270,10 @@ class HierarchicalChainMap: except KeyError: pass + to_delete = [key for key in self._prefixed_keys.keys() if key.startswith(prefix)] + for prefix in to_delete: + del self._prefixed_keys[prefix] + def deep_dict(self): return self._unflatten(self._chainmap) @@ -439,19 +443,13 @@ class HierarchicalChainMap: def insert_map(self, pos, d): flattened = self._flatten(d) for k in flattened: - if _CHAINMAP_SEP in k: - self._invalidate_prefixed_keys( - k.rsplit(_CHAINMAP_SEP, 1)[0] + _CHAINMAP_SEP - ) + self._invalidate_prefixed_keys(k + _CHAINMAP_SEP) self._chainmap.maps.insert(pos, flattened) def delete_map(self, pos): flattened = self._chainmap.maps[pos] for k in flattened: - if _CHAINMAP_SEP in k: - self._invalidate_prefixed_keys( - k.rsplit(_CHAINMAP_SEP, 1)[0] + _CHAINMAP_SEP - ) + self._invalidate_prefixed_keys(k + _CHAINMAP_SEP) del self._chainmap.maps[pos] @property diff --git a/src/octoprint/vendor/awesome_slugify/main.py b/src/octoprint/vendor/awesome_slugify/main.py index dfb07b063..430642d28 100644 --- a/src/octoprint/vendor/awesome_slugify/main.py +++ b/src/octoprint/vendor/awesome_slugify/main.py @@ -41,7 +41,7 @@ def join_words(words, separator, max_length=None): # uppercase letters to translate to uppercase letters, NOT camelcase UPPER_TO_UPPER_LETTERS_RE = \ - u''' + r''' ( \p{Uppercase_Letter} {2,} # 2 or more adjacent letters - UP always | @@ -95,7 +95,7 @@ class Slugify(object): convert_dict[letter_upper] = translation.capitalize() self.convert_dict = convert_dict - PRETRANSLATE = re.compile(u'(\L)', options=convert_dict) + PRETRANSLATE = re.compile(r'(\L)', options=convert_dict) # translate some letters before translating return lambda text: PRETRANSLATE.sub(lambda m: convert_dict[m.group(1)], text) @@ -137,11 +137,11 @@ class Slugify(object): stop_words = property(fset=set_stop_words) def calc_unwanted_chars_re(self): - unwanted_chars_re = u'[^\p{{AlNum}}{safe_chars}]+'.format(safe_chars=re.escape(self._safe_chars or '')) + unwanted_chars_re = r'[^\p{{AlNum}}{safe_chars}]+'.format(safe_chars=re.escape(self._safe_chars or '')) self.unwanted_chars_re = re.compile(unwanted_chars_re, re.IGNORECASE) if self._stop_words: - unwanted_chars_and_words_re = unwanted_chars_re + u'|(?)(?!\p{AlNum})' + unwanted_chars_and_words_re = unwanted_chars_re + r'|(?)(?!\p{AlNum})' self.unwanted_chars_and_words_re = re.compile(unwanted_chars_and_words_re, re.IGNORECASE, stop_words=self._stop_words) else: self.unwanted_chars_and_words_re = None diff --git a/tests/plugin/test_settings.py b/tests/plugin/test_settings.py index 6d5a3d428..36f52182d 100644 --- a/tests/plugin/test_settings.py +++ b/tests/plugin/test_settings.py @@ -111,6 +111,7 @@ def test_deprecated_forwarded_getter( called_method.__name__ = forwarded called_method.__qualname__ = forwarded called_method.__annotations__ = {} + called_method.__type_params__ = () method = getattr(plugin_settings, deprecated) assert callable(method) @@ -330,6 +331,7 @@ def test_deprecated_forwarded_setter( called_method.__name__ = forwarded called_method.__qualname__ = forwarded called_method.__annotations__ = {} + called_method.__type_params__ = () method = getattr(plugin_settings, deprecated) assert callable(method) diff --git a/tests/settings/_files/config.yaml b/tests/settings/_files/config.yaml index c6d98294a..c660f9a12 100644 --- a/tests/settings/_files/config.yaml +++ b/tests/settings/_files/config.yaml @@ -18,6 +18,14 @@ plugins: a: 1 b: 2 c: 3 + baz: + a: 1 + b: 2 + c: 3 + d: + a: 1 + b: 2 + c: 3 server: port: 8080 devel: diff --git a/tests/settings/test_settings.py b/tests/settings/test_settings.py index ce282d3bd..b19608956 100644 --- a/tests/settings/test_settings.py +++ b/tests/settings/test_settings.py @@ -772,6 +772,10 @@ def _key(*path): return octoprint.settings._CHAINMAP_SEP.join(path) +def _prefix(*path): + return _key(*path) + octoprint.settings._CHAINMAP_SEP + + @ddt.ddt class ChainmapTest(unittest.TestCase): def setUp(self): @@ -915,3 +919,66 @@ class ChainmapTest(unittest.TestCase): self.assertEqual( expected, octoprint.settings.HierarchicalChainMap._unflatten(value) ) + + def test_prefix_caching_has_populates(self): + # this should populate the prefix cache + self.chainmap.has_path(["plugins", "foo"]) + + # validate that + self.assertTrue(len(self.chainmap._prefixed_keys) == 1) + self.assertTrue(_prefix("plugins", "foo") in self.chainmap._prefixed_keys) + + def test_prefix_caching_get_populates(self): + # this should populate the prefix cache + self.chainmap.get_by_path(["plugins", "foo"]) + + # validate that + self.assertTrue(len(self.chainmap._prefixed_keys) == 1) + self.assertTrue(_prefix("plugins", "foo") in self.chainmap._prefixed_keys) + + def test_prefix_caching_scalars_ignored(self): + # this shouldn't populate the prefix cache + self.chainmap.has_path(["api", "key"]) + + # validate that + self.assertTrue(len(self.chainmap._prefixed_keys) == 0) + + def test_prefix_caching_set_invalidates(self): + # this should populate the prefix cache + self.chainmap.has_path(["plugins", "foo"]) + + # validate that + self.assertTrue(len(self.chainmap._prefixed_keys) == 1) + self.assertTrue(_prefix("plugins", "foo") in self.chainmap._prefixed_keys) + + # this should extend the prefix cache + self.chainmap.get_by_path(["plugins", "foo", "bar"]) + + # validate that + self.assertTrue(len(self.chainmap._prefixed_keys) == 2) + self.chainmap.has_path(["plugins", "foo", "bar"]) + + # this should remove all plugins.foo keys in the prefix cache + self.chainmap.set_by_path(["plugins", "foo"], {}) + + # validate that + self.assertTrue(len(self.chainmap._prefixed_keys) == 0) + + def test_prefix_caching_del_invalidates(self): + # this should populate the prefix cache + self.chainmap.has_path(["plugins", "baz", "d"]) + + # validate that + self.assertTrue(len(self.chainmap._prefixed_keys) == 1) + self.assertTrue(_prefix("plugins", "baz", "d") in self.chainmap._prefixed_keys) + + # this should remove all plugins.baz keys in the prefix cache + self.chainmap.del_by_path(["plugins", "baz"]) + + # validate that + keys = [ + key + for key in self.chainmap._prefixed_keys + if key.startswith(_prefix("plugins", "baz")) + ] + self.assertTrue(len(keys) == 0) diff --git a/versioneer.py b/versioneer.py index 63428fa14..f67734948 100644 --- a/versioneer.py +++ b/versioneer.py @@ -442,10 +442,14 @@ def get_config_from_root(root): # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") - # TODO: find a py2 compatible solution for the configparser deprecation issues - parser = configparser.SafeConfigParser() - with io.open(setup_cfg, "rt", encoding="utf-8") as f: - parser.readfp(f) + try: + parser = configparser.SafeConfigParser() + with io.open(setup_cfg, "rt", encoding="utf-8") as f: + parser.readfp(f) + except AttributeError: # python 3.12 no longer has SafeConfigParser + parser = configparser.ConfigParser() + with io.open(setup_cfg, "rt", encoding="utf-8") as f: + parser.read_file(f) VCS = parser.get("versioneer", "VCS") # mandatory