1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-21 23:33:13 +00:00

Use Ruff for linting and formatting. By @SAMAD101 (#1980)

This commit is contained in:
Sam 2024-10-18 16:38:59 +05:30 committed by GitHub
parent 4aea36814c
commit 0fb76b68ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 101 additions and 73 deletions

View file

@ -3,3 +3,6 @@ b6a24debb78b953117a3f637db18942f370a4b85
# Run pre-commit after adding ruff # Run pre-commit after adding ruff
24e1dd5c561bc3da972e41e6fd61961f12a2fc9f 24e1dd5c561bc3da972e41e6fd61961f12a2fc9f
# Apply ruff sort settings
ba9f1bd3d77dbd0b9efeb1f2f91c743b97ec558e

View file

@ -22,9 +22,9 @@ jobs:
python-version: 3.11 python-version: 3.11
pre-commit: true pre-commit: true
- name: Test formatting with Flake8, ruff and Black - name: Test formatting with ruff
shell: bash shell: bash
run: make lint run: pre-commit run --all-files --show-diff-on-failure
prepare-matrix: prepare-matrix:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View file

@ -29,17 +29,19 @@ repos:
- id: requirements-txt-fixer - id: requirements-txt-fixer
- repo: https://github.com/charliermarsh/ruff-pre-commit - repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.257" rev: v0.7.0
hooks: hooks:
# Run the linter.
- id: ruff - id: ruff
args: [--fix, --exit-non-zero-on-fix] # Run the formatter.
- id: ruff-format
# format python files # format python files
- repo: https://github.com/psf/black # - repo: https://github.com/psf/black
rev: 22.12.0 # rev: 22.12.0
hooks: # hooks:
- id: black # - id: black
files: ^(src/vorta/|tests) # files: ^(src/vorta/|tests)
# # run black on code embedded in docstrings # # run black on code embedded in docstrings
# - repo: https://github.com/asottile/blacken-docs # - repo: https://github.com/asottile/blacken-docs
@ -56,12 +58,6 @@ repos:
# py39, # py39,
# ] # ]
# check pep8 conformity using flake8
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
# configuration for the pre-commit.ci bot # configuration for the pre-commit.ci bot
# only relevant when actually using the bot # only relevant when actually using the bot
ci: ci:

View file

View file

@ -11,6 +11,7 @@
import sys import sys
from pathlib import Path from pathlib import Path
from typing import Generator, List, Optional from typing import Generator, List, Optional
from macholib.MachO import MachO from macholib.MachO import MachO

View file

@ -1,14 +1,23 @@
[tool.black]
line-length = 120
skip-string-normalization = true
target-version = ['py39']
include = "(src/vorta/|tests).*.py$"
[build-system] [build-system]
requires = ["setuptools"] requires = ["setuptools"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[tool.ruff] [tool.ruff]
select = ["T", "I"] line-length = 120
exclude = ["package"] # exclude = ["package", "build", "dist", ".git", ".idea", ".cache", ".tox", ".eggs", "./src/vorta/__init__.py", ".direnv", "env"]
fixable = ["I"] include = ["src/**/*.py", "tests/**/*.py"]
[tool.ruff.lint]
select = [
"E", # Error
"F", # pyflakes
"I", # isort
"W", # Warning
"YTT", # flake8-2020
]
ignore = [
"F401",
]
[tool.ruff.format]
quote-style = "preserve"

View file

@ -1,6 +1,4 @@
black==22.*
coverage coverage
flake8
macholib macholib
nox nox
pkgconfig pkgconfig

View file

@ -72,16 +72,8 @@ source = vorta
omit = tests/* omit = tests/*
relative_files = true relative_files = true
[flake8]
ignore =
max-line-length = 120
extend-ignore = E203,E121,E123,E126,E226,E24,E704,W503,W504
exclude =
build,dist,.git,.idea,.cache,.tox,.eggs,
./src/vorta/__init__.py,.direnv,env
[tox:tox] [tox:tox]
envlist = py36,py37,py38,flake8 envlist = py36,py37,py38
skip_missing_interpreters = true skip_missing_interpreters = true
[testenv] [testenv]
@ -92,10 +84,10 @@ deps =
commands=pytest commands=pytest
passenv = DISPLAY passenv = DISPLAY
[testenv:flake8] [testenv:ruff]
deps = deps =
flake8 ruff
commands=flake8 src tests commands=ruff check src tests
[pycodestyle] [pycodestyle]
max_line_length = 120 max_line_length = 120

View file

@ -135,7 +135,7 @@
], ],
"tags": ["application:firefox", "type:browser", "os:linux"], "tags": ["application:firefox", "type:browser", "os:linux"],
"author": "Divi, Renner0E" "author": "Divi, Renner0E"
} },
{ {
"name": "Mozilla Firefox Snap cache and config files", "name": "Mozilla Firefox Snap cache and config files",
"slug": "firefox-snap-cache", "slug": "firefox-snap-cache",

View file

@ -31,7 +31,6 @@ def open_app_at_startup(enabled=True):
while on Linux it adds a .desktop file at ~/.config/autostart while on Linux it adds a .desktop file at ~/.config/autostart
""" """
if sys.platform == 'darwin': if sys.platform == 'darwin':
url = NSURL.alloc().initFileURLWithPath_(APP_PATH) url = NSURL.alloc().initFileURLWithPath_(APP_PATH)
login_items = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None) login_items = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None)
props = NSDictionary.dictionaryWithObject_forKey_(True, kLSSharedFileListItemHidden) props = NSDictionary.dictionaryWithObject_forKey_(True, kLSSharedFileListItemHidden)

View file

@ -10,7 +10,6 @@ def started_event(self):
@classmethod @classmethod
def prepare(cls, params): def prepare(cls, params):
# Build fake profile because we don't have it in the DB yet. # Build fake profile because we don't have it in the DB yet.
profile = FakeProfile( profile = FakeProfile(
999, 999,

View file

@ -1,6 +1,7 @@
""" """
internationalisation (i18n) support code internationalisation (i18n) support code
""" """
import logging import logging
import os import os

View file

@ -1,4 +1,4 @@
# flake8: noqa # ruff: noqa
""" """
A dirty objc implementation to access the macOS Keychain. Because the A dirty objc implementation to access the macOS Keychain. Because the
@ -7,11 +7,14 @@
Adapted from https://gist.github.com/apettinen/5dc7bf1f6a07d148b2075725db6b1950 Adapted from https://gist.github.com/apettinen/5dc7bf1f6a07d148b2075725db6b1950
""" """
import logging import logging
import sys import sys
from ctypes import c_char from ctypes import c_char
import objc import objc
from Foundation import NSBundle from Foundation import NSBundle
from .abc import VortaKeyring from .abc import VortaKeyring
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -47,14 +50,14 @@ def _set_keychain(self):
objc.loadBundleFunctions(Security, globals(), S_functions) objc.loadBundleFunctions(Security, globals(), S_functions)
SecKeychainRef = objc.registerCFSignature('SecKeychainRef', b'^{OpaqueSecKeychainRef=}', SecKeychainGetTypeID()) objc.registerCFSignature('SecKeychainRef', b'^{OpaqueSecKeychainRef=}', SecKeychainGetTypeID())
SecKeychainItemRef = objc.registerCFSignature( objc.registerCFSignature(
'SecKeychainItemRef', 'SecKeychainItemRef',
b'^{OpaqueSecKeychainItemRef=}', b'^{OpaqueSecKeychainItemRef=}',
SecKeychainItemGetTypeID(), SecKeychainItemGetTypeID(),
) )
PassBuffRef = objc.createOpaquePointerType('PassBuffRef', b'^{OpaquePassBuff=}', None) objc.createOpaquePointerType('PassBuffRef', b'^{OpaquePassBuff=}', None)
# Get the login keychain # Get the login keychain
result, login_keychain = SecKeychainOpen(b'login.keychain', None) result, login_keychain = SecKeychainOpen(b'login.keychain', None)
@ -81,7 +84,12 @@ def get_password(self, service, repo_url):
if not self.login_keychain: if not self.login_keychain:
self._set_keychain() self._set_keychain()
(result, password_length, password_buffer, keychain_item,) = SecKeychainFindGenericPassword( (
result,
password_length,
password_buffer,
keychain_item,
) = SecKeychainFindGenericPassword(
self.login_keychain, self.login_keychain,
len(service), len(service),
service.encode(), service.encode(),

View file

@ -40,7 +40,6 @@ class QtSingleApplication(QApplication):
message_received_event = pyqtSignal(str) message_received_event = pyqtSignal(str)
def __init__(self, id, *argv): def __init__(self, id, *argv):
super().__init__(*argv) super().__init__(*argv)
self._id = id self._id = id

View file

@ -469,7 +469,6 @@ def extract_mount_points_v1(proc, repo_url):
for idx, parameter in enumerate(proc.cmdline()): for idx, parameter in enumerate(proc.cmdline()):
if parameter.startswith(repo_url): if parameter.startswith(repo_url):
if len(proc.cmdline()) > idx + 1: if len(proc.cmdline()) > idx + 1:
mount_point = proc.cmdline()[idx + 1] mount_point = proc.cmdline()[idx + 1]

View file

@ -154,7 +154,7 @@ def populate_custom_exclusions_list(self):
.order_by(ExclusionModel.name) .order_by(ExclusionModel.name)
} }
for (exclude, enabled) in user_excluded_patterns.items(): for exclude, enabled in user_excluded_patterns.items():
item = QStandardItem(exclude) item = QStandardItem(exclude)
item.setCheckable(True) item.setCheckable(True)
item.setCheckState(Qt.CheckState.Checked if enabled else Qt.CheckState.Unchecked) item.setCheckState(Qt.CheckState.Checked if enabled else Qt.CheckState.Unchecked)

View file

@ -909,12 +909,10 @@ def __init__(self, parent=None) -> None:
self.folders_on_top = False self.folders_on_top = False
@overload @overload
def keepFoldersOnTop(self) -> bool: def keepFoldersOnTop(self) -> bool: ...
...
@overload @overload
def keepFoldersOnTop(self, value: bool) -> bool: def keepFoldersOnTop(self, value: bool) -> bool: ...
...
def keepFoldersOnTop(self, value=None) -> bool: def keepFoldersOnTop(self, value=None) -> bool:
""" """

View file

@ -2,10 +2,11 @@
import sys import sys
import pytest import pytest
from peewee import SqliteDatabase
import vorta import vorta
import vorta.application import vorta.application
import vorta.borg.jobs_manager import vorta.borg.jobs_manager
from peewee import SqliteDatabase
def pytest_configure(config): def pytest_configure(config):

View file

@ -2,11 +2,12 @@
import subprocess import subprocess
import pytest import pytest
from peewee import SqliteDatabase
from pkg_resources import parse_version
import vorta import vorta
import vorta.application import vorta.application
import vorta.borg.jobs_manager import vorta.borg.jobs_manager
from peewee import SqliteDatabase
from pkg_resources import parse_version
from vorta.store.models import ( from vorta.store.models import (
ArchiveModel, ArchiveModel,
BackupProfileModel, BackupProfileModel,

View file

@ -7,10 +7,11 @@
import psutil import psutil
import pytest import pytest
from PyQt6 import QtCore
import vorta.borg import vorta.borg
import vorta.utils import vorta.utils
import vorta.views.archive_tab import vorta.views.archive_tab
from PyQt6 import QtCore
from vorta.store.models import ArchiveModel from vorta.store.models import ArchiveModel

View file

@ -5,6 +5,7 @@
from pathlib import Path from pathlib import Path
import pytest import pytest
import vorta.borg import vorta.borg
import vorta.store.models import vorta.store.models
from vorta.borg.info_archive import BorgInfoArchiveJob from vorta.borg.info_archive import BorgInfoArchiveJob

View file

@ -3,10 +3,11 @@
""" """
import pytest import pytest
from pkg_resources import parse_version
import vorta.borg import vorta.borg
import vorta.utils import vorta.utils
import vorta.views.archive_tab import vorta.views.archive_tab
from pkg_resources import parse_version
from vorta.borg.diff import BorgDiffJob from vorta.borg.diff import BorgDiffJob
from vorta.views.diff_result import ( from vorta.views.diff_result import (
ChangeType, ChangeType,

View file

@ -6,11 +6,12 @@
from pathlib import PurePath from pathlib import PurePath
import pytest import pytest
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QMessageBox
import vorta.borg import vorta.borg
import vorta.utils import vorta.utils
import vorta.views.repo_add_dialog import vorta.views.repo_add_dialog
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QMessageBox
LONG_PASSWORD = 'long-password-long' LONG_PASSWORD = 'long-password-long'
TEST_REPO_NAME = 'TEST - REPONAME' TEST_REPO_NAME = 'TEST - REPONAME'

View file

@ -4,6 +4,7 @@
import pytest import pytest
from PyQt6 import QtCore from PyQt6 import QtCore
from vorta.store.models import ArchiveModel, EventLogModel from vorta.store.models import ArchiveModel, EventLogModel

View file

@ -1,6 +1,7 @@
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pytest import pytest
from vorta.network_status import darwin from vorta.network_status import darwin

View file

@ -2,6 +2,7 @@
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pytest import pytest
from vorta.network_status.abc import SystemWifiInfo from vorta.network_status.abc import SystemWifiInfo
from vorta.network_status.network_manager import ( from vorta.network_status.network_manager import (
ActiveConnectionInfo, ActiveConnectionInfo,

View file

@ -2,10 +2,11 @@
from datetime import datetime as dt from datetime import datetime as dt
import pytest import pytest
from peewee import SqliteDatabase
import vorta import vorta
import vorta.application import vorta.application
import vorta.borg.jobs_manager import vorta.borg.jobs_manager
from peewee import SqliteDatabase
from vorta.store.models import ( from vorta.store.models import (
ArchiveModel, ArchiveModel,
BackupProfileModel, BackupProfileModel,

View file

@ -2,11 +2,12 @@
import psutil import psutil
import pytest import pytest
from PyQt6 import QtCore
from PyQt6.QtWidgets import QMenu
import vorta.borg import vorta.borg
import vorta.utils import vorta.utils
import vorta.views.archive_tab import vorta.views.archive_tab
from PyQt6 import QtCore
from PyQt6.QtWidgets import QMenu
from vorta.store.models import ArchiveModel, BackupProfileModel from vorta.store.models import ArchiveModel, BackupProfileModel

View file

@ -1,4 +1,5 @@
import pytest import pytest
import vorta.borg import vorta.borg
import vorta.store.models import vorta.store.models
from vorta.borg.prune import BorgPruneJob from vorta.borg.prune import BorgPruneJob

View file

@ -1,11 +1,12 @@
from pathlib import PurePath from pathlib import PurePath
import pytest import pytest
from PyQt6.QtCore import QDateTime, QItemSelectionModel, Qt
from PyQt6.QtWidgets import QMenu
import vorta.borg import vorta.borg
import vorta.utils import vorta.utils
import vorta.views.archive_tab import vorta.views.archive_tab
from PyQt6.QtCore import QDateTime, QItemSelectionModel, Qt
from PyQt6.QtWidgets import QMenu
from vorta.store.models import ArchiveModel from vorta.store.models import ArchiveModel
from vorta.views.diff_result import ( from vorta.views.diff_result import (
ChangeType, ChangeType,

View file

@ -1,6 +1,7 @@
import pytest import pytest
import vorta.borg
from PyQt6.QtCore import QModelIndex, Qt from PyQt6.QtCore import QModelIndex, Qt
import vorta.borg
from vorta.store.models import ArchiveModel from vorta.store.models import ArchiveModel
from vorta.views.extract_dialog import ( from vorta.views.extract_dialog import (
ExtractDialog, ExtractDialog,

View file

@ -4,6 +4,7 @@
import pytest import pytest
from PyQt6 import QtCore from PyQt6 import QtCore
from PyQt6.QtWidgets import QDialogButtonBox, QFileDialog, QMessageBox from PyQt6.QtWidgets import QDialogButtonBox, QFileDialog, QMessageBox
from vorta.profile_export import VersionException from vorta.profile_export import VersionException
from vorta.store.models import BackupProfileModel, SourceFileModel from vorta.store.models import BackupProfileModel, SourceFileModel
from vorta.views.import_window import ImportWindow from vorta.views.import_window import ImportWindow

View file

@ -1,7 +1,8 @@
import pytest import pytest
from PyQt6 import QtCore
import vorta.application import vorta.application
import vorta.borg.borg_job import vorta.borg.borg_job
from PyQt6 import QtCore
def test_create_perm_error(qapp, borg_json_output, mocker, qtbot): def test_create_perm_error(qapp, borg_json_output, mocker, qtbot):

View file

@ -4,10 +4,11 @@
from unittest.mock import Mock from unittest.mock import Mock
import pytest import pytest
import vorta.store.models
from PyQt6 import QtCore from PyQt6 import QtCore
from PyQt6.QtGui import QCloseEvent from PyQt6.QtGui import QCloseEvent
from PyQt6.QtWidgets import QCheckBox, QFormLayout, QMessageBox from PyQt6.QtWidgets import QCheckBox, QFormLayout, QMessageBox
import vorta.store.models
from vorta.store.models import SettingsModel from vorta.store.models import SettingsModel

View file

@ -1,9 +1,10 @@
import sys import sys
import pytest import pytest
from PyQt6 import QtDBus
import vorta.borg import vorta.borg
import vorta.notifications import vorta.notifications
from PyQt6 import QtDBus
@pytest.mark.skipif(sys.platform != 'linux', reason="DBus notifications only on Linux") @pytest.mark.skipif(sys.platform != 'linux', reason="DBus notifications only on Linux")

View file

@ -1,5 +1,6 @@
import pytest import pytest
from PyQt6.QtWidgets import QFormLayout, QWidget from PyQt6.QtWidgets import QFormLayout, QWidget
from vorta.views.partials.password_input import PasswordInput, PasswordLineEdit from vorta.views.partials.password_input import PasswordInput, PasswordLineEdit

View file

@ -2,6 +2,7 @@
from PyQt6 import QtCore from PyQt6 import QtCore
from PyQt6.QtWidgets import QDialogButtonBox, QFileDialog, QMessageBox, QToolTip from PyQt6.QtWidgets import QDialogButtonBox, QFileDialog, QMessageBox, QToolTip
from vorta.store.models import BackupProfileModel, SourceFileModel from vorta.store.models import BackupProfileModel, SourceFileModel
from vorta.views.export_window import ExportWindow from vorta.views.export_window import ExportWindow

View file

@ -3,9 +3,10 @@
from typing import Any, Dict from typing import Any, Dict
import pytest import pytest
import vorta.borg.borg_job
from PyQt6 import QtCore from PyQt6 import QtCore
from PyQt6.QtWidgets import QMessageBox from PyQt6.QtWidgets import QMessageBox
import vorta.borg.borg_job
from vorta.keyring.abc import VortaKeyring from vorta.keyring.abc import VortaKeyring
from vorta.store.models import ArchiveModel, EventLogModel, RepoModel from vorta.store.models import ArchiveModel, EventLogModel, RepoModel

View file

@ -3,8 +3,9 @@
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pytest import pytest
import vorta.scheduler
from PyQt6 import QtCore from PyQt6 import QtCore
import vorta.scheduler
from vorta.application import VortaApp from vorta.application import VortaApp
from vorta.store.models import BackupProfileModel, EventLogModel from vorta.store.models import BackupProfileModel, EventLogModel

View file

@ -4,9 +4,10 @@
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pytest import pytest
from pytest import mark
import vorta.borg import vorta.borg
import vorta.scheduler import vorta.scheduler
from pytest import mark
from vorta.scheduler import ScheduleStatus, ScheduleStatusType, VortaScheduler from vorta.scheduler import ScheduleStatus, ScheduleStatusType, VortaScheduler
from vorta.store.models import BackupProfileModel, EventLogModel from vorta.store.models import BackupProfileModel, EventLogModel

View file

@ -1,7 +1,8 @@
import pytest import pytest
import vorta.views
from PyQt6 import QtCore from PyQt6 import QtCore
from PyQt6.QtWidgets import QMessageBox from PyQt6.QtWidgets import QMessageBox
import vorta.views
from vorta.views.main_window import MainWindow from vorta.views.main_window import MainWindow
from vorta.views.source_tab import SourceTab from vorta.views.source_tab import SourceTab

View file

@ -2,6 +2,7 @@
import pytest import pytest
from PyQt6.QtCore import QModelIndex from PyQt6.QtCore import QModelIndex
from vorta.views.partials.treemodel import FileSystemItem, FileTreeModel from vorta.views.partials.treemodel import FileSystemItem, FileTreeModel

View file

@ -2,6 +2,7 @@
import uuid import uuid
import pytest import pytest
from vorta.keyring.abc import VortaKeyring from vorta.keyring.abc import VortaKeyring
from vorta.utils import ( from vorta.utils import (
find_best_unit_for_sizes, find_best_unit_for_sizes,