diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1705c0dc1..db8e594b0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,9 @@ +default_language_version: + python: python3.10 exclude: ^(src/octoprint/vendor/|src/octoprint/static/js/lib|src/octoprint/static/vendor|tests/static/js/lib|tests/util/_files|scripts/|translations/|.*\.css|.*\.svg) repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.4.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace @@ -14,7 +16,7 @@ repos: args: ["--remove"] exclude: "setup.py|versioneer.py|src/octoprint_setuptools/__init__.py" - repo: https://github.com/asottile/pyupgrade - rev: v2.31.0 + rev: v3.3.1 hooks: - id: pyupgrade args: ["--py37-plus"] @@ -43,26 +45,23 @@ repos: hooks: - id: isort - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.1.0 hooks: - id: black - additional_dependencies: - - click==8.0.4 - repo: https://github.com/pycqa/flake8 - rev: 3.9.2 + rev: 6.0.0 hooks: - id: flake8 args: [--config=setup.cfg] additional_dependencies: - - flake8-bugbear==22.3.20 - - importlib-metadata<5.0 + - flake8-bugbear exclude: ^(docs/) - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.5.1 + rev: v2.7.1 hooks: - id: prettier - repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.8.0 + rev: v8.34.0 hooks: - id: eslint additional_dependencies: @@ -70,7 +69,7 @@ repos: files: \.js$ exclude: ^(src/octoprint/vendor/|tests/static/js/lib|tests/util/_files|docs/|scripts/|translations/) - repo: https://github.com/codespell-project/codespell - rev: v2.1.0 + rev: v2.2.2 hooks: - id: codespell exclude: ^(src/octoprint/vendor/|tests/static/js/lib|tests/util/_files|tests/playwright|scripts/) diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index bf4207bea..583826706 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -1360,7 +1360,7 @@ octoprint.printer.sdcardupload to be created on the ``sdcard`` storage. ``elapsed`` is the elapsed time in seconds. If the hook is going to handle the upload, it must return the (future) remote filename of the file on the ``sdcard`` - storage. If it returns ``None`` (or an otherwise falsy value), OctoPrint will interpret this as the hook not going to + storage. If it returns ``None`` (or an otherwise false-y value), OctoPrint will interpret this as the hook not going to handle the file upload, in which case the next hook or - if no other hook is registered - the default implementation will be called. diff --git a/docs/sphinxext/onlineinclude.py b/docs/sphinxext/onlineinclude.py index 0d87709f3..cfe369718 100644 --- a/docs/sphinxext/onlineinclude.py +++ b/docs/sphinxext/onlineinclude.py @@ -26,7 +26,6 @@ cache = {} class OnlineIncludeReader(LiteralIncludeReader): def read_file(self, filename: str, location: Any = None) -> list[str]: - global cache try: if filename in cache: diff --git a/setup.cfg b/setup.cfg index f02d12124..6d4730827 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,7 +15,7 @@ lookupfile = .versioneer-lookup [flake8] max-line-length = 90 -extend-ignore = E203, E231, E265, E266, E402, E501, E731 +extend-ignore = E203, E231, E265, E266, E402, E501, E731, B023, B903, B904, B907, B950, W503 select = B,C,E,F,W,T4,B9 exclude = src/octoprint/vendor diff --git a/src/octoprint/access/permissions.py b/src/octoprint/access/permissions.py index cb4519491..311f3172c 100644 --- a/src/octoprint/access/permissions.py +++ b/src/octoprint/access/permissions.py @@ -268,7 +268,6 @@ class PermissionsMetaClass(type): class Permissions(metaclass=PermissionsMetaClass): - # Special permission ADMIN = OctoPrintPermission( "Admin", diff --git a/src/octoprint/cli/__init__.py b/src/octoprint/cli/__init__.py index 91a57b79a..b08415610 100644 --- a/src/octoprint/cli/__init__.py +++ b/src/octoprint/cli/__init__.py @@ -362,7 +362,6 @@ from .systeminfo import cli as systeminfo_commands # noqa: E402 @click.version_option(version=octoprint.__version__, allow_from_autoenv=False) @click.pass_context def octo(ctx, **kwargs): - if ctx.invoked_subcommand is None: # We have to support calling the octoprint command without any # sub commands to remain backwards compatible. diff --git a/src/octoprint/daemon.py b/src/octoprint/daemon.py index 2ec04e98f..48f66dd04 100644 --- a/src/octoprint/daemon.py +++ b/src/octoprint/daemon.py @@ -63,8 +63,8 @@ class Daemon: sys.stdout.flush() sys.stderr.flush() si = open(os.devnull, encoding="utf-8") - so = open(os.devnull, "at+", encoding="utf-8") - se = open(os.devnull, "at+", encoding="utf-8") + so = open(os.devnull, "a+", encoding="utf-8") + se = open(os.devnull, "a+", encoding="utf-8") os.dup2(si.fileno(), sys.stdin.fileno()) os.dup2(so.fileno(), sys.stdout.fileno()) @@ -160,7 +160,7 @@ class Daemon: def set_pid(self, pid): """Write the pid to the pidfile.""" - with open(self.pidfile, "wt+", encoding="utf-8") as f: + with open(self.pidfile, "w+", encoding="utf-8") as f: f.write(str(pid) + "\n") def remove_pidfile(self): diff --git a/src/octoprint/environment.py b/src/octoprint/environment.py index be6a21e8b..6ae4768c1 100644 --- a/src/octoprint/environment.py +++ b/src/octoprint/environment.py @@ -167,7 +167,7 @@ class EnvironmentDetector: dumped_environment = yaml.dump(environment, pretty=True).strip() environment_lines = "\n".join( - map(lambda l: f"| {l}", dumped_environment.split("\n")) + map(lambda x: f"| {x}", dumped_environment.split("\n")) ) return "Detected environment is Python {} under {} ({}). Details:\n{}".format( environment["python"]["version"], diff --git a/src/octoprint/filemanager/destinations.py b/src/octoprint/filemanager/destinations.py index ea9496d32..42f17c4ed 100644 --- a/src/octoprint/filemanager/destinations.py +++ b/src/octoprint/filemanager/destinations.py @@ -2,6 +2,5 @@ __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agp class FileDestinations: - SDCARD = "sdcard" LOCAL = "local" diff --git a/src/octoprint/logging/filters.py b/src/octoprint/logging/filters.py index 0885a491a..0b6c941fc 100644 --- a/src/octoprint/logging/filters.py +++ b/src/octoprint/logging/filters.py @@ -8,7 +8,6 @@ class TornadoAccessFilter(logging.Filter): status, request_line, rtt = record.args if status == 409: - _, url, _ = request_line.split() u = urllib.parse.urlparse(url) if u.path in ("/api/printer",): diff --git a/src/octoprint/logging/handlers.py b/src/octoprint/logging/handlers.py index 479cba474..fe7fcac36 100644 --- a/src/octoprint/logging/handlers.py +++ b/src/octoprint/logging/handlers.py @@ -66,7 +66,6 @@ class OctoPrintStreamHandler(AsyncLogHandlerMixin, logging.StreamHandler): class TriggeredRolloverLogHandler( AsyncLogHandlerMixin, logging.handlers.RotatingFileHandler ): - do_rollover = False suffix_template = "%Y-%m-%d_%H-%M-%S" file_pattern = re.compile(r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}$") diff --git a/src/octoprint/plugins/action_command_prompt/__init__.py b/src/octoprint/plugins/action_command_prompt/__init__.py index 8a43d33dc..bb0dcb1eb 100644 --- a/src/octoprint/plugins/action_command_prompt/__init__.py +++ b/src/octoprint/plugins/action_command_prompt/__init__.py @@ -38,7 +38,6 @@ class ActionCommandPromptPlugin( octoprint.plugin.SimpleApiPlugin, octoprint.plugin.TemplatePlugin, ): - COMMAND = "M876" CAP_PROMPT_SUPPORT = "PROMPT_SUPPORT" diff --git a/src/octoprint/plugins/announcements/__init__.py b/src/octoprint/plugins/announcements/__init__.py index f0e713b9c..15f52ca3e 100644 --- a/src/octoprint/plugins/announcements/__init__.py +++ b/src/octoprint/plugins/announcements/__init__.py @@ -36,7 +36,6 @@ class AnnouncementPlugin( octoprint.plugin.TemplatePlugin, octoprint.plugin.EventHandlerPlugin, ): - # noinspection PyMissingConstructor def __init__(self): self._cached_channel_configs = None diff --git a/src/octoprint/plugins/backup/__init__.py b/src/octoprint/plugins/backup/__init__.py index 129e51859..a721aa7d0 100644 --- a/src/octoprint/plugins/backup/__init__.py +++ b/src/octoprint/plugins/backup/__init__.py @@ -60,7 +60,6 @@ class BackupPlugin( octoprint.plugin.StartupPlugin, octoprint.plugin.WizardPlugin, ): - _pip_caller = None _backup_in_progress = threading.Lock() @@ -168,7 +167,6 @@ class BackupPlugin( @no_firstrun_access @Permissions.PLUGIN_BACKUP_ACCESS.require(403) def create_backup(self): - data = flask.request.json exclude = data.get("exclude", []) filename = self._build_backup_filename(settings=self._settings) @@ -922,7 +920,6 @@ class BackupPlugin( ) with cls._backup_in_progress: - if name is None: name = cls._build_backup_filename(settings) @@ -971,7 +968,9 @@ class BackupPlugin( final_path = os.path.join(datafolder, name) own_folder = datafolder - defaults = [os.path.join(basedir, "config.yaml"),] + [ + defaults = [ + os.path.join(basedir, "config.yaml"), + ] + [ os.path.join(basedir, folder) for folder in default_settings["folder"].keys() ] @@ -1179,7 +1178,6 @@ class BackupPlugin( on_restore_start(path) try: - with zipfile.ZipFile(path, "r") as zip: # read metadata try: diff --git a/src/octoprint/plugins/corewizard/__init__.py b/src/octoprint/plugins/corewizard/__init__.py index 9a9f27c2c..6b94247c1 100644 --- a/src/octoprint/plugins/corewizard/__init__.py +++ b/src/octoprint/plugins/corewizard/__init__.py @@ -16,7 +16,6 @@ class CoreWizardPlugin( octoprint.plugin.BlueprintPlugin, Subwizards, ): - # ~~ TemplatePlugin API def get_template_configs(self): diff --git a/src/octoprint/plugins/discovery/__init__.py b/src/octoprint/plugins/discovery/__init__.py index 6e617bd78..62f07de93 100644 --- a/src/octoprint/plugins/discovery/__init__.py +++ b/src/octoprint/plugins/discovery/__init__.py @@ -42,7 +42,6 @@ class DiscoveryPlugin( octoprint.plugin.BlueprintPlugin, octoprint.plugin.SettingsPlugin, ): - ssdp_multicast_addr = "239.255.255.250" # IPv6: ff0X::c ssdp_multicast_port = 1900 @@ -688,7 +687,6 @@ class DiscoveryPlugin( ) class Request(BaseHTTPRequestHandler): - # noinspection PyMissingConstructor def __init__(self, request_text): self.rfile = BytesIO(request_text) diff --git a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js index 00d89cffc..5b49120f8 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js @@ -496,8 +496,8 @@ $(function () { }; self._configureContainerElement = function (containerElement) { - // Prevent the default browser action for the mouse wheel down event. The desired behavor is to have the - // gocde canvas pan on mouse down + drag, which happens. But if we don't prevent the default action, the browser + // Prevent the default browser action for the mouse wheel down event. The desired behavior is to have the + // gcode canvas pan on mouse down + drag, which happens. But if we don't prevent the default action, the browser // will also scroll the entire page. containerElement.mousedown(function (event) { // Middle mouse button diff --git a/src/octoprint/plugins/logging/__init__.py b/src/octoprint/plugins/logging/__init__.py index 5e3f2ec58..41f40e93d 100644 --- a/src/octoprint/plugins/logging/__init__.py +++ b/src/octoprint/plugins/logging/__init__.py @@ -23,7 +23,6 @@ class LoggingPlugin( octoprint.plugin.TemplatePlugin, octoprint.plugin.BlueprintPlugin, ): - # Additional permissions hook def get_additional_permissions(self): diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 52773ca10..f715ed19d 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -114,7 +114,6 @@ class PluginManagerPlugin( octoprint.plugin.BlueprintPlugin, octoprint.plugin.EventHandlerPlugin, ): - ARCHIVE_EXTENSIONS = (".zip", ".tar.gz", ".tgz", ".tar", ".gz", ".whl") PYTHON_EXTENSIONS = (".py",) JSON_EXTENSIONS = (".json",) @@ -1823,7 +1822,6 @@ class PluginManagerPlugin( additional_args = self._settings.get(["pip_args"]) if additional_args is not None: - inapplicable_arguments = self.__class__.PIP_INAPPLICABLE_ARGUMENTS.get( args[0], list() ) diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 41fd4bb0f..43886af01 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -231,7 +231,6 @@ class SoftwareUpdatePlugin( or self._configured_checks is None or self._check_overlays_stale ): - self._refresh_configured_checks = False overlays = self._get_check_overlays() @@ -934,7 +933,6 @@ class SoftwareUpdatePlugin( return 9 def on_settings_migrate(self, target, current=None): - if current is None or current < 6: # up until & including config version 5 we didn't set the method parameter for the octoprint check # configuration @@ -1657,7 +1655,6 @@ class SoftwareUpdatePlugin( continue for future in futures.as_completed(futures_to_result): - target, populated_check = futures_to_result[future] if future.exception() is not None: self._logger.error( @@ -2034,7 +2031,6 @@ class SoftwareUpdatePlugin( return to_be_updated, check_data def _update_worker(self, checks, check_targets, force): - restart_type = None credentials = self._settings.get(["credentials"], merged=True) diff --git a/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py b/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py index b9500eb2a..5dca8c85c 100644 --- a/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py +++ b/src/octoprint/plugins/softwareupdate/scripts/update-octoprint.py @@ -232,7 +232,7 @@ def _rescue_changes(git_executable, folder): ) ) - with open(patch, "wt", encoding="utf-8", errors="replace") as f: + with open(patch, "w", encoding="utf-8", errors="replace") as f: for line in stdout: f.write(line) diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index 7e6137a7d..8f70762ef 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -1817,7 +1817,7 @@ class VirtualPrinter: handle = None try: - handle = open(file, "wt", encoding="utf-8") + handle = open(file, "w", encoding="utf-8") except Exception: self._send("error writing to file") self._writingToSdHandle = handle @@ -2150,7 +2150,7 @@ class VirtualEEPROM: else: # no eeprom file, make new one with defaults data = self.get_default_settings() - with open(self._eeprom_file_path, "wt", encoding="utf-8") as eeprom_file: + with open(self._eeprom_file_path, "w", encoding="utf-8") as eeprom_file: eeprom_file.write(to_unicode(json.dumps(data))) return data @@ -2261,7 +2261,7 @@ class VirtualEEPROM: def save_settings(self): # M500 behind-the-scenes - with open(self._eeprom_file_path, "wt", encoding="utf-8") as eeprom_file: + with open(self._eeprom_file_path, "w", encoding="utf-8") as eeprom_file: eeprom_file.write(to_unicode(json.dumps(self._eeprom))) def read_settings(self): diff --git a/src/octoprint/printer/estimation.py b/src/octoprint/printer/estimation.py index 8aa16b135..7e6ce02eb 100644 --- a/src/octoprint/printer/estimation.py +++ b/src/octoprint/printer/estimation.py @@ -197,7 +197,6 @@ class PrintTimeEstimator: class TimeEstimationHelper: - STABLE_THRESHOLD = 0.1 STABLE_COUNTDOWN = 250 STABLE_ROLLING_WINDOW = 250 diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 72e9a2e6f..ebdfea124 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -360,7 +360,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): for name, hook in self._handle_connect_hooks.items(): try: if hook( - self, port=port, baudrate=baudrate, profile=profile, *args, **kwargs + self, *args, port=port, baudrate=baudrate, profile=profile, **kwargs ): self._logger.info(f"Connect signalled as handled by plugin {name}") return @@ -403,7 +403,6 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._firmware_info = None def get_transport(self, *args, **kwargs): - if self._comm is None: return None diff --git a/src/octoprint/schema/webcam/__init__.py b/src/octoprint/schema/webcam/__init__.py index d1c04895f..18a223dc0 100644 --- a/src/octoprint/schema/webcam/__init__.py +++ b/src/octoprint/schema/webcam/__init__.py @@ -15,7 +15,6 @@ class RatioEnum(str, Enum): @with_attrs_docs class WebcamCompatibility(BaseModel): - streamTimeout: int = 5 """The timeout of the stream in seconds""" @@ -43,7 +42,6 @@ class WebcamCompatibility(BaseModel): @with_attrs_docs class Webcam(BaseModel): - name: str """Identifier of this webcam""" diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index d90e17b76..57ec46362 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -2726,10 +2726,10 @@ class Server: permission = PluginOctoPrintPermission( permission_name(plugin_info.name, definition), description, + *roles_and_permissions, plugin=plugin_info.key, dangerous=dangerous, default_groups=default_groups, - *roles_and_permissions, ) setattr( octoprint.access.permissions.Permissions, @@ -2737,10 +2737,10 @@ class Server: PluginOctoPrintPermission( permission_name(plugin_info.name, definition), description, + *roles_and_permissions, plugin=plugin_info.key, dangerous=dangerous, default_groups=default_groups, - *roles_and_permissions, ), ) diff --git a/src/octoprint/server/api/languages.py b/src/octoprint/server/api/languages.py index 714f1229f..fef19f9bb 100644 --- a/src/octoprint/server/api/languages.py +++ b/src/octoprint/server/api/languages.py @@ -153,7 +153,6 @@ def uploadLanguagePack(): @no_firstrun_access @Permissions.SETTINGS.require(403) def deleteInstalledLanguagePack(locale, pack): - if pack == "_core": target_path = os.path.join(settings().getBaseFolder("translations"), locale) else: diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index 799a0f9d9..edb3625b7 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -274,7 +274,6 @@ class ReverseProxiedEnvironment: server=None, port=None, ): - # sensible defaults if header_prefix is None: header_prefix = ["x-script-name", "x-forwarded-prefix"] @@ -1720,7 +1719,6 @@ class PluginAssetResolver(flask_assets.FlaskResolver): class SettingsCheckUpdater(webassets.updater.BaseUpdater): - updater = "always" def __init__(self): diff --git a/src/octoprint/server/util/sockjs.py b/src/octoprint/server/util/sockjs.py index f6aa9a971..3140887d7 100644 --- a/src/octoprint/server/util/sockjs.py +++ b/src/octoprint/server/util/sockjs.py @@ -77,7 +77,6 @@ class PrinterStateConnection( LoginStatusListener, GroupChangeListener, ): - _event_permissions = { Events.USER_LOGGED_IN: [Permissions.ADMIN], Events.USER_LOGGED_OUT: [Permissions.ADMIN], diff --git a/src/octoprint/server/util/tornado.py b/src/octoprint/server/util/tornado.py index 0957fb577..b4be6a6d9 100644 --- a/src/octoprint/server/util/tornado.py +++ b/src/octoprint/server/util/tornado.py @@ -92,7 +92,6 @@ def fix_websocket_check_origin(): class RequestlessExceptionLoggingMixin(tornado.web.RequestHandler): - LOG_REQUEST = False def log_exception(self, typ, value, tb, *args, **kwargs): @@ -1616,7 +1615,6 @@ class SystemInfoBundleHandler(CorsSupportMixin, tornado.web.RequestHandler): class GlobalHeaderTransform(tornado.web.OutputTransform): - HEADERS = {} FORCED_HEADERS = {} REMOVED_HEADERS = [] diff --git a/src/octoprint/settings/__init__.py b/src/octoprint/settings/__init__.py index ad9cb51ca..4ca274dda 100644 --- a/src/octoprint/settings/__init__.py +++ b/src/octoprint/settings/__init__.py @@ -966,7 +966,6 @@ class Settings: self.remove_overlay(key) if deprecated is not None: - self._logger.debug( f"Marking all (recursive) paths in this overlay as deprecated: {overlay}" ) @@ -2114,7 +2113,7 @@ def _validate_folder(folder, create=True, check_writable=True, deep_check_writab # to determine whether things are *actually* writable testfile = os.path.join(folder, ".testballoon.txt") try: - with open(testfile, "wt", encoding="utf-8") as f: + with open(testfile, "w", encoding="utf-8") as f: f.write("test") os.remove(testfile) except Exception: diff --git a/src/octoprint/systemcommands/__init__.py b/src/octoprint/systemcommands/__init__.py index cf91b9db3..b281c329d 100644 --- a/src/octoprint/systemcommands/__init__.py +++ b/src/octoprint/systemcommands/__init__.py @@ -23,7 +23,6 @@ def system_command_manager(): class SystemCommandManager: - SERVER_RESTART_COMMAND = "serverRestartCommand" SYSTEM_RESTART_COMMAND = "systemRestartCommand" SYSTEM_SHUTDOWN_COMMAND = "systemShutdownCommand" diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py index 4d65e779f..04f51b26b 100644 --- a/src/octoprint/timelapse.py +++ b/src/octoprint/timelapse.py @@ -536,7 +536,7 @@ class Timelapse: eventManager().subscribe(Events.PRINT_FAILED, self.on_print_done) eventManager().subscribe(Events.PRINT_DONE, self.on_print_done) eventManager().subscribe(Events.PRINT_RESUMED, self.on_print_resumed) - for (event, callback) in self.event_subscriptions(): + for event, callback in self.event_subscriptions(): eventManager().subscribe(event, callback) @property @@ -560,7 +560,7 @@ class Timelapse: eventManager().unsubscribe(Events.PRINT_FAILED, self.on_print_done) eventManager().unsubscribe(Events.PRINT_DONE, self.on_print_done) eventManager().unsubscribe(Events.PRINT_RESUMED, self.on_print_resumed) - for (event, callback) in self.event_subscriptions(): + for event, callback in self.event_subscriptions(): eventManager().unsubscribe(event, callback) def on_print_started(self, event, payload): @@ -951,7 +951,6 @@ class TimedTimelapse(Timelapse): class TimelapseRenderJob: - render_job_lock = threading.RLock() def __init__( diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index 70f95865f..129b5498b 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -881,7 +881,6 @@ def dict_filter(dictionary, filter_function): # Source: http://stackoverflow.com/a/6190500/562769 class DefaultOrderedDict(collections.OrderedDict): def __init__(self, default_factory=None, *a, **kw): - if default_factory is not None and not callable(default_factory): raise TypeError("first argument must be callable") collections.OrderedDict.__init__(self, *a, **kw) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 44f00b56f..74ed974d2 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2717,7 +2717,6 @@ class MachineCom: or line.startswith("T0:") or ((" B:" in line or line.startswith("B:")) and "A:" not in line) ): - if ( not disable_external_heatup_detection and not self._temperature_autoreporting @@ -3052,7 +3051,6 @@ class MachineCom: else: self._consecutive_not_sd_printing = 0 if self.isSdFileSelected(): - # If we are not yet sd printing, the current does not equal the total, is larger # than zero and has increased since the last time we saw a position report, then # yes, this looks like we just started printing due to an external trigger. @@ -4488,7 +4486,7 @@ class MachineCom: enqueued_something = False # process all but the last ... - for (cmd, cmd_type, gcode, subcode, tags) in results: + for cmd, cmd_type, gcode, subcode, tags in results: enqueued_something = ( process(cmd, cmd_type, gcode, subcode, tags=tags) or enqueued_something diff --git a/src/octoprint/util/version.py b/src/octoprint/util/version.py index ad016e5d7..34ffa00bc 100644 --- a/src/octoprint/util/version.py +++ b/src/octoprint/util/version.py @@ -219,7 +219,6 @@ def is_prerelease(version): def normalize_version(version): - # Debian has the python version set to 2.7.15+ which is not PEP440 compliant (bug 914072) if version.endswith("+"): version = version[:-1] diff --git a/src/octoprint/util/yaml.py b/src/octoprint/util/yaml.py index d36f652c4..3b9a5561b 100644 --- a/src/octoprint/util/yaml.py +++ b/src/octoprint/util/yaml.py @@ -31,7 +31,7 @@ def load_from_file( def _save_to_file_base(data, file=None, path=None, pretty=False, **kwargs): if path is not None: assert file is None - with open(path, "wt", encoding="utf-8") as f: + with open(path, "w", encoding="utf-8") as f: return _save_to_file_base(data, file=f, pretty=pretty, **kwargs) if file is not None: diff --git a/tests/filemanager/test_localstorage.py b/tests/filemanager/test_localstorage.py index f825c8e67..97d226628 100644 --- a/tests/filemanager/test_localstorage.py +++ b/tests/filemanager/test_localstorage.py @@ -833,7 +833,7 @@ class LocalStorageTest(unittest.TestCase): # prepare import yaml - with open(yaml_path, "wt") as f: + with open(yaml_path, "w") as f: yaml.safe_dump(metadata, f) # migrate diff --git a/tests/settings/test_settings.py b/tests/settings/test_settings.py index c8942cc95..101000a88 100644 --- a/tests/settings/test_settings.py +++ b/tests/settings/test_settings.py @@ -34,7 +34,7 @@ def _load_yaml(fname): def _dump_yaml(fname, config): - with open(fname, "wt", encoding="utf-8") as f: + with open(fname, "w", encoding="utf-8") as f: yaml.safe_dump(config, f) diff --git a/tests/test_daemon.py b/tests/test_daemon.py index d5a35d0c8..65948853f 100644 --- a/tests/test_daemon.py +++ b/tests/test_daemon.py @@ -10,7 +10,6 @@ class ExpectedExit(BaseException): class DaemonTest(unittest.TestCase): def setUp(self): - run_method = mock.MagicMock() echo_method = mock.MagicMock() error_method = mock.MagicMock() @@ -19,10 +18,10 @@ class DaemonTest(unittest.TestCase): def run(self): run_method() - def echo(cls, line): + def echo(self, line): echo_method(line) - def error(cls, line): + def error(self, line): error_method(line) self.pidfile = "/my/pid/file" @@ -132,8 +131,8 @@ class DaemonTest(unittest.TestCase): mock_open.mock_calls, [ mock.call(mock_devnull, encoding="utf-8"), - mock.call(mock_devnull, "at+", encoding="utf-8"), - mock.call(mock_devnull, "at+", encoding="utf-8"), + mock.call(mock_devnull, "a+", encoding="utf-8"), + mock.call(mock_devnull, "a+", encoding="utf-8"), ], ) self.assertListEqual( @@ -448,7 +447,7 @@ class DaemonTest(unittest.TestCase): self.daemon.set_pid(pid) # assert - m.assert_called_once_with(self.pidfile, "wt+", encoding="utf-8") + m.assert_called_once_with(self.pidfile, "w+", encoding="utf-8") handle = m() handle.write.assert_called_once_with(f"{pid}\n") @@ -461,7 +460,7 @@ class DaemonTest(unittest.TestCase): self.daemon.set_pid(pid) # assert - m.assert_called_once_with(self.pidfile, "wt+", encoding="utf-8") + m.assert_called_once_with(self.pidfile, "w+", encoding="utf-8") handle = m() handle.write.assert_called_once_with(f"{pid}\n") diff --git a/tests/timelapse/test_timelapse_helpers.py b/tests/timelapse/test_timelapse_helpers.py index 1129dbb38..c9c96c14c 100644 --- a/tests/timelapse/test_timelapse_helpers.py +++ b/tests/timelapse/test_timelapse_helpers.py @@ -129,7 +129,6 @@ class TimelapseTest(unittest.TestCase): @mock.patch("os.scandir") def test_get_finished_timelapses(self, mock_listdir): - ## prepare mocked_path = "/path/to/timelapse" @@ -215,7 +214,6 @@ class TimelapseTest(unittest.TestCase): return result def test_ffmpeg_parse(self): - # Test strings noChange1Str = " built on Jan 7 2014 22:07:02 with gcc 4.8.2 (GCC)" durationStr = ( diff --git a/tests/util/test_file_helpers.py b/tests/util/test_file_helpers.py index 4e1e2881c..c776601d3 100644 --- a/tests/util/test_file_helpers.py +++ b/tests/util/test_file_helpers.py @@ -548,7 +548,7 @@ class IsHiddenPathTest(unittest.TestCase): "path_always_hidden", ): path = getattr(self, attr) - with open(path, "wt+", encoding="utf-8") as f: + with open(path, "w+", encoding="utf-8") as f: f.write(attr) if sys.platform == "win32":