mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-05-06 13:31:50 +02:00
Compare commits
8 commits
41a6c59634
...
87eac56345
Author | SHA1 | Date | |
---|---|---|---|
![]() |
87eac56345 | ||
![]() |
688bc991ab | ||
![]() |
5ad8092a2c | ||
![]() |
9764a1b3f2 | ||
![]() |
5d4d8ed441 | ||
![]() |
75bbfea6ce | ||
![]() |
0f8382b831 | ||
![]() |
19915fda50 |
10 changed files with 55 additions and 159 deletions
35
Makefile
35
Makefile
|
@ -1,23 +1,6 @@
|
|||
LARGE_TEST_REPO_DIR:=tests/test_docs_large
|
||||
GIT_DESC=$$(git describe)
|
||||
JUNIT_FLAGS := --capture=sys -o junit_logging=all
|
||||
|
||||
.PHONY: lint-black
|
||||
lint-black: ## check python source code formatting issues, with black
|
||||
black --check --diff ./
|
||||
|
||||
.PHONY: lint-black-apply
|
||||
lint-black-apply: ## apply black's source code formatting suggestions
|
||||
black ./
|
||||
|
||||
.PHONY: lint-isort
|
||||
lint-isort: ## check imports are organized, with isort
|
||||
isort --check --diff ./
|
||||
|
||||
.PHONY: lint-isort-apply
|
||||
lint-isort-apply: ## apply isort's imports organization suggestions
|
||||
isort ./
|
||||
|
||||
MYPY_ARGS := --ignore-missing-imports \
|
||||
--disallow-incomplete-defs \
|
||||
--disallow-untyped-defs \
|
||||
|
@ -26,19 +9,17 @@ MYPY_ARGS := --ignore-missing-imports \
|
|||
--warn-unused-ignores \
|
||||
--exclude $(LARGE_TEST_REPO_DIR)/*.py
|
||||
|
||||
mypy-host:
|
||||
.PHONY: lint
|
||||
lint: ## Check the code for linting, formatting, and typing issues with ruff and mypy
|
||||
ruff check
|
||||
ruff format --check
|
||||
mypy $(MYPY_ARGS) dangerzone
|
||||
|
||||
mypy-tests:
|
||||
mypy $(MYPY_ARGS) tests
|
||||
|
||||
mypy: mypy-host mypy-tests ## check type hints with mypy
|
||||
|
||||
.PHONY: lint
|
||||
lint: lint-black lint-isort mypy ## check the code with various linters
|
||||
|
||||
.PHONY: lint-apply
|
||||
format: lint-black-apply lint-isort-apply ## apply all the linter's suggestions
|
||||
.PHONY: fix
|
||||
fix: ## apply all the suggestions from ruff
|
||||
ruff check --fix
|
||||
ruff format
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
|
|
|
@ -6,7 +6,6 @@ import signal
|
|||
import subprocess
|
||||
import sys
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import IO, Callable, Iterator, Optional
|
||||
|
||||
import fitz
|
||||
|
|
|
@ -71,7 +71,7 @@ class DangerzoneCore(object):
|
|||
ocr_lang,
|
||||
stdout_callback,
|
||||
)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
log.exception(
|
||||
f"Unexpected error occurred while converting '{document}'"
|
||||
)
|
||||
|
|
|
@ -8,7 +8,6 @@ import platform
|
|||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import urllib.request
|
||||
from datetime import date
|
||||
|
||||
DEFAULT_GUI = True
|
||||
|
|
|
@ -95,11 +95,11 @@ def main():
|
|||
parser.add_argument(
|
||||
"--version",
|
||||
required=True,
|
||||
help=f"look for assets with this Dangerzone version",
|
||||
help="look for assets with this Dangerzone version",
|
||||
)
|
||||
parser.add_argument(
|
||||
"dir",
|
||||
help=f"look for assets in this directory",
|
||||
help="look for assets in this directory",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
setup_logging()
|
||||
|
|
|
@ -105,7 +105,7 @@ def build_components_xml(root, data):
|
|||
Guid=subdata["component_guid"],
|
||||
)
|
||||
for filename in subdata["files"]:
|
||||
file_el = ET.SubElement(
|
||||
ET.SubElement(
|
||||
component_el, "File", Source=filename, Id="file_" + uuid.uuid4().hex
|
||||
)
|
||||
|
||||
|
|
89
poetry.lock
generated
89
poetry.lock
generated
|
@ -44,52 +44,6 @@ files = [
|
|||
{file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "black"
|
||||
version = "24.10.0"
|
||||
description = "The uncompromising code formatter."
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
files = [
|
||||
{file = "black-24.10.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e6668650ea4b685440857138e5fe40cde4d652633b1bdffc62933d0db4ed9812"},
|
||||
{file = "black-24.10.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:1c536fcf674217e87b8cc3657b81809d3c085d7bf3ef262ead700da345bfa6ea"},
|
||||
{file = "black-24.10.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:649fff99a20bd06c6f727d2a27f401331dc0cc861fb69cde910fe95b01b5928f"},
|
||||
{file = "black-24.10.0-cp310-cp310-win_amd64.whl", hash = "sha256:fe4d6476887de70546212c99ac9bd803d90b42fc4767f058a0baa895013fbb3e"},
|
||||
{file = "black-24.10.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:5a2221696a8224e335c28816a9d331a6c2ae15a2ee34ec857dcf3e45dbfa99ad"},
|
||||
{file = "black-24.10.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f9da3333530dbcecc1be13e69c250ed8dfa67f43c4005fb537bb426e19200d50"},
|
||||
{file = "black-24.10.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4007b1393d902b48b36958a216c20c4482f601569d19ed1df294a496eb366392"},
|
||||
{file = "black-24.10.0-cp311-cp311-win_amd64.whl", hash = "sha256:394d4ddc64782e51153eadcaaca95144ac4c35e27ef9b0a42e121ae7e57a9175"},
|
||||
{file = "black-24.10.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:b5e39e0fae001df40f95bd8cc36b9165c5e2ea88900167bddf258bacef9bbdc3"},
|
||||
{file = "black-24.10.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d37d422772111794b26757c5b55a3eade028aa3fde43121ab7b673d050949d65"},
|
||||
{file = "black-24.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:14b3502784f09ce2443830e3133dacf2c0110d45191ed470ecb04d0f5f6fcb0f"},
|
||||
{file = "black-24.10.0-cp312-cp312-win_amd64.whl", hash = "sha256:30d2c30dc5139211dda799758559d1b049f7f14c580c409d6ad925b74a4208a8"},
|
||||
{file = "black-24.10.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:1cbacacb19e922a1d75ef2b6ccaefcd6e93a2c05ede32f06a21386a04cedb981"},
|
||||
{file = "black-24.10.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:1f93102e0c5bb3907451063e08b9876dbeac810e7da5a8bfb7aeb5a9ef89066b"},
|
||||
{file = "black-24.10.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ddacb691cdcdf77b96f549cf9591701d8db36b2f19519373d60d31746068dbf2"},
|
||||
{file = "black-24.10.0-cp313-cp313-win_amd64.whl", hash = "sha256:680359d932801c76d2e9c9068d05c6b107f2584b2a5b88831c83962eb9984c1b"},
|
||||
{file = "black-24.10.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:17374989640fbca88b6a448129cd1745c5eb8d9547b464f281b251dd00155ccd"},
|
||||
{file = "black-24.10.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:63f626344343083322233f175aaf372d326de8436f5928c042639a4afbbf1d3f"},
|
||||
{file = "black-24.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ccfa1d0cb6200857f1923b602f978386a3a2758a65b52e0950299ea014be6800"},
|
||||
{file = "black-24.10.0-cp39-cp39-win_amd64.whl", hash = "sha256:2cd9c95431d94adc56600710f8813ee27eea544dd118d45896bb734e9d7a0dc7"},
|
||||
{file = "black-24.10.0-py3-none-any.whl", hash = "sha256:3bb2b7a1f7b685f85b11fed1ef10f8a9148bceb49853e47a294a3dd963c1dd7d"},
|
||||
{file = "black-24.10.0.tar.gz", hash = "sha256:846ea64c97afe3bc677b761787993be4991810ecc7a4a937816dd6bddedc4875"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
click = ">=8.0.0"
|
||||
mypy-extensions = ">=0.4.3"
|
||||
packaging = ">=22.0"
|
||||
pathspec = ">=0.9.0"
|
||||
platformdirs = ">=2"
|
||||
tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""}
|
||||
typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""}
|
||||
|
||||
[package.extras]
|
||||
colorama = ["colorama (>=0.4.3)"]
|
||||
d = ["aiohttp (>=3.10)"]
|
||||
jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"]
|
||||
uvloop = ["uvloop (>=0.15.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2024.8.30"
|
||||
|
@ -531,20 +485,6 @@ files = [
|
|||
{file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "isort"
|
||||
version = "5.13.2"
|
||||
description = "A Python utility / library to sort Python imports."
|
||||
optional = false
|
||||
python-versions = ">=3.8.0"
|
||||
files = [
|
||||
{file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"},
|
||||
{file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
colors = ["colorama (>=0.4.6)"]
|
||||
|
||||
[[package]]
|
||||
name = "lief"
|
||||
version = "0.15.1"
|
||||
|
@ -709,33 +649,6 @@ files = [
|
|||
{file = "packaging-24.2.tar.gz", hash = "sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pathspec"
|
||||
version = "0.12.1"
|
||||
description = "Utility library for gitignore style pattern matching of file paths."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08"},
|
||||
{file = "pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "platformdirs"
|
||||
version = "4.3.6"
|
||||
description = "A small Python package for determining appropriate platform-specific dirs, e.g. a `user data dir`."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "platformdirs-4.3.6-py3-none-any.whl", hash = "sha256:73e575e1408ab8103900836b97580d5307456908a03e92031bab39e4554cc3fb"},
|
||||
{file = "platformdirs-4.3.6.tar.gz", hash = "sha256:357fb2acbc885b0419afd3ce3ed34564c13c9b95c89360cd9563f73aa5e2b907"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
docs = ["furo (>=2024.8.6)", "proselint (>=0.14)", "sphinx (>=8.0.2)", "sphinx-autodoc-typehints (>=2.4)"]
|
||||
test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=8.3.2)", "pytest-cov (>=5)", "pytest-mock (>=3.14)"]
|
||||
type = ["mypy (>=1.11.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "pluggy"
|
||||
version = "1.5.0"
|
||||
|
@ -1216,4 +1129,4 @@ type = ["pytest-mypy"]
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">=3.9,<3.13"
|
||||
content-hash = "6bafa7debf5fe9dd53777d8634da065d733a5d1fff87dda76e6fb8df9bfd9b04"
|
||||
content-hash = "56e1ef68447c1e9d96c0ae369e43b3c7ac79a7ce424674fa78a886553cc5693d"
|
||||
|
|
|
@ -37,8 +37,6 @@ pyinstaller = {version = "*", platform = "darwin"}
|
|||
|
||||
# Dependencies required for linting the code.
|
||||
[tool.poetry.group.lint.dependencies]
|
||||
black = "*"
|
||||
isort = "*"
|
||||
mypy = "*"
|
||||
ruff = "*"
|
||||
types-PySide2 = "*"
|
||||
|
@ -61,11 +59,11 @@ pymupdf = "1.24.11" # Last version to support python 3.8 (needed for Ubuntu Foca
|
|||
[tool.poetry.group.dev.dependencies]
|
||||
httpx = "^0.27.2"
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
skip_gitignore = true
|
||||
# This is necessary due to https://github.com/PyCQA/isort/issues/1835
|
||||
follow_links = false
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
# isort
|
||||
"I",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.2.0"]
|
||||
|
|
|
@ -33,17 +33,19 @@ def test_order_mime_handers() -> None:
|
|||
"LibreOffice",
|
||||
]
|
||||
|
||||
with mock.patch(
|
||||
"subprocess.check_output", return_value=b"libreoffice-draw.desktop"
|
||||
) as mock_default_mime_hander, mock.patch(
|
||||
"os.listdir",
|
||||
side_effect=[
|
||||
["org.gnome.Evince.desktop"],
|
||||
["org.pwmt.zathura-pdf-mupdf.desktop"],
|
||||
["libreoffice-draw.desktop"],
|
||||
],
|
||||
) as mock_list, mock.patch(
|
||||
"dangerzone.gui.logic.DesktopEntry", return_value=mock_desktop
|
||||
with (
|
||||
mock.patch(
|
||||
"subprocess.check_output", return_value=b"libreoffice-draw.desktop"
|
||||
) as mock_default_mime_hander,
|
||||
mock.patch(
|
||||
"os.listdir",
|
||||
side_effect=[
|
||||
["org.gnome.Evince.desktop"],
|
||||
["org.pwmt.zathura-pdf-mupdf.desktop"],
|
||||
["libreoffice-draw.desktop"],
|
||||
],
|
||||
) as mock_list,
|
||||
mock.patch("dangerzone.gui.logic.DesktopEntry", return_value=mock_desktop),
|
||||
):
|
||||
dz = DangerzoneGui(mock_app, dummy)
|
||||
|
||||
|
@ -77,18 +79,20 @@ def test_mime_handers_succeeds_no_default_found() -> None:
|
|||
"LibreOffice",
|
||||
]
|
||||
|
||||
with mock.patch(
|
||||
"subprocess.check_output",
|
||||
side_effect=subprocess.CalledProcessError(1, "Oh no, xdg-mime error!)"),
|
||||
) as mock_default_mime_hander, mock.patch(
|
||||
"os.listdir",
|
||||
side_effect=[
|
||||
["org.gnome.Evince.desktop"],
|
||||
["org.pwmt.zathura-pdf-mupdf.desktop"],
|
||||
["libreoffice-draw.desktop"],
|
||||
],
|
||||
) as mock_list, mock.patch(
|
||||
"dangerzone.gui.logic.DesktopEntry", return_value=mock_desktop
|
||||
with (
|
||||
mock.patch(
|
||||
"subprocess.check_output",
|
||||
side_effect=subprocess.CalledProcessError(1, "Oh no, xdg-mime error!)"),
|
||||
) as mock_default_mime_hander,
|
||||
mock.patch(
|
||||
"os.listdir",
|
||||
side_effect=[
|
||||
["org.gnome.Evince.desktop"],
|
||||
["org.pwmt.zathura-pdf-mupdf.desktop"],
|
||||
["libreoffice-draw.desktop"],
|
||||
],
|
||||
) as mock_list,
|
||||
mock.patch("dangerzone.gui.logic.DesktopEntry", return_value=mock_desktop),
|
||||
):
|
||||
dz = DangerzoneGui(mock_app, dummy)
|
||||
|
||||
|
@ -109,13 +113,16 @@ def test_malformed_desktop_entry_is_catched() -> None:
|
|||
mock_app = mock.MagicMock()
|
||||
dummy = mock.MagicMock()
|
||||
|
||||
with mock.patch("dangerzone.gui.logic.DesktopEntry") as mock_desktop, mock.patch(
|
||||
"os.listdir",
|
||||
side_effect=[
|
||||
["malformed.desktop", "another.desktop"],
|
||||
[],
|
||||
[],
|
||||
],
|
||||
with (
|
||||
mock.patch("dangerzone.gui.logic.DesktopEntry") as mock_desktop,
|
||||
mock.patch(
|
||||
"os.listdir",
|
||||
side_effect=[
|
||||
["malformed.desktop", "another.desktop"],
|
||||
[],
|
||||
[],
|
||||
],
|
||||
),
|
||||
):
|
||||
mock_desktop.side_effect = ParsingError("Oh noes!", "malformed.desktop")
|
||||
DangerzoneGui(mock_app, dummy)
|
||||
|
|
|
@ -7,7 +7,6 @@ from typing import List
|
|||
|
||||
from pytest import MonkeyPatch, fixture
|
||||
from pytest_mock import MockerFixture
|
||||
from pytest_subprocess import FakeProcess
|
||||
from pytestqt.qtbot import QtBot
|
||||
|
||||
from dangerzone.document import Document
|
||||
|
|
Loading…
Reference in a new issue