🎨 pyupgrade --py37-plus
This commit is contained in:
1 parent
a71f6fcd40
commit
fd2ece0f13
84 files changed
+511
-716
No files matched your search
@@ -3,7 +3,6 @@ __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agp
|
||||
__copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
import copy
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
@@ -705,7 +704,7 @@ class PluginManagerPlugin(
|
||||
|
||||
kind = filetype.guess(path)
|
||||
if kind:
|
||||
return ".{}".format(kind.extension) in PluginManagerPlugin.ARCHIVE_EXTENSIONS
|
||||
return f".{kind.extension}" in PluginManagerPlugin.ARCHIVE_EXTENSIONS
|
||||
return False
|
||||
|
||||
def _is_pythonfile(self, path):
|
||||
@@ -714,13 +713,11 @@ class PluginManagerPlugin(
|
||||
import ast
|
||||
|
||||
try:
|
||||
with io.open(path, "rb") as f:
|
||||
with open(path, "rb") as f:
|
||||
ast.parse(f.read(), filename=path)
|
||||
return True
|
||||
except Exception as exc:
|
||||
self._logger.exception(
|
||||
"Could not parse {} as python file: {}".format(path, exc)
|
||||
)
|
||||
self._logger.exception(f"Could not parse {path} as python file: {exc}")
|
||||
|
||||
return False
|
||||
|
||||
@@ -767,12 +764,12 @@ class PluginManagerPlugin(
|
||||
raise exceptions.InvalidPackageFormat()
|
||||
|
||||
except requests.exceptions.HTTPError as e:
|
||||
self._logger.error("Could not fetch plugin from server, got {}".format(e))
|
||||
self._logger.error(f"Could not fetch plugin from server, got {e}")
|
||||
result = {
|
||||
"result": False,
|
||||
"source": source,
|
||||
"source_type": source_type,
|
||||
"reason": "Could not fetch plugin from server, got {}".format(e),
|
||||
"reason": f"Could not fetch plugin from server, got {e}",
|
||||
}
|
||||
self._send_result_notification("install", result)
|
||||
|
||||
@@ -863,7 +860,7 @@ class PluginManagerPlugin(
|
||||
lambda line: path_url in line.lower()
|
||||
) # lower case in case of windows
|
||||
|
||||
self._logger.info("Installing plugin from {}".format(source))
|
||||
self._logger.info(f"Installing plugin from {source}")
|
||||
pip_args = [
|
||||
"--disable-pip-version-check",
|
||||
"install",
|
||||
@@ -909,7 +906,7 @@ class PluginManagerPlugin(
|
||||
)
|
||||
force = True
|
||||
except Exception as e:
|
||||
self._logger.exception("Could not install plugin from {}".format(source))
|
||||
self._logger.exception(f"Could not install plugin from {source}")
|
||||
self._logger.exception("Reason: {}".format(repr(e)))
|
||||
result = {
|
||||
"result": False,
|
||||
@@ -930,9 +927,7 @@ class PluginManagerPlugin(
|
||||
try:
|
||||
returncode, stdout, stderr = self._call_pip(pip_args)
|
||||
except Exception as e:
|
||||
self._logger.exception(
|
||||
"Could not install plugin from {}".format(source)
|
||||
)
|
||||
self._logger.exception(f"Could not install plugin from {source}")
|
||||
self._logger.exception("Reason: {}".format(repr(e)))
|
||||
result = {
|
||||
"result": False,
|
||||
@@ -1092,7 +1087,7 @@ class PluginManagerPlugin(
|
||||
if name is None:
|
||||
name = os.path.basename(path)
|
||||
|
||||
self._logger.info("Installing single file plugin {} from {}".format(name, source))
|
||||
self._logger.info(f"Installing single file plugin {name} from {source}")
|
||||
|
||||
all_plugins_before = self._plugin_manager.find_plugins(existing={})
|
||||
|
||||
@@ -1100,10 +1095,10 @@ class PluginManagerPlugin(
|
||||
plugin_id, _ = os.path.splitext(name)
|
||||
|
||||
try:
|
||||
self._log_call("cp {} {}".format(path, destination))
|
||||
self._log_call(f"cp {path} {destination}")
|
||||
shutil.copy(path, destination)
|
||||
except Exception:
|
||||
self._logger.exception("Installing plugin from {} failed".format(source))
|
||||
self._logger.exception(f"Installing plugin from {source} failed")
|
||||
result = {
|
||||
"result": False,
|
||||
"source": source,
|
||||
@@ -1221,22 +1216,16 @@ class PluginManagerPlugin(
|
||||
|
||||
if os.path.isdir(full_path):
|
||||
# plugin is installed via a plugin folder, need to use rmtree to get rid of it
|
||||
self._log_stdout(
|
||||
"Deleting plugin from {folder}".format(folder=plugin.location)
|
||||
)
|
||||
self._log_stdout(f"Deleting plugin from {plugin.location}")
|
||||
shutil.rmtree(full_path)
|
||||
elif os.path.isfile(full_path):
|
||||
self._log_stdout(
|
||||
"Deleting plugin from {file}".format(file=plugin.location)
|
||||
)
|
||||
self._log_stdout(f"Deleting plugin from {plugin.location}")
|
||||
os.remove(full_path)
|
||||
|
||||
if full_path.endswith(".py"):
|
||||
pyc_file = "{full_path}c".format(**locals())
|
||||
if os.path.isfile(pyc_file):
|
||||
self._log_stdout(
|
||||
"Deleting plugin from {file}".format(file=pyc_file)
|
||||
)
|
||||
self._log_stdout(f"Deleting plugin from {pyc_file}")
|
||||
os.remove(pyc_file)
|
||||
|
||||
else:
|
||||
@@ -1270,9 +1259,7 @@ class PluginManagerPlugin(
|
||||
if plugin.enabled:
|
||||
self._plugin_manager.disable_plugin(plugin.key, plugin=plugin)
|
||||
except octoprint.plugin.core.PluginLifecycleException as e:
|
||||
self._logger.exception(
|
||||
"Problem disabling plugin {name}".format(name=plugin.key)
|
||||
)
|
||||
self._logger.exception(f"Problem disabling plugin {plugin.key}")
|
||||
result = {
|
||||
"result": False,
|
||||
"uninstalled": True,
|
||||
@@ -1287,9 +1274,7 @@ class PluginManagerPlugin(
|
||||
if plugin.loaded:
|
||||
self._plugin_manager.unload_plugin(plugin.key)
|
||||
except octoprint.plugin.core.PluginLifecycleException as e:
|
||||
self._logger.exception(
|
||||
"Problem unloading plugin {name}".format(name=plugin.key)
|
||||
)
|
||||
self._logger.exception(f"Problem unloading plugin {plugin.key}")
|
||||
result = {
|
||||
"result": False,
|
||||
"uninstalled": True,
|
||||
@@ -1316,7 +1301,7 @@ class PluginManagerPlugin(
|
||||
"plugin": self._to_external_plugin(plugin),
|
||||
}
|
||||
self._send_result_notification("uninstall", result)
|
||||
self._logger.info("Plugin {} uninstalled".format(plugin.key))
|
||||
self._logger.info(f"Plugin {plugin.key} uninstalled")
|
||||
|
||||
self._cleanup_disabled(plugin.key)
|
||||
if cleanup:
|
||||
@@ -1337,7 +1322,7 @@ class PluginManagerPlugin(
|
||||
key = plugin.key
|
||||
result_value = self._to_external_plugin(plugin)
|
||||
|
||||
message = "Cleaning up plugin {}...".format(key)
|
||||
message = f"Cleaning up plugin {key}..."
|
||||
self._logger.info(message)
|
||||
self._log_stdout(message)
|
||||
|
||||
@@ -1351,7 +1336,7 @@ class PluginManagerPlugin(
|
||||
# delete plugin data folder
|
||||
result_data = True
|
||||
if not self._cleanup_data(key):
|
||||
message = "Could not delete data folder of plugin {}".format(key)
|
||||
message = f"Could not delete data folder of plugin {key}"
|
||||
self._logger.exception(message)
|
||||
self._log_stderr(message)
|
||||
result_data = False
|
||||
@@ -1425,7 +1410,7 @@ class PluginManagerPlugin(
|
||||
return True
|
||||
except Exception:
|
||||
self._logger.exception(
|
||||
"Could not delete plugin data folder at {}".format(data_folder)
|
||||
f"Could not delete plugin data folder at {data_folder}"
|
||||
)
|
||||
return False
|
||||
else:
|
||||
@@ -1679,9 +1664,7 @@ class PluginManagerPlugin(
|
||||
try:
|
||||
import json
|
||||
|
||||
with io.open(
|
||||
self._repository_cache_path, "rt", encoding="utf-8"
|
||||
) as f:
|
||||
with open(self._repository_cache_path, encoding="utf-8") as f:
|
||||
repo_data = json.load(f)
|
||||
self._repository_mtime = mtime
|
||||
self._logger.info(
|
||||
@@ -1707,9 +1690,7 @@ class PluginManagerPlugin(
|
||||
try:
|
||||
r = requests.get(repository_url, timeout=30)
|
||||
r.raise_for_status()
|
||||
self._logger.info(
|
||||
"Loaded plugin repository data from {}".format(repository_url)
|
||||
)
|
||||
self._logger.info(f"Loaded plugin repository data from {repository_url}")
|
||||
except Exception as e:
|
||||
self._logger.exception(
|
||||
"Could not fetch plugins from repository at {repository_url}: {message}".format(
|
||||
@@ -1721,13 +1702,13 @@ class PluginManagerPlugin(
|
||||
try:
|
||||
repo_data = r.json()
|
||||
except Exception as e:
|
||||
self._logger.exception("Error while reading repository data: {}".format(e))
|
||||
self._logger.exception(f"Error while reading repository data: {e}")
|
||||
return None
|
||||
|
||||
# validation
|
||||
if not isinstance(repo_data, (list, tuple)):
|
||||
self._logger.warning(
|
||||
"Invalid repository data: expected a list, got {!r}".format(repo_data)
|
||||
f"Invalid repository data: expected a list, got {repo_data!r}"
|
||||
)
|
||||
return None
|
||||
|
||||
@@ -1774,7 +1755,7 @@ class PluginManagerPlugin(
|
||||
try:
|
||||
import json
|
||||
|
||||
with io.open(self._notices_cache_path, "rt", encoding="utf-8") as f:
|
||||
with open(self._notices_cache_path, encoding="utf-8") as f:
|
||||
notice_data = json.load(f)
|
||||
self._notices_mtime = mtime
|
||||
self._logger.info("Loaded notice data from disk, was still valid")
|
||||
@@ -1798,7 +1779,7 @@ class PluginManagerPlugin(
|
||||
try:
|
||||
r = requests.get(notices_url, timeout=30)
|
||||
r.raise_for_status()
|
||||
self._logger.info("Loaded plugin notices data from {}".format(notices_url))
|
||||
self._logger.info(f"Loaded plugin notices data from {notices_url}")
|
||||
except Exception as e:
|
||||
self._logger.exception(
|
||||
"Could not fetch notices from {notices_url}: {message}".format(
|
||||
|
||||
Reference in new issue
Block a user