From acb9e092935b61c301474c27547889c79bce278d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= <6774676+eumiro@users.noreply.github.com> Date: Thu, 21 Jan 2021 19:37:19 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=95=20Remove=20redundant=20float=20con?= =?UTF-8?q?versions=20from=20Python2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we import division from __future__, the division behaves the same in Python 2.7 and 3.x --- AUTHORS.md | 1 + src/octoprint/filemanager/storage.py | 2 +- .../plugins/virtual_printer/virtual.py | 26 +++++++++---------- src/octoprint/printer/profile.py | 4 +-- src/octoprint/printer/standard.py | 6 ++--- src/octoprint/server/util/tornado.py | 2 +- src/octoprint/timelapse.py | 2 +- src/octoprint/util/__init__.py | 8 +++--- src/octoprint/util/comm.py | 12 ++++----- src/octoprint/util/gcodeInterpreter.py | 12 ++++----- .../vendor/sockjs/tornado/periodic.py | 2 +- src/octoprint/vendor/sockjs/tornado/stats.py | 2 +- src/octoprint/vendor/zeroconf.py | 4 +-- tests/timelapse/test_timelapse_helpers.py | 4 +-- 14 files changed, 44 insertions(+), 43 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 87aeb9db3..97c7d96cb 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -131,6 +131,7 @@ date of first contribution): * [Manuel McLure](https://github.com/ManuelMcLure) * ["j7126"](https://github.com/j7126) * ["coliss86"](https://github.com/coliss86) + * [Miroslav Šedivý](https://github.com/eumiro) 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/filemanager/storage.py b/src/octoprint/filemanager/storage.py index b84218884..76c7afbf2 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -1376,7 +1376,7 @@ class LocalFileStorage(StorageInterface): continue statistics["averagePrintTime"][printer_profile] = sum( former_print_times[printer_profile] - ) / float(len(former_print_times[printer_profile])) + ) / len(former_print_times[printer_profile]) for printer_profile in last_print: if not last_print[printer_profile]: diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index 486d1a605..d2741b8c7 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -809,7 +809,7 @@ class VirtualPrinter(object): # noinspection PyUnusedLocal def _gcode_G20(self, data): # type: (str) -> None - self._unitModifier = 1.0 / 2.54 + self._unitModifier = 1 / 2.54 if self._lastX is not None: self._lastX *= 2.54 if self._lastY is not None: @@ -866,7 +866,7 @@ class VirtualPrinter(object): _timeout = 0 if matchP: - _timeout = float(matchP.group(1)) / 1000.0 + _timeout = float(matchP.group(1)) / 1000 elif matchS: _timeout = float(matchS.group(1)) @@ -1639,8 +1639,8 @@ class VirtualPrinter(object): except ValueError: pass - speedXYZ = self._lastF * (self._feedrate_multiplier / 100.0) - speedE = self._lastF * (self._flowrate_multiplier / 100.0) + speedXYZ = self._lastF * (self._feedrate_multiplier / 100) + speedE = self._lastF * (self._flowrate_multiplier / 100) if speedXYZ == 0: speedXYZ = 999999999999 if speedE == 0: @@ -1653,10 +1653,10 @@ class VirtualPrinter(object): pass else: if self._relative or self._lastX is None: - duration = max(duration, x * self._unitModifier / speedXYZ * 60.0) + duration = max(duration, x * self._unitModifier / speedXYZ * 60) else: duration = max( - duration, (x - self._lastX) * self._unitModifier / speedXYZ * 60.0 + duration, (x - self._lastX) * self._unitModifier / speedXYZ * 60 ) if self._relative and self._lastX is not None: @@ -1670,10 +1670,10 @@ class VirtualPrinter(object): pass else: if self._relative or self._lastY is None: - duration = max(duration, y * self._unitModifier / speedXYZ * 60.0) + duration = max(duration, y * self._unitModifier / speedXYZ * 60) else: duration = max( - duration, (y - self._lastY) * self._unitModifier / speedXYZ * 60.0 + duration, (y - self._lastY) * self._unitModifier / speedXYZ * 60 ) if self._relative and self._lastY is not None: @@ -1687,10 +1687,10 @@ class VirtualPrinter(object): pass else: if self._relative or self._lastZ is None: - duration = max(duration, z * self._unitModifier / speedXYZ * 60.0) + duration = max(duration, z * self._unitModifier / speedXYZ * 60) else: duration = max( - duration, (z - self._lastZ) * self._unitModifier / speedXYZ * 60.0 + duration, (z - self._lastZ) * self._unitModifier / speedXYZ * 60 ) if self._relative and self._lastZ is not None: @@ -1705,10 +1705,10 @@ class VirtualPrinter(object): else: lastE = self._lastE[self.currentExtruder] if self._relative or lastE is None: - duration = max(duration, e * self._unitModifier / speedE * 60.0) + duration = max(duration, e * self._unitModifier / speedE * 60) else: duration = max( - duration, (e - lastE) * self._unitModifier / speedE * 60.0 + duration, (e - lastE) * self._unitModifier / speedE * 60 ) if self._relative and lastE is not None: @@ -2295,7 +2295,7 @@ class CharCountingQueue(queue.Queue): endtime = monotonic_time() + timeout while not self._will_it_fit(item): remaining = endtime - monotonic_time() - if remaining <= 0.0: + if remaining <= 0: raise queue.Full self.not_full.wait(remaining) diff --git a/src/octoprint/printer/profile.py b/src/octoprint/printer/profile.py index d4261f6fe..c826df750 100644 --- a/src/octoprint/printer/profile.py +++ b/src/octoprint/printer/profile.py @@ -796,8 +796,8 @@ class PrinterProfileManager(object): @staticmethod def _default_box_for_volume(volume): if volume["origin"] == BedOrigin.CENTER: - half_width = volume["width"] / 2.0 - half_depth = volume["depth"] / 2.0 + half_width = volume["width"] / 2 + half_depth = volume["depth"] / 2 return { "x_min": -half_width, "x_max": half_width, diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index dac3d0a38..b6df58242 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -611,7 +611,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): raise ValueError("factor is not a number") if isinstance(factor, float): - factor = int(factor * 100.0) + factor = int(factor * 100) if min_val and factor < min_val: raise ValueError("factor must be a value >={}".format(min_val)) @@ -1107,7 +1107,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): if progress == 0: printTimeLeft = None printTimeLeftOrigin = None - elif progress == 1.0: + elif progress == 1: printTimeLeft = 0 printTimeLeftOrigin = None elif estimator is not None: @@ -1153,7 +1153,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): return self._dict( count=self._comm.received_resends, transmitted=self._comm.transmitted_lines, - ratio=int(self._comm.resend_ratio * 100.0), + ratio=int(self._comm.resend_ratio * 100), ) def _addTemperatureData(self, tools=None, bed=None, chamber=None, custom=None): diff --git a/src/octoprint/server/util/tornado.py b/src/octoprint/server/util/tornado.py index 121d6fe2a..f0744ca20 100644 --- a/src/octoprint/server/util/tornado.py +++ b/src/octoprint/server/util/tornado.py @@ -814,7 +814,7 @@ class WsgiInputContainer(object): log_method = access_log.warning else: log_method = access_log.error - request_time = 1000.0 * request.request_time() + request_time = 1000 * request.request_time() summary = request.method + " " + request.uri + " (" + request.remote_ip + ")" log_method("%d %s %.2fms", status_code, summary, request_time) diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py index ce32d3efa..60bf3b5c2 100644 --- a/src/octoprint/timelapse.py +++ b/src/octoprint/timelapse.py @@ -1097,7 +1097,7 @@ class TimelapseRenderJob(object): current_time = _ffmpeg_current_regex.search(line) if current_time is not None and self._parsed_duration != 0: current_s = self._convert_time(*current_time.groups()) - progress = current_s / float(self._parsed_duration) * 100 + progress = current_s / self._parsed_duration * 100 # Update progress bar for callback in _update_callbacks: diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index f28f1bff5..0c052da28 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -347,9 +347,9 @@ def get_formatted_size(num): """ for x in ["B", "KB", "MB", "GB"]: - if num < 1024.0: + if num < 1024: return "%3.1f%s" % (num, x) - num /= 1024.0 + num /= 1024 return "%3.1f%s" % (num, "TB") @@ -1760,7 +1760,7 @@ class PrependableQueue(queue.Queue): endtime = _time() + timeout while self._qsize() == self.maxsize: remaining = endtime - _time() - if remaining <= 0.0: + if remaining <= 0: raise queue.Full self.not_full.wait(remaining) self._prepend(item) @@ -1889,7 +1889,7 @@ def time_this( try: return f(*args, **kwargs) finally: - timing = (time.time() - start) * 1000.0 + timing = (time.time() - start) * 1000 func = fqfn(f) lt = logtarget diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 9bd20c757..a16607834 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -666,7 +666,7 @@ class MachineCom(object): self._received_resend_requests = 0 self._resend_ratio_start = settings().getInt(["serial", "resendRatioStart"]) self._resend_ratio_threshold = ( - settings().getInt(["serial", "resendRatioThreshold"]) / 100.0 + settings().getInt(["serial", "resendRatioThreshold"]) / 100 ) self._resend_ratio_reported = False @@ -4749,7 +4749,7 @@ class MachineCom(object): # may be busy, so give things a little time before we try again. Extend this # period each time we fail until either we write the data or run out of retry attempts. if passes > 1: - time.sleep((passes - 1) / 10.0) + time.sleep((passes - 1) / 10) self._transmitted_lines += 1 @@ -5168,7 +5168,7 @@ class MachineCom(object): _timeout = 0 if p_match: - _timeout = float(p_match.group("value")) / 1000.0 + _timeout = float(p_match.group("value")) / 1000 elif s_match: _timeout = float(s_match.group("value")) @@ -5399,7 +5399,7 @@ class PrintingFileInformation(object): """ if self._size is None or not self._size > 0: return -1 - return float(self._pos) / float(self._size) + return self._pos / self._size def reset(self): """ @@ -5608,8 +5608,8 @@ class StreamingGcodeFileInformation(PrintingGcodeFileInformation): if duration > 0 and read_lines > 0: stats = { "lines": read_lines, - "rate": float(read_lines) / duration, - "time_per_line": duration * 1000.0 / float(read_lines), + "rate": read_lines / duration, + "time_per_line": duration * 1000 / read_lines, "duration": duration, } self._logger.info( diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index d8ece15dc..026be5f96 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -282,9 +282,9 @@ class gcode(object): readBytes += len(line.encode("utf-8")) if isinstance(gcodeFile, (io.IOBase, codecs.StreamReaderWriter)): - percentage = float(readBytes) / float(self._fileSize) + percentage = readBytes / self._fileSize elif isinstance(gcodeFile, (list)): - percentage = float(lineNo) / float(len(gcodeFile)) + percentage = lineNo / len(gcodeFile) else: percentage = None @@ -387,7 +387,7 @@ class gcode(object): e -= currentE[currentExtruder] # If move with extrusion, calculate new min/max coordinates of model - if e > 0.0 and move: + if e > 0 and move: # extrusion and move -> oldPos & pos relevant for print area & dimensions self._minMax.record(oldPos) self._minMax.record(pos) @@ -405,7 +405,7 @@ class gcode(object): currentE[i] += e maxExtrusion[i] = max(maxExtrusion[i], totalExtrusion[i]) else: - e = 0.0 + e = 0 # move time in x, y, z, will be 0 if no movement happened moveTimeXYZ = abs((oldPos - pos).length / feedrate) @@ -419,10 +419,10 @@ class gcode(object): elif G == 4: # Delay S = getCodeFloat(line, "S") if S is not None: - totalMoveTimeMinute += S / 60.0 + totalMoveTimeMinute += S / 60 P = getCodeFloat(line, "P") if P is not None: - totalMoveTimeMinute += P / 60.0 / 1000.0 + totalMoveTimeMinute += P / 60 / 1000 elif G == 10: # Firmware retract totalMoveTimeMinute += fwretractTime elif G == 11: # Firmware retract recover diff --git a/src/octoprint/vendor/sockjs/tornado/periodic.py b/src/octoprint/vendor/sockjs/tornado/periodic.py index 77c92c099..35dc85354 100644 --- a/src/octoprint/vendor/sockjs/tornado/periodic.py +++ b/src/octoprint/vendor/sockjs/tornado/periodic.py @@ -37,7 +37,7 @@ class Callback(object): def calculate_next_run(self): """Caltulate next scheduled run""" - return time.time() + self.callback_time / 1000.0 + return time.time() + self.callback_time / 1000 def start(self, timeout=None): """Start callbacks""" diff --git a/src/octoprint/vendor/sockjs/tornado/stats.py b/src/octoprint/vendor/sockjs/tornado/stats.py index f256e7e3b..536ebd7a3 100644 --- a/src/octoprint/vendor/sockjs/tornado/stats.py +++ b/src/octoprint/vendor/sockjs/tornado/stats.py @@ -50,7 +50,7 @@ class MovingAverage(object): if streamlen == 0: self.last_average = 0 else: - self.last_average = self.sum / float(streamlen) + self.last_average = self.sum / streamlen class StatsCollector(object): diff --git a/src/octoprint/vendor/zeroconf.py b/src/octoprint/vendor/zeroconf.py index 647d1852a..3f710983f 100644 --- a/src/octoprint/vendor/zeroconf.py +++ b/src/octoprint/vendor/zeroconf.py @@ -453,7 +453,7 @@ class DNSRecord(DNSEntry): def get_remaining_ttl(self, now): """Returns the remaining TTL in seconds.""" - return max(0, (self._expiration_time - now) / 1000.0) + return max(0, (self._expiration_time - now) / 1000) def is_expired(self, now): """Returns true if this record has expired.""" @@ -1820,7 +1820,7 @@ class Zeroconf(QuietLogger): """Calling thread waits for a given number of milliseconds or until notified.""" with self.condition: - self.condition.wait(timeout / 1000.0) + self.condition.wait(timeout / 1000) def notify_all(self): """Notifies all waiting threads""" diff --git a/tests/timelapse/test_timelapse_helpers.py b/tests/timelapse/test_timelapse_helpers.py index 9e39b7d98..e1893ab72 100644 --- a/tests/timelapse/test_timelapse_helpers.py +++ b/tests/timelapse/test_timelapse_helpers.py @@ -233,9 +233,9 @@ class TimelapseTest(unittest.TestCase): "0: Video: mpeg2video, yuv420p, 640x480, q=2-31, 10000 kb/s, 90k tbn, 25 tbc" ) progress1Str = "frame= 134 fps=0.0 q=1.6 size= 1528kB time=00:00:05.28 bitrate=2370.7kbits/s dup=80 drop=0 " # 5s elapsed - expectedProgress1 = 5.0 / 18.0 * 100.0 + expectedProgress1 = 5 / 18 * 100 progress2Str = "frame= 274 fps=270 q=2.0 size= 2748kB time=00:00:10.88 bitrate=2069.1kbits/s dup=164 drop=0 " # 10s elapsed - expectedProgress2 = 10.0 / 18.0 * 100.0 + expectedProgress2 = 10 / 18 * 100 # Callback mock callback = mock.MagicMock()