From 4175c847216607ff27e3fa9cde722d33c8506fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Wed, 22 May 2024 15:05:14 +0200 Subject: [PATCH] chore(imports): remove useless imports As detected by [ruff](https://github.com/astral-sh/ruff) Related to #254, although it doesn't provide the command to lint the codebase itself. --- dangerzone/__init__.py | 2 +- dangerzone/cli.py | 2 +- dangerzone/conversion/common.py | 8 +------- dangerzone/conversion/doc_to_pixels.py | 5 +---- dangerzone/conversion/errors.py | 1 - dangerzone/conversion/pixels_to_pdf.py | 1 - dangerzone/document.py | 5 ----- dangerzone/errors.py | 2 +- dangerzone/gui/__init__.py | 2 -- dangerzone/gui/logic.py | 1 - dangerzone/gui/main_window.py | 6 +----- dangerzone/gui/updater.py | 4 ++-- dangerzone/isolation_provider/base.py | 1 - dangerzone/isolation_provider/container.py | 2 +- dangerzone/isolation_provider/dummy.py | 1 - dangerzone/isolation_provider/qubes.py | 3 +-- dangerzone/logic.py | 6 ------ dangerzone/settings.py | 2 +- dangerzone/util.py | 1 - dev_scripts/env.py | 2 -- dev_scripts/upload-asset.py | 3 --- qubes/dz.ConvertDev | 4 ---- setup-windows.py | 2 -- setup.py | 1 - tests/gui/__init__.py | 1 - tests/gui/test_main_window.py | 4 +--- tests/gui/test_updater.py | 3 --- tests/isolation_provider/base.py | 2 -- tests/isolation_provider/test_container.py | 6 ------ tests/isolation_provider/test_dummy.py | 2 +- tests/isolation_provider/test_qubes.py | 2 -- tests/test_cli.py | 2 -- tests/test_document.py | 2 -- tests/test_large_set.py | 1 - tests/test_settings.py | 3 +-- 35 files changed, 14 insertions(+), 81 deletions(-) diff --git a/dangerzone/__init__.py b/dangerzone/__init__.py index 69fb9dbb5..6144f3a4d 100644 --- a/dangerzone/__init__.py +++ b/dangerzone/__init__.py @@ -13,4 +13,4 @@ if mode == "cli": from .cli import cli_main as main else: - from .gui import gui_main as main + from .gui import gui_main as main # NOQA diff --git a/dangerzone/cli.py b/dangerzone/cli.py index 4ba94328d..3e2352e75 100644 --- a/dangerzone/cli.py +++ b/dangerzone/cli.py @@ -1,6 +1,6 @@ import logging import sys -from typing import Any, Callable, List, Optional, TypeVar +from typing import List, Optional import click from colorama import Back, Fore, Style diff --git a/dangerzone/conversion/common.py b/dangerzone/conversion/common.py index e0a9f39d5..4560f3d5d 100644 --- a/dangerzone/conversion/common.py +++ b/dangerzone/conversion/common.py @@ -1,16 +1,10 @@ #!/usr/bin/env python3 import asyncio -import glob -import json import os -import re -import shutil -import subprocess import sys -import time from abc import abstractmethod -from typing import Callable, Dict, List, Optional, TextIO, Tuple, Union +from typing import Callable, List, Optional, TextIO, Tuple DEFAULT_DPI = 150 # Pixels per inch INT_BYTES = 2 diff --git a/dangerzone/conversion/doc_to_pixels.py b/dangerzone/conversion/doc_to_pixels.py index 5f1abf3b9..1d8c14e5c 100644 --- a/dangerzone/conversion/doc_to_pixels.py +++ b/dangerzone/conversion/doc_to_pixels.py @@ -1,11 +1,8 @@ #!/usr/bin/env python3 import asyncio -import glob import os -import re -import shutil import sys -from typing import Dict, List, Optional, TextIO +from typing import Dict, Optional import fitz import magic diff --git a/dangerzone/conversion/errors.py b/dangerzone/conversion/errors.py index b719e68a5..6bb5ec1cc 100644 --- a/dangerzone/conversion/errors.py +++ b/dangerzone/conversion/errors.py @@ -1,4 +1,3 @@ -import subprocess from typing import List, Optional, Type, Union # XXX: errors start at 128 for conversion-related issues diff --git a/dangerzone/conversion/pixels_to_pdf.py b/dangerzone/conversion/pixels_to_pdf.py index d69c7a3c3..b419670ef 100644 --- a/dangerzone/conversion/pixels_to_pdf.py +++ b/dangerzone/conversion/pixels_to_pdf.py @@ -11,7 +11,6 @@ import io import json import os -import shutil import sys from typing import Optional diff --git a/dangerzone/document.py b/dangerzone/document.py index 66d2eac41..6e3a0574a 100644 --- a/dangerzone/document.py +++ b/dangerzone/document.py @@ -1,15 +1,10 @@ import enum import logging import os -import platform import secrets -import stat -import tempfile from pathlib import Path from typing import Optional -import appdirs - from . import errors, util SAFE_EXTENSION = "-safe.pdf" diff --git a/dangerzone/errors.py b/dangerzone/errors.py index 8d916788c..63dc4e7b9 100644 --- a/dangerzone/errors.py +++ b/dangerzone/errors.py @@ -1,7 +1,7 @@ import functools import logging import sys -from typing import Any, Callable, Sequence, TypeVar, cast +from typing import Any, Callable, TypeVar, cast import click diff --git a/dangerzone/gui/__init__.py b/dangerzone/gui/__init__.py index d7595edcc..664fe1cfc 100644 --- a/dangerzone/gui/__init__.py +++ b/dangerzone/gui/__init__.py @@ -1,12 +1,10 @@ import enum -import functools import logging import os import platform import signal import sys import typing -import uuid from typing import Dict, List, Optional import click diff --git a/dangerzone/gui/logic.py b/dangerzone/gui/logic.py index e19c9df6b..effe8bb85 100644 --- a/dangerzone/gui/logic.py +++ b/dangerzone/gui/logic.py @@ -25,7 +25,6 @@ from ..isolation_provider.base import IsolationProvider from ..logic import DangerzoneCore -from ..settings import Settings from ..util import get_resource_path, replace_control_chars log = logging.getLogger(__name__) diff --git a/dangerzone/gui/main_window.py b/dangerzone/gui/main_window.py index 7b750b1fd..9e04e44d2 100644 --- a/dangerzone/gui/main_window.py +++ b/dangerzone/gui/main_window.py @@ -1,15 +1,11 @@ -import json import logging import os import platform -import shutil import subprocess import tempfile import typing from multiprocessing.pool import ThreadPool -from typing import Dict, List, Optional - -from colorama import Fore, Style +from typing import List, Optional # FIXME: See https://github.com/freedomofpress/dangerzone/issues/320 for more details. if typing.TYPE_CHECKING: diff --git a/dangerzone/gui/updater.py b/dangerzone/gui/updater.py index d5cf8bba6..1dc3ffaa5 100644 --- a/dangerzone/gui/updater.py +++ b/dangerzone/gui/updater.py @@ -6,7 +6,7 @@ import sys import time import typing -from typing import Any, Optional +from typing import Optional from packaging import version @@ -20,7 +20,7 @@ # XXX implict import for "markdown" module required for Cx_Freeze to build on Windows # See https://github.com/freedomofpress/dangerzone/issues/501 -import html.parser +import html.parser # NOQA import markdown import requests diff --git a/dangerzone/isolation_provider/base.py b/dangerzone/isolation_provider/base.py index f0a2478d4..4a8ff401c 100644 --- a/dangerzone/isolation_provider/base.py +++ b/dangerzone/isolation_provider/base.py @@ -1,6 +1,5 @@ import contextlib import logging -import os import subprocess import sys import tempfile diff --git a/dangerzone/isolation_provider/container.py b/dangerzone/isolation_provider/container.py index e469588b9..4b2de1f64 100644 --- a/dangerzone/isolation_provider/container.py +++ b/dangerzone/isolation_provider/container.py @@ -11,7 +11,7 @@ from ..conversion import errors from ..document import Document -from ..util import get_resource_path, get_subprocess_startupinfo, get_tmp_dir +from ..util import get_resource_path, get_subprocess_startupinfo from .base import PIXELS_TO_PDF_LOG_END, PIXELS_TO_PDF_LOG_START, IsolationProvider # Define startupinfo for subprocesses diff --git a/dangerzone/isolation_provider/dummy.py b/dangerzone/isolation_provider/dummy.py index aaf718fac..c476f335d 100644 --- a/dangerzone/isolation_provider/dummy.py +++ b/dangerzone/isolation_provider/dummy.py @@ -4,7 +4,6 @@ import subprocess import sys import time -from pathlib import Path from typing import Callable, Optional from ..document import Document diff --git a/dangerzone/isolation_provider/qubes.py b/dangerzone/isolation_provider/qubes.py index f8f86bdcc..34e76edee 100644 --- a/dangerzone/isolation_provider/qubes.py +++ b/dangerzone/isolation_provider/qubes.py @@ -1,5 +1,4 @@ import asyncio -import inspect import io import logging import os @@ -8,7 +7,7 @@ import sys import zipfile from pathlib import Path -from typing import IO, Callable, Optional +from typing import IO, Optional from ..conversion import errors from ..conversion.common import running_on_qubes diff --git a/dangerzone/logic.py b/dangerzone/logic.py index 3cab438b1..0f3e346c7 100644 --- a/dangerzone/logic.py +++ b/dangerzone/logic.py @@ -1,12 +1,6 @@ import concurrent.futures -import gzip import json import logging -import pathlib -import platform -import shutil -import subprocess -import sys from typing import Callable, List, Optional import colorama diff --git a/dangerzone/settings.py b/dangerzone/settings.py index 762f1326d..596b5fd3a 100644 --- a/dangerzone/settings.py +++ b/dangerzone/settings.py @@ -1,7 +1,7 @@ import json import logging import os -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict from packaging import version diff --git a/dangerzone/util.py b/dangerzone/util.py index b56a2e8d0..888c20025 100644 --- a/dangerzone/util.py +++ b/dangerzone/util.py @@ -1,6 +1,5 @@ import pathlib import platform -import string import subprocess import sys import unicodedata diff --git a/dev_scripts/env.py b/dev_scripts/env.py index 39605056c..3c8756e8b 100755 --- a/dev_scripts/env.py +++ b/dev_scripts/env.py @@ -1,10 +1,8 @@ #!/usr/bin/env python3 import argparse -import functools import os import pathlib -import re import shutil import subprocess import sys diff --git a/dev_scripts/upload-asset.py b/dev_scripts/upload-asset.py index 8cf771278..cfcc31ed9 100755 --- a/dev_scripts/upload-asset.py +++ b/dev_scripts/upload-asset.py @@ -2,12 +2,9 @@ import argparse import getpass -import inspect import logging import os -import pathlib import sys -import urllib import requests diff --git a/qubes/dz.ConvertDev b/qubes/dz.ConvertDev index 74a984540..19d83d9f4 100755 --- a/qubes/dz.ConvertDev +++ b/qubes/dz.ConvertDev @@ -1,12 +1,8 @@ #!/usr/bin/env python3 import asyncio -import glob -import io -import os import sys import tempfile -import zipfile def say(msg): diff --git a/setup-windows.py b/setup-windows.py index 3d77f476a..deae94381 100644 --- a/setup-windows.py +++ b/setup-windows.py @@ -1,6 +1,4 @@ #!/usr/bin/env python3 -import os - from cx_Freeze import Executable, setup with open("share/version.txt") as f: diff --git a/setup.py b/setup.py index d7fbea772..eba6f947e 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 import os -import sys import setuptools diff --git a/tests/gui/__init__.py b/tests/gui/__init__.py index 4cab65f06..cbf49de5c 100644 --- a/tests/gui/__init__.py +++ b/tests/gui/__init__.py @@ -1,6 +1,5 @@ from pathlib import Path from typing import Optional -from unittest import mock import pytest from pytest import MonkeyPatch diff --git a/tests/gui/test_main_window.py b/tests/gui/test_main_window.py index d7fb66a30..6ee524b00 100644 --- a/tests/gui/test_main_window.py +++ b/tests/gui/test_main_window.py @@ -2,9 +2,8 @@ import pathlib import shutil import time -import typing -from PySide6 import QtCore, QtWidgets +from PySide6 import QtCore from pytest import MonkeyPatch, fixture from pytest_mock import MockerFixture from pytestqt.qtbot import QtBot @@ -15,7 +14,6 @@ from dangerzone.gui.logic import DangerzoneGui from dangerzone.gui.main_window import ContentWidget from dangerzone.gui.updater import UpdateReport, UpdaterThread -from dangerzone.util import get_version from .. import sample_doc, sample_pdf from . import qt_updater as updater diff --git a/tests/gui/test_updater.py b/tests/gui/test_updater.py index 60470f563..e6f76c285 100644 --- a/tests/gui/test_updater.py +++ b/tests/gui/test_updater.py @@ -1,9 +1,7 @@ import json -import os import platform import sys import time -import typing from pathlib import Path import pytest @@ -13,7 +11,6 @@ from pytestqt.qtbot import QtBot from dangerzone import settings -from dangerzone.gui import MainWindow from dangerzone.gui import updater as updater_module from dangerzone.gui.updater import UpdateReport, UpdaterThread from dangerzone.util import get_version diff --git a/tests/isolation_provider/base.py b/tests/isolation_provider/base.py index 1dd459b90..5775d7455 100644 --- a/tests/isolation_provider/base.py +++ b/tests/isolation_provider/base.py @@ -2,8 +2,6 @@ import subprocess import pytest -from colorama import Style -from pytest import MonkeyPatch from pytest_mock import MockerFixture from dangerzone.conversion import errors diff --git a/tests/isolation_provider/test_container.py b/tests/isolation_provider/test_container.py index 33bd8b49b..6a05f83d3 100644 --- a/tests/isolation_provider/test_container.py +++ b/tests/isolation_provider/test_container.py @@ -1,15 +1,9 @@ -import itertools -import json import os import subprocess import time -from typing import Any, Dict import pytest -from pytest_mock import MockerFixture -from dangerzone.document import Document -from dangerzone.isolation_provider import base from dangerzone.isolation_provider.container import Container from dangerzone.isolation_provider.qubes import is_qubes_native_conversion diff --git a/tests/isolation_provider/test_dummy.py b/tests/isolation_provider/test_dummy.py index 061eb5aaf..04ccf9724 100644 --- a/tests/isolation_provider/test_dummy.py +++ b/tests/isolation_provider/test_dummy.py @@ -9,7 +9,7 @@ from dangerzone.isolation_provider.base import IsolationProvider from dangerzone.isolation_provider.dummy import Dummy -from .base import IsolationProviderTermination, IsolationProviderTest +from .base import IsolationProviderTermination class DummyWait(Dummy): diff --git a/tests/isolation_provider/test_qubes.py b/tests/isolation_provider/test_qubes.py index 43d297260..b05049f4d 100644 --- a/tests/isolation_provider/test_qubes.py +++ b/tests/isolation_provider/test_qubes.py @@ -1,6 +1,5 @@ import os import pathlib -import signal import subprocess import time @@ -10,7 +9,6 @@ from dangerzone.conversion import errors from dangerzone.document import Document -from dangerzone.isolation_provider.base import IsolationProvider from dangerzone.isolation_provider.qubes import ( Qubes, is_qubes_native_conversion, diff --git a/tests/test_cli.py b/tests/test_cli.py index 884b9816a..cb615eae6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,11 +1,9 @@ from __future__ import annotations import base64 -import contextlib import copy import os import platform -import re import shutil import sys import tempfile diff --git a/tests/test_document.py b/tests/test_document.py index c999f426e..46aaf1831 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -1,7 +1,5 @@ import os import platform -import stat -import tempfile from pathlib import Path from unittest.mock import MagicMock diff --git a/tests/test_large_set.py b/tests/test_large_set.py index e9c9b438b..d596c7476 100644 --- a/tests/test_large_set.py +++ b/tests/test_large_set.py @@ -2,7 +2,6 @@ import re import subprocess import sys -import time from pathlib import Path from typing import List diff --git a/tests/test_settings.py b/tests/test_settings.py index 4cddd5657..13deaddf8 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,4 +1,3 @@ -import collections import json import os from pathlib import Path @@ -7,7 +6,7 @@ import pytest from pytest_mock import MockerFixture -from dangerzone.settings import * +from dangerzone.settings import SETTINGS_FILENAME, Settings def default_settings_0_4_1() -> dict: