From 8680ca449573f1efbc48f2eb3f05bf09e4e877fe Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 1 Aug 2022 09:23:56 +0200 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=8E=A8=20Convert=20type=20comments=20?= =?UTF-8?q?into=20Python=20type=20hints=20(#4575)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * com2ann: Convert type comments into Python type hints - again * Make modifications based on code review --- docs/sphinxext/codeblockext.py | 10 +++------- docs/sphinxext/onlineinclude.py | 13 ++++--------- src/octoprint/filemanager/storage.py | 4 ++-- src/octoprint/util/__init__.py | 5 ++--- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/docs/sphinxext/codeblockext.py b/docs/sphinxext/codeblockext.py index cfbbadbb0..d21600121 100644 --- a/docs/sphinxext/codeblockext.py +++ b/docs/sphinxext/codeblockext.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, division, print_function, unicode_literals +from __future__ import annotations __author__ = "Gina Häußge " __license__ = "The MIT License " @@ -20,9 +19,7 @@ from pygments.filters import VisibleWhitespaceFilter, ErrorToken from pygments.lexers.python import PythonConsoleLexer from pygments.util import ClassNotFound -if False: - # For type annotation - from typing import Any, Dict, List, Tuple # NOQA +from typing import Any def _merge_dict(a, b): @@ -75,8 +72,7 @@ class CodeBlockExt(CodeBlock): option_spec = _merge_dict(CodeBlock.option_spec, {"whitespace": directives.flag}) - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> list[nodes.Node]: # get result from parent implementation code_block = CodeBlock.run(self) diff --git a/docs/sphinxext/onlineinclude.py b/docs/sphinxext/onlineinclude.py index 5344e3473..1e9356aeb 100644 --- a/docs/sphinxext/onlineinclude.py +++ b/docs/sphinxext/onlineinclude.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, division, print_function, unicode_literals +from __future__ import annotations __author__ = "Gina Häußge " __license__ = "The MIT License " @@ -21,16 +20,13 @@ from sphinx.directives.code import ( ) from sphinx.util.nodes import set_source_info -if False: - # For type annotation - from typing import Any, List # NOQA +from typing import Any cache = {} class OnlineIncludeReader(LiteralIncludeReader): - def read_file(self, filename, location=None): - # type: (unicode, Any) -> List[unicode] + def read_file(self, filename: str, location: Any = None) -> list[str]: global cache try: @@ -56,8 +52,7 @@ class OnlineIncludeReader(LiteralIncludeReader): class OnlineIncludeDirective(LiteralInclude): - def run(self): - # type: () -> List[nodes.Node] + def run(self) -> list[nodes.Node]: document = self.state.document if not document.settings.file_insertion_enabled: return [ diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index 8cd24d38c..007685d93 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -164,7 +164,7 @@ class StorageInterface: :param string path: the path of the new folder :param bool ignore_existing: if set to True, no error will be raised if the folder to be added already exists - :param unicode display: display name of the folder + :param str display: display name of the folder :return: the sanitized name of the new folder to be used for future references to the folder """ raise NotImplementedError() @@ -220,7 +220,7 @@ class StorageInterface: :param list links: any links to add with the file :param bool allow_overwrite: if set to True no error will be raised if the file already exists and the existing file and its metadata will just be silently overwritten - :param unicode display: display name of the file + :param str display: display name of the file :return: the sanitized name of the file to be used for future references to it """ raise NotImplementedError() diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index b7f5cb79e..70f95865f 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -77,7 +77,7 @@ def to_unicode( s_or_u: Union[str, bytes], encoding: str = "utf-8", errors: str = "strict" ) -> str: """ - Make sure ``s_or_u`` is a unicode string (str). + Make sure ``s_or_u`` is a string (str). Arguments: s_or_u (str or bytes): The value to convert @@ -202,7 +202,6 @@ def warning_factory(warning_type): "__dict__", "__doc__", "__str__", - "__unicode__", "__repr__", "__getattribute__", "__setattr__", @@ -1611,7 +1610,7 @@ class CaseInsensitiveSet(Set): """ Basic case insensitive set - Any str or unicode values will be stored and compared in lower case. Other value types are left as-is. + Any str values will be stored and compared in lower case. Other value types are left as-is. """ def __init__(self, *args): From 7824d0e58c7de92e302c2eaec84cfc8729056445 Mon Sep 17 00:00:00 2001 From: Charlie Powell <31997505+cp2004@users.noreply.github.com> Date: Mon, 1 Aug 2022 10:31:36 +0100 Subject: [PATCH 2/8] :sparkles: Automatically detect less files to build (#4584) --- src/octoprint/cli/dev.py | 103 +++++++++++++++------------------------ 1 file changed, 39 insertions(+), 64 deletions(-) diff --git a/src/octoprint/cli/dev.py b/src/octoprint/cli/dev.py index 4cee08083..ad8a29c4f 100644 --- a/src/octoprint/cli/dev.py +++ b/src/octoprint/cli/dev.py @@ -262,55 +262,38 @@ class OctoPrintDevelCommands(click.MultiCommand): "--list", "list_files", is_flag=True, help="List all available files and exit" ) def command(files, all_files, list_files): - import os.path import shutil + from pathlib import Path - available_files = { - "core": { - "source": "static/less/octoprint.less", - "output": "static/css/octoprint.css", - }, - "login": { - "source": "static/less/login.less", - "output": "static/css/login.css", - }, - "recovery": { - "source": "static/less/recovery.less", - "output": "static/css/recovery.css", - }, - "plugin_announcements": { - "source": "plugins/announcements/static/less/announcements.less", - "output": "plugins/announcements/static/css/announcements.css", - }, - "plugin_appkeys_core": { - "source": "plugins/appkeys/static/less/appkeys.less", - "output": "plugins/appkeys/static/css/appkeys.css", - }, - "plugin_appkeys_authdialog": { - "source": "plugins/appkeys/static/less/authdialog.less", - "output": "plugins/appkeys/static/css/authdialog.css", - }, - "plugin_backup": { - "source": "plugins/backup/static/less/backup.less", - "output": "plugins/backup/static/css/backup.css", - }, - "plugin_gcodeviewer": { - "source": "plugins/gcodeviewer/static/less/gcodeviewer.less", - "output": "plugins/gcodeviewer/static/css/gcodeviewer.css", - }, - "plugin_logging": { - "source": "plugins/logging/static/less/logging.less", - "output": "plugins/logging/static/css/logging.css", - }, - "plugin_pluginmanager": { - "source": "plugins/pluginmanager/static/less/pluginmanager.less", - "output": "plugins/pluginmanager/static/css/pluginmanager.css", - }, - "plugin_softwareupdate": { - "source": "plugins/softwareupdate/static/less/softwareupdate.less", - "output": "plugins/softwareupdate/static/css/softwareupdate.css", - }, - } + # src/octoprint + octoprint_base = Path(__file__).parent.parent + + available_files = {} + for less_file in Path(octoprint_base, "static", "less").glob("*.less"): + # Check corresponding css file exists + # Less files can be imported, not all need building + css_file = Path(less_file.parent.parent, "css", f"{less_file.stem}.css") + if css_file.exists(): + available_files[less_file.stem] = { + "source": str(less_file), + "output": str(css_file), + } + + path_to_plugins = Path(octoprint_base, "plugins") + for plugin in Path(path_to_plugins).iterdir(): + for less_file in Path(plugin, "static", "less").glob("*.less"): + name = f"plugin_{plugin.name}" + if less_file.stem != plugin.name: + name += f"_{less_file.stem}" + # Check there is a corresponding CSS file first + css_file = Path( + less_file.parent.parent, "css", f"{less_file.stem}.css" + ) + if css_file.exists(): + available_files[name] = { + "source": str(less_file), + "output": str(css_file), + } if list_files: click.echo("Available files to build:") @@ -329,7 +312,6 @@ class OctoPrintDevelCommands(click.MultiCommand): # Check that lessc is installed less = shutil.which("lessc") - if not less: click.echo( "lessc is not installed/not available, please install it first" @@ -339,26 +321,19 @@ class OctoPrintDevelCommands(click.MultiCommand): ) sys.exit(1) - # Find the folder of the `octoprint` package - # Two folders up from this file - octoprint = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - for file in files: - if file not in available_files.keys(): - click.echo(f"Unknown file {file}") + for less_file in files: + if less_file not in available_files.keys(): + click.echo(f"Unknown file {less_file}") sys.exit(1) - source_path = os.path.join(octoprint, available_files[file]["source"]) - output_path = os.path.join(octoprint, available_files[file]["output"]) - - # Check the target file exists - if not os.path.exists(source_path): - click.echo(f"Target file {source_path} does not exist") - continue - # Build command line, with necessary options # TODO -x is deprecated, find replacement? - less_command = [less, "-x", source_path, output_path] + less_command = [ + less, + "-x", + available_files[less_file]["source"], + available_files[less_file]["output"], + ] self.command_caller.call(less_command) From 037ca041223ce482f05eed1f01a7827fb30375eb Mon Sep 17 00:00:00 2001 From: Kestin Goforth Date: Mon, 1 Aug 2022 05:36:16 -0400 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=90=9B=20Use=20G2/G3=20arc=20length?= =?UTF-8?q?=20for=20move=20time=20estimates=20(#4581)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AUTHORS.md | 1 + src/octoprint/util/gcodeInterpreter.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index 4fe6c4cec..80e556ce3 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -167,6 +167,7 @@ date of first contribution): * [Zack Lewis](https://github.com/lima3w) * [Billy Richardson](https://github.com/richardsondev) * [Christian Bianchini](https://github.com/max246) + * [Kestin Goforth](https://github.com/kforth) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index 5574d246f..fa217e73f 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -587,8 +587,13 @@ class gcode: else: e = 0 + # calculate 3d arc length + arcLengthXYZ = math.sqrt( + (oldPos.z - pos.z) ** 2 + ((endAngle - startAngle) * r) ** 2 + ) + # move time in x, y, z, will be 0 if no movement happened - moveTimeXYZ = abs((oldPos - pos).length / feedrate) + moveTimeXYZ = abs(arcLengthXYZ / feedrate) # time needed for extruding, will be 0 if no extrusion happened extrudeTime = abs(e / feedrate) From 5753ee3cfa26a78feceee0b137ca72bd4bbf0b34 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 1 Aug 2022 11:41:55 +0200 Subject: [PATCH 4/8] =?UTF-8?q?=E2=9C=8F=20Highlight=20branch=20names=20in?= =?UTF-8?q?=20PR=20template=20(#4573)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PULL_REQUEST_TEMPLATE.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 9d7dce15b..f8c0d33a3 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,10 +1,10 @@ + + + + {{ _('Set this if you keep running into rate limiting issues. See here for how to obtain a token.', url="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token") }} From a3554994674a08fbc90838c4f4cd1223b2aebf67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 2 Aug 2022 14:14:34 +0200 Subject: [PATCH 8/8] =?UTF-8?q?=E2=9C=A8=20Support=20traefik's=20X-Forward?= =?UTF-8?q?ed-Prefix=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Traefik sets `X-Forwarded-Prefix` to the prefix path if the stripPrefix middleware is used. Instead of having to define `X-Script-Name` manually in such cases, this now makes OctoPrint also check that header for prefix information. See also https://doc.traefik.io/traefik/middlewares/http/stripprefix/ --- src/octoprint/server/util/flask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index 8cc2c679f..b63d7295b 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -265,7 +265,7 @@ class ReverseProxiedEnvironment: # sensible defaults if header_prefix is None: - header_prefix = ["x-script-name"] + header_prefix = ["x-script-name", "x-forwarded-prefix"] if header_scheme is None: header_scheme = ["x-forwarded-proto", "x-scheme"] if header_host is None: