diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 00000000..4075d8f5 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,19 @@ +version = 1 + +test_patterns = [ + "desktop/tests/**", + "cli/tests/**" +] + +exclude_patterns = [ + "snap/**", + "licenses/**", + "flatpak/**" +] + +[[analyzers]] +name = "python" +enabled = true + + [analyzers.meta] + runtime_version = "3.x.x" \ No newline at end of file diff --git a/cli/onionshare_cli/__init__.py b/cli/onionshare_cli/__init__.py index 0f361b00..c40bf6a0 100644 --- a/cli/onionshare_cli/__init__.py +++ b/cli/onionshare_cli/__init__.py @@ -514,8 +514,7 @@ def main(cwd=None): print("Stopped because auto-stop timer ran out") web.stop(app.port) break - else: - web.receive_mode.can_upload = False + web.receive_mode.can_upload = False # Allow KeyboardInterrupt exception to be handled with threads # https://stackoverflow.com/questions/3788208/python-threading-ignores-keyboardinterrupt-exception time.sleep(0.2) diff --git a/cli/onionshare_cli/common.py b/cli/onionshare_cli/common.py index 6e36dbd6..4cfe83ae 100644 --- a/cli/onionshare_cli/common.py +++ b/cli/onionshare_cli/common.py @@ -19,13 +19,11 @@ along with this program. If not, see . """ import base64 import hashlib -import inspect import os import platform import random import socket import sys -import tempfile import threading import time import shutil diff --git a/cli/onionshare_cli/onion.py b/cli/onionshare_cli/onion.py index aab2e1ff..8bc353c0 100644 --- a/cli/onionshare_cli/onion.py +++ b/cli/onionshare_cli/onion.py @@ -28,11 +28,9 @@ import tempfile import subprocess import time import shlex -import getpass import psutil from distutils.version import LooseVersion as Version -from .settings import Settings class TorErrorAutomatic(Exception): @@ -518,13 +516,12 @@ class Onion(object): self.settings.get("control_port_address"), self.settings.get("control_port_port"), ) - else: - print( - "Can't connect to the Tor controller using socket file {}.".format( - self.settings.get("socket_file_path") - ) + print( + "Can't connect to the Tor controller using socket file {}.".format( + self.settings.get("socket_file_path") ) - raise TorErrorSocketFile(self.settings.get("socket_file_path")) + ) + raise TorErrorSocketFile(self.settings.get("socket_file_path")) # Try authenticating try: @@ -755,7 +752,7 @@ class Onion(object): ): rendevouz_circuit_ids.append(c.id) - symbols = [c for c in "\\|/-"] + symbols = list("\\|/-") symbols_i = 0 while True: @@ -837,9 +834,6 @@ class Onion(object): # Import the key key = RSA.importKey(base64.b64decode(key)) # Is this a v2 Onion key? (1024 bits) If so, we should keep using it. - if key.n.bit_length() == 1024: - return True - else: - return False + return key.n.bit_length() == 1024 except: return False diff --git a/cli/onionshare_cli/onionshare.py b/cli/onionshare_cli/onionshare.py index 30eae3f3..4e34cf4b 100644 --- a/cli/onionshare_cli/onionshare.py +++ b/cli/onionshare_cli/onionshare.py @@ -19,8 +19,6 @@ along with this program. If not, see . """ import os, shutil - -from . import common from .common import AutoStopTimer diff --git a/cli/onionshare_cli/settings.py b/cli/onionshare_cli/settings.py index a655d46c..00e3e79b 100644 --- a/cli/onionshare_cli/settings.py +++ b/cli/onionshare_cli/settings.py @@ -20,7 +20,6 @@ along with this program. If not, see . import json import os -import platform import locale try: diff --git a/cli/onionshare_cli/web/chat_mode.py b/cli/onionshare_cli/web/chat_mode.py index d4c57438..2daf9654 100644 --- a/cli/onionshare_cli/web/chat_mode.py +++ b/cli/onionshare_cli/web/chat_mode.py @@ -19,15 +19,11 @@ along with this program. If not, see . """ from flask import ( - Request, request, render_template, make_response, jsonify, - redirect, - session, -) -from werkzeug.utils import secure_filename + session) from flask_socketio import emit, join_room, leave_room diff --git a/cli/onionshare_cli/web/send_base_mode.py b/cli/onionshare_cli/web/send_base_mode.py index b09fc4c6..b42c346b 100644 --- a/cli/onionshare_cli/web/send_base_mode.py +++ b/cli/onionshare_cli/web/send_base_mode.py @@ -23,7 +23,7 @@ import sys import tempfile import mimetypes import gzip -from flask import Response, request, render_template, make_response +from flask import Response, request from unidecode import unidecode from werkzeug.urls import url_quote diff --git a/cli/onionshare_cli/web/web.py b/cli/onionshare_cli/web/web.py index 6f4986e7..7408046b 100644 --- a/cli/onionshare_cli/web/web.py +++ b/cli/onionshare_cli/web/web.py @@ -17,17 +17,11 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ - -import hmac import logging import os import queue -import socket -import sys -import tempfile import requests from distutils.version import LooseVersion as Version -from urllib.request import urlopen import flask from flask import ( diff --git a/cli/onionshare_cli/web/website_mode.py b/cli/onionshare_cli/web/website_mode.py index fa8b53bd..5718c9a9 100644 --- a/cli/onionshare_cli/web/website_mode.py +++ b/cli/onionshare_cli/web/website_mode.py @@ -19,10 +19,7 @@ along with this program. If not, see . """ import os -import sys -import tempfile -import mimetypes -from flask import Response, request, render_template, make_response +from flask import render_template, make_response from .send_base_mode import SendBaseModeWeb diff --git a/cli/setup.py b/cli/setup.py index 90f7ddbc..e6050ff8 100644 --- a/cli/setup.py +++ b/cli/setup.py @@ -18,11 +18,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ - -# snap and flatpak packaging uses setup.py -# PyPi publishing, developing, and testing uses poetry - -import os import setuptools version = "2.3.1" diff --git a/cli/tests/test_cli_common.py b/cli/tests/test_cli_common.py index e95ba03e..96838c95 100644 --- a/cli/tests/test_cli_common.py +++ b/cli/tests/test_cli_common.py @@ -1,12 +1,10 @@ import contextlib -import inspect import io import os import random import re import socket import sys -import zipfile import pytest diff --git a/cli/tests/test_cli_web.py b/cli/tests/test_cli_web.py index 063bd43c..421ee4f3 100644 --- a/cli/tests/test_cli_web.py +++ b/cli/tests/test_cli_web.py @@ -1,11 +1,6 @@ -import contextlib -import inspect -import io import os import random import re -import socket -import sys import zipfile import tempfile import base64 diff --git a/desktop/package/linux/build-appimage.py b/desktop/package/linux/build-appimage.py index 73164b55..0c64494f 100755 --- a/desktop/package/linux/build-appimage.py +++ b/desktop/package/linux/build-appimage.py @@ -2,7 +2,6 @@ import os import inspect import subprocess -import argparse import shutil import glob diff --git a/desktop/package/windows/build.py b/desktop/package/windows/build.py index 59929070..603b1514 100644 --- a/desktop/package/windows/build.py +++ b/desktop/package/windows/build.py @@ -2,7 +2,6 @@ import os import inspect import subprocess -import argparse import shutil import glob diff --git a/desktop/scripts/check_lacked_trans.py b/desktop/scripts/check_lacked_trans.py index 965b103b..2456c995 100755 --- a/desktop/scripts/check_lacked_trans.py +++ b/desktop/scripts/check_lacked_trans.py @@ -105,11 +105,10 @@ def main(): if src[quote_i] == '"': quote = '"' break - elif src[quote_i] == "'": + if src[quote_i] == "'": quote = "'" break - else: - inc += 1 + inc += 1 # find the starting quote starting_i = src.find(quote, starting_i) diff --git a/desktop/scripts/get-tor-osx.py b/desktop/scripts/get-tor-osx.py index bf0cb5bc..f3aa6e7b 100755 --- a/desktop/scripts/get-tor-osx.py +++ b/desktop/scripts/get-tor-osx.py @@ -29,8 +29,6 @@ import inspect import os import sys import hashlib -import zipfile -import io import shutil import subprocess import requests diff --git a/desktop/scripts/rebuild-cli.py b/desktop/scripts/rebuild-cli.py index c13461bc..66582cf1 100755 --- a/desktop/scripts/rebuild-cli.py +++ b/desktop/scripts/rebuild-cli.py @@ -6,7 +6,6 @@ and installs it in the virtual environment. import inspect import os -import sys import glob import subprocess import shutil diff --git a/desktop/src/onionshare/gui_common.py b/desktop/src/onionshare/gui_common.py index bd72246a..7703f7a8 100644 --- a/desktop/src/onionshare/gui_common.py +++ b/desktop/src/onionshare/gui_common.py @@ -19,7 +19,6 @@ along with this program. If not, see . """ import os -import inspect import shutil from pkg_resources import resource_filename diff --git a/desktop/src/onionshare/main_window.py b/desktop/src/onionshare/main_window.py index 2f6e91d0..d87092b6 100644 --- a/desktop/src/onionshare/main_window.py +++ b/desktop/src/onionshare/main_window.py @@ -21,8 +21,6 @@ along with this program. If not, see . import time from PySide2 import QtCore, QtWidgets, QtGui -from onionshare_cli.web import Web - from . import strings from .tor_connection_dialog import TorConnectionDialog from .settings_dialog import SettingsDialog diff --git a/desktop/src/onionshare/settings_dialog.py b/desktop/src/onionshare/settings_dialog.py index 3f913bcd..190ae35d 100644 --- a/desktop/src/onionshare/settings_dialog.py +++ b/desktop/src/onionshare/settings_dialog.py @@ -24,8 +24,6 @@ import platform import datetime import re import os - -from onionshare_cli import common from onionshare_cli.settings import Settings from onionshare_cli.onion import ( Onion, @@ -47,11 +45,7 @@ from onionshare_cli.onion import ( from . import strings from .widgets import Alert from .update_checker import ( - UpdateCheckerCheckError, - UpdateCheckerInvalidLatestVersion, - UpdateChecker, - UpdateThread, -) + UpdateThread) from .tor_connection_dialog import TorConnectionDialog from .gui_common import GuiCommon diff --git a/desktop/src/onionshare/strings.py b/desktop/src/onionshare/strings.py index a3db202c..c4192a33 100644 --- a/desktop/src/onionshare/strings.py +++ b/desktop/src/onionshare/strings.py @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ import json -import locale import os strings = {} diff --git a/desktop/src/onionshare/tab/server_status.py b/desktop/src/onionshare/tab/server_status.py index 8c1c9655..d8266820 100644 --- a/desktop/src/onionshare/tab/server_status.py +++ b/desktop/src/onionshare/tab/server_status.py @@ -17,8 +17,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ - -import platform import textwrap from PySide2 import QtCore, QtWidgets, QtGui from PySide2.QtCore import Qt diff --git a/desktop/src/onionshare/threads.py b/desktop/src/onionshare/threads.py index 214344f7..504591f6 100644 --- a/desktop/src/onionshare/threads.py +++ b/desktop/src/onionshare/threads.py @@ -158,14 +158,14 @@ class AutoStartTimer(QtCore.QThread): ) try: # Sleep until scheduled time - while autostart_timer_datetime_delta > 0 and self.canceled == False: + while autostart_timer_datetime_delta > 0 and self.canceled is False: time.sleep(0.1) now = QtCore.QDateTime.currentDateTime() autostart_timer_datetime_delta = now.secsTo( self.mode.server_status.autostart_timer_datetime ) # Timer has now finished - if self.canceled == False: + if self.canceled is False: self.mode.server_status.server_button.setText( strings._("gui_please_wait") ) diff --git a/desktop/src/onionshare/update_checker.py b/desktop/src/onionshare/update_checker.py index 1d8e8b07..43c83828 100644 --- a/desktop/src/onionshare/update_checker.py +++ b/desktop/src/onionshare/update_checker.py @@ -19,14 +19,11 @@ along with this program. If not, see . """ from PySide2 import QtCore -import datetime, time, socket, re, platform +import datetime, re import socks from distutils.version import LooseVersion as Version from onionshare_cli.settings import Settings -from onionshare_cli.onion import Onion - -from . import strings class UpdateCheckerCheckError(Exception): diff --git a/desktop/src/setup.py b/desktop/src/setup.py index 83aeeba1..c2c91d28 100644 --- a/desktop/src/setup.py +++ b/desktop/src/setup.py @@ -18,11 +18,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ - -# This setup.py file is used for snap and flatpak packaging. For other packaging, -# OnionShare uses briefcase. - -import os import setuptools version = "2.3.1" diff --git a/desktop/tests/conftest.py b/desktop/tests/conftest.py index 65d13fa6..a043af0c 100644 --- a/desktop/tests/conftest.py +++ b/desktop/tests/conftest.py @@ -13,7 +13,7 @@ from datetime import datetime, timedelta import pytest -from PySide2 import QtTest, QtGui +from PySide2 import QtTest @staticmethod diff --git a/desktop/tests/gui_base_test.py b/desktop/tests/gui_base_test.py index 214da945..c6a5da2f 100644 --- a/desktop/tests/gui_base_test.py +++ b/desktop/tests/gui_base_test.py @@ -1,11 +1,7 @@ -import pytest import unittest - -import json import os import requests import shutil -import base64 import tempfile import secrets import platform @@ -13,9 +9,6 @@ import platform from PySide2 import QtCore, QtTest, QtWidgets from onionshare_cli.common import Common -from onionshare_cli.settings import Settings -from onionshare_cli.onion import Onion -from onionshare_cli.web import Web from onionshare import Application, MainWindow, GuiCommon from onionshare.tab.mode.share_mode import ShareMode diff --git a/desktop/tests/test_gui_share.py b/desktop/tests/test_gui_share.py index 0e521d52..380d63f6 100644 --- a/desktop/tests/test_gui_share.py +++ b/desktop/tests/test_gui_share.py @@ -1,4 +1,3 @@ -import pytest import os import requests import tempfile diff --git a/desktop/tests/test_gui_tabs.py b/desktop/tests/test_gui_tabs.py index 4ebbdffb..84558420 100644 --- a/desktop/tests/test_gui_tabs.py +++ b/desktop/tests/test_gui_tabs.py @@ -1,4 +1,3 @@ -import pytest import os from PySide2 import QtCore, QtTest, QtWidgets diff --git a/desktop/tests/test_gui_website.py b/desktop/tests/test_gui_website.py index 164aa07d..a838cb96 100644 --- a/desktop/tests/test_gui_website.py +++ b/desktop/tests/test_gui_website.py @@ -1,10 +1,6 @@ -import pytest -import os import requests -import shutil -from datetime import datetime, timedelta -from PySide2 import QtCore, QtTest +from PySide2 import QtTest from .gui_base_test import GuiBaseTest diff --git a/docs/source/conf.py b/docs/source/conf.py index 18a58d80..ae124a22 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,5 +1,3 @@ -import sphinx_rtd_theme -import sphinx_intl project = "OnionShare"