From bf08e2916245d9299734aeef9d78546c899a9314 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Fri, 30 Apr 2021 11:38:23 -0700 Subject: [PATCH] Fix flake8 warnings in desktop --- desktop/package/linux/build-appimage.py | 2 +- desktop/package/windows/build.py | 2 +- desktop/scripts/get-tor-osx.py | 1 - desktop/scripts/get-tor-windows.py | 5 ++-- desktop/src/onionshare/__init__.py | 1 - desktop/src/onionshare/tab/mode/__init__.py | 4 +-- .../onionshare/tab/mode/chat_mode/__init__.py | 6 ---- desktop/src/onionshare/tab/mode/history.py | 2 +- .../tab/mode/mode_settings_widget.py | 2 +- .../tab/mode/share_mode/__init__.py | 3 +- .../onionshare/tab/mode/share_mode/threads.py | 2 +- .../tab/mode/website_mode/__init__.py | 5 +--- desktop/src/onionshare/tab/server_status.py | 2 +- desktop/src/onionshare/threads.py | 2 +- .../src/onionshare/tor_connection_dialog.py | 2 +- desktop/src/onionshare/update_checker.py | 3 +- desktop/src/setup.py | 7 ++++- desktop/tests/conftest.py | 28 +++++++++---------- 18 files changed, 35 insertions(+), 44 deletions(-) diff --git a/desktop/package/linux/build-appimage.py b/desktop/package/linux/build-appimage.py index 0c64494f..dfaba1b4 100755 --- a/desktop/package/linux/build-appimage.py +++ b/desktop/package/linux/build-appimage.py @@ -43,4 +43,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/desktop/package/windows/build.py b/desktop/package/windows/build.py index 603b1514..5fc796d4 100644 --- a/desktop/package/windows/build.py +++ b/desktop/package/windows/build.py @@ -211,7 +211,7 @@ def main(): ] print(f"○ Created unsigned installer: {msi_filename}") - print(f"○ Signing installer") + print("○ Signing installer") run( [ "signtool.exe", diff --git a/desktop/scripts/get-tor-osx.py b/desktop/scripts/get-tor-osx.py index f3aa6e7b..76c7a5fe 100755 --- a/desktop/scripts/get-tor-osx.py +++ b/desktop/scripts/get-tor-osx.py @@ -24,7 +24,6 @@ This script downloads a pre-built tor binary to bundle with OnionShare. In order to avoid a Mac gnupg dependency, I manually verify the signature and hard-code the sha256 hash. """ - import inspect import os import sys diff --git a/desktop/scripts/get-tor-windows.py b/desktop/scripts/get-tor-windows.py index 9cb8898c..87080c4a 100644 --- a/desktop/scripts/get-tor-windows.py +++ b/desktop/scripts/get-tor-windows.py @@ -23,7 +23,6 @@ This script downloads a pre-built tor binary to bundle with OnionShare. In order to avoid a Windows gnupg dependency, I manually verify the signature and hard-code the sha256 hash. """ - import inspect import os import sys @@ -75,7 +74,7 @@ def main(): "e", "-y", exe_path, - "Browser\TorBrowser\Tor", + "Browser\\TorBrowser\\Tor", "-o%s" % os.path.join(working_path, "Tor"), ] ).wait() @@ -85,7 +84,7 @@ def main(): "e", "-y", exe_path, - "Browser\TorBrowser\Data\Tor\geoip*", + "Browser\\TorBrowser\\Data\\Tor\\geoip*", "-o%s" % os.path.join(working_path, "Data"), ] ).wait() diff --git a/desktop/src/onionshare/__init__.py b/desktop/src/onionshare/__init__.py index 1c69ffa5..8276dae4 100644 --- a/desktop/src/onionshare/__init__.py +++ b/desktop/src/onionshare/__init__.py @@ -21,7 +21,6 @@ along with this program. If not, see . from __future__ import division import os import sys -import platform import argparse import signal import json diff --git a/desktop/src/onionshare/tab/mode/__init__.py b/desktop/src/onionshare/tab/mode/__init__.py index 9cd8fe81..fe7d6615 100644 --- a/desktop/src/onionshare/tab/mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/__init__.py @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -from PySide2 import QtCore, QtWidgets, QtGui +from PySide2 import QtCore, QtWidgets from onionshare_cli.common import AutoStopTimer @@ -379,7 +379,7 @@ class Mode(QtWidgets.QWidget): if self.server_status.status != ServerStatus.STATUS_STOPPED: try: self.web.stop(self.app.port) - except: + except Exception: # Probably we had no port to begin with (Onion service didn't start) pass self.app.cleanup() diff --git a/desktop/src/onionshare/tab/mode/chat_mode/__init__.py b/desktop/src/onionshare/tab/mode/chat_mode/__init__.py index 44a6d240..7f32aebb 100644 --- a/desktop/src/onionshare/tab/mode/chat_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/chat_mode/__init__.py @@ -18,14 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import os -import random -import string - from PySide2 import QtCore, QtWidgets, QtGui -from onionshare_cli.onion import * -from onionshare_cli.common import Common from onionshare_cli.web import Web from .. import Mode diff --git a/desktop/src/onionshare/tab/mode/history.py b/desktop/src/onionshare/tab/mode/history.py index 45e37c75..10606c85 100644 --- a/desktop/src/onionshare/tab/mode/history.py +++ b/desktop/src/onionshare/tab/mode/history.py @@ -253,7 +253,7 @@ class ReceiveHistoryItemFile(QtWidgets.QWidget): try: # If nautilus is available, open it subprocess.Popen(["xdg-open", self.dir]) - except: + except Exception: Alert( self.common, strings._("gui_open_folder_error").format(abs_filename), diff --git a/desktop/src/onionshare/tab/mode/mode_settings_widget.py b/desktop/src/onionshare/tab/mode/mode_settings_widget.py index ef59f37e..98a6a01a 100644 --- a/desktop/src/onionshare/tab/mode/mode_settings_widget.py +++ b/desktop/src/onionshare/tab/mode/mode_settings_widget.py @@ -234,7 +234,7 @@ class ModeSettingsWidget(QtWidgets.QWidget): self.tab.change_title.emit( self.tab.tab_id, strings._("gui_tab_name_chat") ) - elif self.tab_mode == None: + elif self.tab_mode is None: pass else: title = self.title_lineedit.text() diff --git a/desktop/src/onionshare/tab/mode/share_mode/__init__.py b/desktop/src/onionshare/tab/mode/share_mode/__init__.py index 05038e20..676d34af 100644 --- a/desktop/src/onionshare/tab/mode/share_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/share_mode/__init__.py @@ -21,7 +21,6 @@ along with this program. If not, see . import os from PySide2 import QtCore, QtWidgets, QtGui -from onionshare_cli.onion import * from onionshare_cli.common import Common from onionshare_cli.web import Web @@ -30,7 +29,7 @@ from .. import Mode from ..file_selection import FileSelection from ..history import History, ToggleHistory, ShareHistoryItem from .... import strings -from ....widgets import Alert, MinimumWidthWidget +from ....widgets import MinimumWidthWidget from ....gui_common import GuiCommon diff --git a/desktop/src/onionshare/tab/mode/share_mode/threads.py b/desktop/src/onionshare/tab/mode/share_mode/threads.py index 6f5c44ea..74d5099a 100644 --- a/desktop/src/onionshare/tab/mode/share_mode/threads.py +++ b/desktop/src/onionshare/tab/mode/share_mode/threads.py @@ -36,7 +36,7 @@ class CompressThread(QtCore.QThread): # prepare files to share def set_processed_size(self, x): - if self.mode._zip_progress_bar != None: + if self.mode._zip_progress_bar is not None: self.mode._zip_progress_bar.update_processed_size_signal.emit(x) def run(self): diff --git a/desktop/src/onionshare/tab/mode/website_mode/__init__.py b/desktop/src/onionshare/tab/mode/website_mode/__init__.py index f7cfa758..10caff51 100644 --- a/desktop/src/onionshare/tab/mode/website_mode/__init__.py +++ b/desktop/src/onionshare/tab/mode/website_mode/__init__.py @@ -19,12 +19,9 @@ along with this program. If not, see . """ import os -import random -import string from PySide2 import QtCore, QtWidgets, QtGui -from onionshare_cli.onion import * from onionshare_cli.common import Common from onionshare_cli.web import Web @@ -32,7 +29,7 @@ from .. import Mode from ..file_selection import FileSelection from ..history import History, ToggleHistory from .... import strings -from ....widgets import Alert, MinimumWidthWidget +from ....widgets import MinimumWidthWidget from ....gui_common import GuiCommon diff --git a/desktop/src/onionshare/tab/server_status.py b/desktop/src/onionshare/tab/server_status.py index d8266820..7ca1af09 100644 --- a/desktop/src/onionshare/tab/server_status.py +++ b/desktop/src/onionshare/tab/server_status.py @@ -161,7 +161,7 @@ class ServerStatus(QtWidgets.QWidget): self.url.setText(wrapped_onion_url) else: self.url.setText(self.get_url()) - except: + except Exception: pass def show_url(self): diff --git a/desktop/src/onionshare/threads.py b/desktop/src/onionshare/threads.py index 504591f6..c9a3dba4 100644 --- a/desktop/src/onionshare/threads.py +++ b/desktop/src/onionshare/threads.py @@ -252,7 +252,7 @@ class EventHandlerThread(QtCore.QThread): "EventHandler", "run", f"invalid event type: {obj}" ) - except: + except Exception: pass if self.should_quit: diff --git a/desktop/src/onionshare/tor_connection_dialog.py b/desktop/src/onionshare/tor_connection_dialog.py index c3644f8b..b5c2f61c 100644 --- a/desktop/src/onionshare/tor_connection_dialog.py +++ b/desktop/src/onionshare/tor_connection_dialog.py @@ -166,7 +166,7 @@ class TorConnectionThread(QtCore.QThread): else: self.canceled_connecting_to_tor.emit() - except BundledTorCanceled as e: + except BundledTorCanceled: self.common.log( "TorConnectionThread", "run", "caught exception: BundledTorCanceled" ) diff --git a/desktop/src/onionshare/update_checker.py b/desktop/src/onionshare/update_checker.py index 43c83828..08755e6e 100644 --- a/desktop/src/onionshare/update_checker.py +++ b/desktop/src/onionshare/update_checker.py @@ -19,7 +19,8 @@ along with this program. If not, see . """ from PySide2 import QtCore -import datetime, re +import datetime +import re import socks from distutils.version import LooseVersion as Version diff --git a/desktop/src/setup.py b/desktop/src/setup.py index c2c91d28..82a5f98a 100644 --- a/desktop/src/setup.py +++ b/desktop/src/setup.py @@ -25,7 +25,12 @@ version = "2.3.1" setuptools.setup( name="onionshare", version=version, - description="OnionShare lets you securely and anonymously send and receive files. It works by starting a web server, making it accessible as a Tor onion service, and generating an unguessable web address so others can download files from you, or upload files to you. It does _not_ require setting up a separate server or using a third party file-sharing service.", + description=( + "OnionShare lets you securely and anonymously send and receive files. It works by starting a web " + "server, making it accessible as a Tor onion service, and generating an unguessable web address so " + "others can download files from you, or upload files to you. It does _not_ require setting up a " + "separate server or using a third party file-sharing service." + ), author="Micah Lee", author_email="micah@micahflee.com", maintainer="Micah Lee", diff --git a/desktop/tests/conftest.py b/desktop/tests/conftest.py index a043af0c..b17aa45c 100644 --- a/desktop/tests/conftest.py +++ b/desktop/tests/conftest.py @@ -1,20 +1,21 @@ import sys - -# Force tests to look for resources in the source code tree -sys.onionshare_dev_mode = True - -# Let OnionShare know the tests are running, to avoid colliding with settings files -sys.onionshare_test_mode = True - import os import shutil import tempfile from datetime import datetime, timedelta import pytest - from PySide2 import QtTest +from onionshare_cli import common, web, settings + + +# Force tests to look for resources in the source code tree +sys.onionshare_dev_mode = True + +# Let OnionShare know the tests are running, to avoid colliding with settings files +sys.onionshare_test_mode = True + @staticmethod def qWait(t, qtapp): @@ -36,9 +37,6 @@ sys.path.insert( ), ) -from onionshare_cli import common, web, settings - - # The temporary directory for CLI tests test_temp_dir = None @@ -69,7 +67,7 @@ def temp_dir(): @pytest.fixture def temp_dir_1024(temp_dir): - """ Create a temporary directory that has a single file of a + """Create a temporary directory that has a single file of a particular size (1024 bytes). """ @@ -83,7 +81,7 @@ def temp_dir_1024(temp_dir): # pytest > 2.9 only needs @pytest.fixture @pytest.yield_fixture def temp_dir_1024_delete(temp_dir): - """ Create a temporary directory that has a single file of a + """Create a temporary directory that has a single file of a particular size (1024 bytes). The temporary directory (including the file inside) will be deleted after fixture usage. """ @@ -97,7 +95,7 @@ def temp_dir_1024_delete(temp_dir): @pytest.fixture def temp_file_1024(temp_dir): - """ Create a temporary file of a particular size (1024 bytes). """ + """Create a temporary file of a particular size (1024 bytes).""" with tempfile.NamedTemporaryFile(delete=False, dir=temp_dir) as tmp_file: tmp_file.write(b"*" * 1024) @@ -141,7 +139,7 @@ def default_zw(): tmp_dir = os.path.dirname(zw.zip_filename) try: shutil.rmtree(tmp_dir, ignore_errors=True) - except: + except Exception: pass