Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacement of flake8 with Ruff #1980

Merged
merged 7 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ b6a24debb78b953117a3f637db18942f370a4b85

# Run pre-commit after adding ruff
24e1dd5c561bc3da972e41e6fd61961f12a2fc9f

# Apply ruff sort settings
ba9f1bd3d77dbd0b9efeb1f2f91c743b97ec558e
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
python-version: 3.11
pre-commit: true

- name: Test formatting with Flake8, ruff and Black
- name: Test formatting with ruff
shell: bash
run: make lint
run: pre-commit run --all-files --show-diff-on-failure

prepare-matrix:
runs-on: ubuntu-latest
Expand Down
22 changes: 9 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ repos:
- id: requirements-txt-fixer

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.257"
rev: v0.7.0
hooks:
# Run the linter.
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
# Run the formatter.
- id: ruff-format

# format python files
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
files: ^(src/vorta/|tests)
# - repo: https://github.com/psf/black
# rev: 22.12.0
# hooks:
# - id: black
# files: ^(src/vorta/|tests)

# # run black on code embedded in docstrings
# - repo: https://github.com/asottile/blacken-docs
Expand All @@ -56,12 +58,6 @@ repos:
# 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
# only relevant when actually using the bot
ci:
Expand Down
Empty file removed bin/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions package/fix_app_qt_folder_names_for_codesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys
from pathlib import Path
from typing import Generator, List, Optional

from macholib.MachO import MachO


Expand Down
27 changes: 18 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
[tool.black]
line-length = 120
skip-string-normalization = true
target-version = ['py39']
include = "(src/vorta/|tests).*.py$"

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.ruff]
select = ["T", "I"]
exclude = ["package"]
fixable = ["I"]
line-length = 120
# exclude = ["package", "build", "dist", ".git", ".idea", ".cache", ".tox", ".eggs", "./src/vorta/__init__.py", ".direnv", "env"]
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"
2 changes: 0 additions & 2 deletions requirements.d/dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
black==22.*
coverage
flake8
macholib
nox
pkgconfig
Expand Down
16 changes: 4 additions & 12 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,8 @@ source = vorta
omit = tests/*
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]
envlist = py36,py37,py38,flake8
envlist = py36,py37,py38
skip_missing_interpreters = true

[testenv]
Expand All @@ -92,10 +84,10 @@ deps =
commands=pytest
passenv = DISPLAY

[testenv:flake8]
[testenv:ruff]
deps =
flake8
commands=flake8 src tests
ruff
commands=ruff check src tests

[pycodestyle]
max_line_length = 120
Expand Down
2 changes: 1 addition & 1 deletion src/vorta/assets/exclusion_presets/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
],
"tags": ["application:firefox", "type:browser", "os:linux"],
"author": "Divi, Renner0E"
}
},
{
"name": "Mozilla Firefox Snap cache and config files",
"slug": "firefox-snap-cache",
Expand Down
1 change: 0 additions & 1 deletion src/vorta/autostart.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def open_app_at_startup(enabled=True):
while on Linux it adds a .desktop file at ~/.config/autostart
"""
if sys.platform == 'darwin':

url = NSURL.alloc().initFileURLWithPath_(APP_PATH)
login_items = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None)
props = NSDictionary.dictionaryWithObject_forKey_(True, kLSSharedFileListItemHidden)
Expand Down
1 change: 0 additions & 1 deletion src/vorta/borg/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def started_event(self):

@classmethod
def prepare(cls, params):

# Build fake profile because we don't have it in the DB yet.
profile = FakeProfile(
999,
Expand Down
1 change: 1 addition & 0 deletions src/vorta/i18n/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
internationalisation (i18n) support code
"""

import logging
import os

Expand Down
18 changes: 13 additions & 5 deletions src/vorta/keyring/darwin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# flake8: noqa
# ruff: noqa

"""
A dirty objc implementation to access the macOS Keychain. Because the
Expand All @@ -7,11 +7,14 @@

Adapted from https://gist.github.com/apettinen/5dc7bf1f6a07d148b2075725db6b1950
"""

import logging
import sys
from ctypes import c_char

import objc
from Foundation import NSBundle

from .abc import VortaKeyring

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -47,14 +50,14 @@ def _set_keychain(self):

objc.loadBundleFunctions(Security, globals(), S_functions)

SecKeychainRef = objc.registerCFSignature('SecKeychainRef', b'^{OpaqueSecKeychainRef=}', SecKeychainGetTypeID())
SecKeychainItemRef = objc.registerCFSignature(
objc.registerCFSignature('SecKeychainRef', b'^{OpaqueSecKeychainRef=}', SecKeychainGetTypeID())
objc.registerCFSignature(
'SecKeychainItemRef',
b'^{OpaqueSecKeychainItemRef=}',
SecKeychainItemGetTypeID(),
)

PassBuffRef = objc.createOpaquePointerType('PassBuffRef', b'^{OpaquePassBuff=}', None)
objc.createOpaquePointerType('PassBuffRef', b'^{OpaquePassBuff=}', None)

# Get the login keychain
result, login_keychain = SecKeychainOpen(b'login.keychain', None)
Expand All @@ -81,7 +84,12 @@ def get_password(self, service, repo_url):
if not self.login_keychain:
self._set_keychain()

(result, password_length, password_buffer, keychain_item,) = SecKeychainFindGenericPassword(
(
result,
password_length,
password_buffer,
keychain_item,
) = SecKeychainFindGenericPassword(
self.login_keychain,
len(service),
service.encode(),
Expand Down
1 change: 0 additions & 1 deletion src/vorta/qt_single_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class QtSingleApplication(QApplication):
message_received_event = pyqtSignal(str)

def __init__(self, id, *argv):

super().__init__(*argv)
self._id = id

Expand Down
1 change: 0 additions & 1 deletion src/vorta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ def extract_mount_points_v1(proc, repo_url):

for idx, parameter in enumerate(proc.cmdline()):
if parameter.startswith(repo_url):

if len(proc.cmdline()) > idx + 1:
mount_point = proc.cmdline()[idx + 1]

Expand Down
2 changes: 1 addition & 1 deletion src/vorta/views/exclude_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def populate_custom_exclusions_list(self):
.order_by(ExclusionModel.name)
}

for (exclude, enabled) in user_excluded_patterns.items():
for exclude, enabled in user_excluded_patterns.items():
item = QStandardItem(exclude)
item.setCheckable(True)
item.setCheckState(Qt.CheckState.Checked if enabled else Qt.CheckState.Unchecked)
Expand Down
6 changes: 2 additions & 4 deletions src/vorta/views/partials/treemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,12 +909,10 @@ def __init__(self, parent=None) -> None:
self.folders_on_top = False

@overload
def keepFoldersOnTop(self) -> bool:
...
def keepFoldersOnTop(self) -> bool: ...

@overload
def keepFoldersOnTop(self, value: bool) -> bool:
...
def keepFoldersOnTop(self, value: bool) -> bool: ...

def keepFoldersOnTop(self, value=None) -> bool:
"""
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import sys

import pytest
from peewee import SqliteDatabase

import vorta
import vorta.application
import vorta.borg.jobs_manager
from peewee import SqliteDatabase


def pytest_configure(config):
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import subprocess

import pytest
from peewee import SqliteDatabase
from pkg_resources import parse_version

import vorta
import vorta.application
import vorta.borg.jobs_manager
from peewee import SqliteDatabase
from pkg_resources import parse_version
from vorta.store.models import (
ArchiveModel,
BackupProfileModel,
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import psutil
import pytest
from PyQt6 import QtCore

import vorta.borg
import vorta.utils
import vorta.views.archive_tab
from PyQt6 import QtCore
from vorta.store.models import ArchiveModel


Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_borg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path

import pytest

import vorta.borg
import vorta.store.models
from vorta.borg.info_archive import BorgInfoArchiveJob
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"""

import pytest
from pkg_resources import parse_version

import vorta.borg
import vorta.utils
import vorta.views.archive_tab
from pkg_resources import parse_version
from vorta.borg.diff import BorgDiffJob
from vorta.views.diff_result import (
ChangeType,
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from pathlib import PurePath

import pytest
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QMessageBox

import vorta.borg
import vorta.utils
import vorta.views.repo_add_dialog
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QMessageBox

LONG_PASSWORD = 'long-password-long'
TEST_REPO_NAME = 'TEST - REPONAME'
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from PyQt6 import QtCore

from vorta.store.models import ArchiveModel, EventLogModel


Expand Down
1 change: 1 addition & 0 deletions tests/network_manager/test_darwin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import MagicMock

import pytest

from vorta.network_status import darwin


Expand Down
1 change: 1 addition & 0 deletions tests/network_manager/test_network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import MagicMock

import pytest

from vorta.network_status.abc import SystemWifiInfo
from vorta.network_status.network_manager import (
ActiveConnectionInfo,
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from datetime import datetime as dt

import pytest
from peewee import SqliteDatabase

import vorta
import vorta.application
import vorta.borg.jobs_manager
from peewee import SqliteDatabase
from vorta.store.models import (
ArchiveModel,
BackupProfileModel,
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import psutil
import pytest
from PyQt6 import QtCore
from PyQt6.QtWidgets import QMenu

import vorta.borg
import vorta.utils
import vorta.views.archive_tab
from PyQt6 import QtCore
from PyQt6.QtWidgets import QMenu
from vorta.store.models import ArchiveModel, BackupProfileModel


Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_borg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

import vorta.borg
import vorta.store.models
from vorta.borg.prune import BorgPruneJob
Expand Down
Loading
Loading