Skip to content

Commit

Permalink
Replace Black, Flake8, and Pydocstyle with Ruff (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra committed May 20, 2024
1 parent 61ba6df commit d26193a
Show file tree
Hide file tree
Showing 124 changed files with 1,106 additions and 862 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:

- name: Run the tests
if: ${{ ! startsWith(runner.os, 'Linux') }}
run: BETTY_TEST_SKIP_SHELLCHECK=true BETTY_TEST_SKIP_BLACK=true BETTY_TEST_SKIP_FLAKE8=true BETTY_TEST_SKIP_MYPY=true BETTY_TEST_SKIP_STYLELINT=true BETTY_TEST_SKIP_ESLINT=true BETTY_TEST_SKIP_BUSTED=true BETTY_TEST_SKIP_PLAYWRIGHT=true BETTY_TEST_SKIP_PYINSTALLER=true ./bin/test
run: BETTY_TEST_SKIP_SHELLCHECK=true BETTY_TEST_SKIP_RUFF=true BETTY_TEST_SKIP_MYPY=true BETTY_TEST_SKIP_STYLELINT=true BETTY_TEST_SKIP_ESLINT=true BETTY_TEST_SKIP_BUSTED=true BETTY_TEST_SKIP_PLAYWRIGHT=true BETTY_TEST_SKIP_PYINSTALLER=true ./bin/test
shell: bash

- name: Upload code coverage
Expand Down
2 changes: 0 additions & 2 deletions .pydocstyle.ini

This file was deleted.

27 changes: 27 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[lint]
extend-select = [
'A',
'B',
'C4',
'D',
'F',
'INT',
'PT',
'PTH',
'SIM',
'SLOT',
'T20',
'TCH',
]
extend-ignore = [
'D101',
'D102',
'D105',
'D107',
'D200',
'D203',
'D212',
'D401',
'F501',
'PTH123',
]
10 changes: 6 additions & 4 deletions betty/_npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

import logging
import sys
from asyncio import subprocess as aiosubprocess
from pathlib import Path
from typing import Sequence
from typing import Sequence, TYPE_CHECKING

from betty.asyncio import wait_to_thread
from betty.error import UserFacingError
from betty.locale import Str, DEFAULT_LOCALIZER
from betty.requirement import Requirement
from betty.subprocess import run_process

if TYPE_CHECKING:
from pathlib import Path
from asyncio import subprocess as aiosubprocess


_NPM_UNAVAILABLE_MESSAGE = Str._(
"npm (https://www.npmjs.com/) must be available for features that require Node.js packages to be installed. Ensure that the `npm` executable is available in your `PATH`."
Expand Down Expand Up @@ -45,7 +47,7 @@ async def npm(
shell=sys.platform.startswith("win32"),
)
except FileNotFoundError:
raise NpmUnavailable()
raise NpmUnavailable() from None


class NpmRequirement(Requirement):
Expand Down
14 changes: 7 additions & 7 deletions betty/_package/pyinstaller/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Integrate Betty with PyInstaller."""

import sys
from glob import glob
from pathlib import Path

from PyInstaller.building.api import PYZ, EXE, COLLECT
from PyInstaller.building.build_main import Analysis
Expand Down Expand Up @@ -40,12 +38,14 @@ async def a_pyz_exe_coll() -> tuple[Analysis, PYZ, EXE, COLLECT]:
"prebuild/**",
]
for data_file_path_pattern in data_file_path_patterns:
for data_file_path_str in glob(
data_file_path_pattern, recursive=True, root_dir=ROOT_DIRECTORY_PATH
):
data_file_path = Path(data_file_path_str)
for data_file_path in ROOT_DIRECTORY_PATH.glob(data_file_path_pattern):
if data_file_path.is_file():
datas.append((data_file_path_str, str(data_file_path.parent)))
datas.append(
(
str(data_file_path),
str(data_file_path.parent.relative_to(ROOT_DIRECTORY_PATH)),
)
)
hiddenimports = [
*find_packages(
".",
Expand Down
11 changes: 6 additions & 5 deletions betty/_package/pyinstaller/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ def main() -> None:


async def _main() -> None:
async with App.new_from_environment() as app:
async with BettyApplication([sys.argv[0]]).with_app(app) as qapp:
window = WelcomeWindow(app)
window.show()
sys.exit(qapp.exec())
async with App.new_from_environment() as app, BettyApplication(
[sys.argv[0]]
).with_app(app) as qapp:
window = WelcomeWindow(app)
window.show()
sys.exit(qapp.exec())


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions betty/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ async def is_development() -> bool:
def _indent_mapping(items: dict[str, str]) -> str:
max_indentation = max(map(len, items.keys())) + 4
return "\n".join(
map(
lambda x: "\n".join(_indent_mapping_item(x[0], x[1], max_indentation)),
items.items(),
(
"\n".join(_indent_mapping_item(x[0], x[1], max_indentation))
for x in items.items()
)
)

Expand Down
10 changes: 5 additions & 5 deletions betty/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

import operator
import weakref
from collections.abc import AsyncIterator
from concurrent.futures import Executor, ProcessPoolExecutor
from contextlib import suppress, asynccontextmanager
from functools import reduce
from graphlib import CycleError, TopologicalSorter
from multiprocessing import get_context
from os import environ
from pathlib import Path
from types import TracebackType
from typing import TYPE_CHECKING, Mapping, Self, Any, final

import aiohttp
Expand All @@ -32,7 +30,6 @@
from betty.cache import Cache, FileCache
from betty.cache.file import BinaryFileCache, PickledFileCache
from betty.config import Configurable, FileBasedConfiguration
from betty.dispatch import Dispatcher
from betty.fs import FileSystem, CACHE_DIRECTORY_PATH
from betty.locale import LocalizerRepository, get_data, DEFAULT_LOCALE, Localizer, Str
from betty.model import Entity, EntityTypeProvider
Expand Down Expand Up @@ -73,6 +70,9 @@
from betty.warnings import deprecate

if TYPE_CHECKING:
from betty.dispatch import Dispatcher
from types import TracebackType
from collections.abc import AsyncIterator
from betty.jinja2 import Environment
from betty.serve import Server
from betty.url import StaticUrlGenerator, LocalizedUrlGenerator
Expand Down Expand Up @@ -131,7 +131,7 @@ def locale(self, locale: str) -> None:
'"{locale}" is not a valid IETF BCP 47 language tag.',
locale=locale,
)
)
) from None
self._locale = locale
self._dispatch_change()

Expand Down Expand Up @@ -341,7 +341,7 @@ def _update_extensions(self) -> None:
app_extension_configuration.extension_type
for app_extension_configuration in self.project.configuration.extensions.values()
]
)
) from None

extensions = []
while extension_types_sorter.is_active():
Expand Down
17 changes: 6 additions & 11 deletions betty/app/extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import functools
from collections import defaultdict
from importlib.metadata import entry_points, EntryPoint
from pathlib import Path
from typing import (
Any,
TypeVar,
Expand All @@ -25,6 +24,7 @@
from betty.locale import Str

if TYPE_CHECKING:
from pathlib import Path
from betty.app import App


Expand Down Expand Up @@ -73,7 +73,7 @@ def __init__(self, dependent_type: type[Extension]):
try:
dependency_requirement = dependency_type.enable_requirement()
except RecursionError:
raise CyclicDependencyError([dependency_type])
raise CyclicDependencyError([dependency_type]) from None
else:
dependency_requirements.append(dependency_requirement)
super().__init__(*dependency_requirements)
Expand All @@ -89,11 +89,9 @@ def summary(self) -> Str:
dependent_label=format_extension_type(self._dependent_type),
dependency_labels=Str.call(
lambda localizer: ", ".join(
map(
lambda extension_type: format_extension_type(
extension_type
).localize(localizer),
self._dependent_type.depends_on(),
(
format_extension_type(extension_type).localize(localizer)
for extension_type in self._dependent_type.depends_on()
),
),
),
Expand Down Expand Up @@ -320,10 +318,7 @@ def __contains__(self, extension_type: type[Extension] | str) -> bool:
extension_type = import_any(extension_type)
except ImportError:
return False
for extension in self.flatten():
if type(extension) is extension_type:
return True
return False
return any(type(extension) is extension_type for extension in self.flatten())


class ExtensionDispatcher(Dispatcher):
Expand Down
20 changes: 19 additions & 1 deletion betty/assets/betty.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-05-18 19:57+0100\n"
"POT-Creation-Date: 2024-05-20 14:26+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -112,6 +112,9 @@ msgstr ""
msgid "About Betty"
msgstr ""

msgid "Access denied"
msgstr ""

#, python-format
msgid "Accessed %(date)s"
msgstr ""
Expand Down Expand Up @@ -455,6 +458,15 @@ msgstr ""
msgid "I'm sorry, dear, but it seems there are no sources."
msgstr ""

msgid "I'm sorry, dear, but it seems this page does not exist."
msgstr ""

msgid "I'm sorry, dear, but it seems you're not allowed to view this page."
msgstr ""

msgid "I'm sorry, dear, but it seems you're not logged in."
msgstr ""

msgid "Immigration"
msgstr ""

Expand Down Expand Up @@ -566,6 +578,9 @@ msgstr ""
msgid "Output more detailed logs and disable optimizations that make debugging harder."
msgstr ""

msgid "Page not found"
msgstr ""

msgid "People"
msgstr ""

Expand Down Expand Up @@ -835,6 +850,9 @@ msgstr ""
msgid "URLs look like <code>/path</code> instead of <code>/path/index.html</code>. This requires a web server that supports it."
msgstr ""

msgid "Unauthorized"
msgstr ""

msgid "Unknown"
msgstr ""

Expand Down
20 changes: 19 additions & 1 deletion betty/assets/locale/de-DE/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-05-18 19:57+0100\n"
"POT-Creation-Date: 2024-05-20 15:17+0100\n"
"PO-Revision-Date: 2024-02-08 13:24+0000\n"
"Last-Translator: Bart Feenstra <bart@bartfeenstra.com>\n"
"Language: de\n"
Expand Down Expand Up @@ -164,6 +164,9 @@ msgstr "Über"
msgid "About Betty"
msgstr "Über Betty"

msgid "Access denied"
msgstr ""

#, python-format
msgid "Accessed %(date)s"
msgstr "Zugriff %(date)s"
Expand Down Expand Up @@ -621,6 +624,15 @@ msgstr "Es tut mir leid, aber sieht so aus, als ob es keine Orte gibt."
msgid "I'm sorry, dear, but it seems there are no sources."
msgstr "Es tut mir leid, aber sieht so aus, als ob es keine Quellen gibt."

msgid "I'm sorry, dear, but it seems this page does not exist."
msgstr ""

msgid "I'm sorry, dear, but it seems you're not allowed to view this page."
msgstr ""

msgid "I'm sorry, dear, but it seems you're not logged in."
msgstr ""

msgid "Immigration"
msgstr "Einwanderung"

Expand Down Expand Up @@ -736,6 +748,9 @@ msgstr ""
"Ausgabe detaillierterer Protokolle und deaktivieren von Optimierungen, "
"die die Fehlersuche erschweren."

msgid "Page not found"
msgstr ""

msgid "People"
msgstr "Personen"

Expand Down Expand Up @@ -1064,6 +1079,9 @@ msgstr ""
"<code>/path/index.html</code>. Die erfordert einen Webserver, der das "
"unterstützt."

msgid "Unauthorized"
msgstr ""

msgid "Unknown"
msgstr "Unbekannt"

Expand Down
20 changes: 19 additions & 1 deletion betty/assets/locale/fr-FR/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-05-18 19:57+0100\n"
"POT-Creation-Date: 2024-05-20 15:17+0100\n"
"PO-Revision-Date: 2024-02-08 13:24+0000\n"
"Last-Translator: Bart Feenstra <bart@bartfeenstra.com>\n"
"Language: fr\n"
Expand Down Expand Up @@ -138,6 +138,9 @@ msgstr "A propos"
msgid "About Betty"
msgstr ""

msgid "Access denied"
msgstr ""

#, python-format
msgid "Accessed %(date)s"
msgstr "Accédé le %(date)s"
Expand Down Expand Up @@ -537,6 +540,15 @@ msgstr ""
msgid "I'm sorry, dear, but it seems there are no sources."
msgstr ""

msgid "I'm sorry, dear, but it seems this page does not exist."
msgstr ""

msgid "I'm sorry, dear, but it seems you're not allowed to view this page."
msgstr ""

msgid "I'm sorry, dear, but it seems you're not logged in."
msgstr ""

msgid "Immigration"
msgstr "Immigration"

Expand Down Expand Up @@ -650,6 +662,9 @@ msgid ""
"harder."
msgstr ""

msgid "Page not found"
msgstr ""

msgid "People"
msgstr "Individu"

Expand Down Expand Up @@ -953,6 +968,9 @@ msgid ""
"it."
msgstr ""

msgid "Unauthorized"
msgstr ""

msgid "Unknown"
msgstr "Inconnu"

Expand Down

0 comments on commit d26193a

Please sign in to comment.