Skip to content

Commit 93f00d6

Browse files
authored
use RUFF for static code analysis (possibly to eventually replace flake8) (#92)
* use RUFF for static code analysis (possibly to eventually replace flake8) * oops... * ignore if TYPE_CHECKING blocks for test coverage * version 0.9.1
1 parent 1cb85b1 commit 93f00d6

25 files changed

Lines changed: 203 additions & 118 deletions

.coveragerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[report]
2+
exclude_lines =
3+
pragma: no cover
4+
if TYPE_CHECKING:

.pre-commit-config.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ repos:
88
- id: debug-statements
99
- id: name-tests-test
1010
- id: requirements-txt-fixer
11+
- repo: https://github.com/charliermarsh/ruff-pre-commit
12+
rev: 'v0.0.265'
13+
hooks:
14+
- id: ruff
15+
args: [ --fix, --exit-non-zero-on-fix ]
1116
- repo: https://github.com/psf/black
1217
rev: 23.3.0
1318
hooks:
@@ -50,10 +55,12 @@ exclude: |
5055
pythonbible/bible/asv/plain_text.py|
5156
pythonbible/bible/asv/plain_text_notes.py|
5257
pythonbible/bible/asv/plain_text_readers.py|
58+
pythonbible/bible/asv/titles.py|
5359
pythonbible/bible/kjv/html.py|
5460
pythonbible/bible/kjv/html_notes.py|
5561
pythonbible/bible/kjv/html_readers.py|
5662
pythonbible/bible/kjv/plain_text.py|
5763
pythonbible/bible/kjv/plain_text_notes.py|
58-
pythonbible/bible/kjv/plain_text_readers.py
64+
pythonbible/bible/kjv/plain_text_readers.py|
65+
pythonbible/bible/kjv/titles.py
5966
)$

docs/source/__init__.py

Whitespace-only changes.

docs/source/conf.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
# add these directories to sys.path here. If the directory is relative to the
1212
# documentation root, use os.path.abspath to make it absolute, like shown here.
1313
#
14-
# import os
15-
# import sys
16-
# sys.path.insert(0, os.path.abspath('.'))
1714

1815

1916
# -- Project information -----------------------------------------------------
@@ -23,7 +20,7 @@
2320
author = "Nathan Patton"
2421

2522
# The full version, including alpha/beta/rc tags
26-
release = "0.9"
23+
release = "0.9.1"
2724

2825

2926
# -- General configuration ---------------------------------------------------

pyproject.toml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,80 @@ dev = [
4949
profile = "black"
5050
add_imports = "from __future__ import annotations"
5151
force_single_line = true
52+
53+
[tool.ruff]
54+
select = [
55+
"A",
56+
"ANN",
57+
"ARG",
58+
"B",
59+
"BLE",
60+
"COM",
61+
"C4",
62+
"C90",
63+
"D",
64+
"DTZ",
65+
"E",
66+
"EM",
67+
"ERA",
68+
"EXE",
69+
"F",
70+
"FBT",
71+
"G",
72+
"I",
73+
"ICN",
74+
"INP",
75+
"ISC",
76+
"N",
77+
"NPY",
78+
"PD",
79+
"PGH",
80+
"PIE",
81+
"PL",
82+
"PT",
83+
"PTH",
84+
"PYI",
85+
"Q",
86+
"RET",
87+
"RSE",
88+
"RUF",
89+
"S",
90+
"SIM",
91+
"SLF",
92+
"TCH",
93+
"TID",
94+
"TRY",
95+
"T10",
96+
"T20",
97+
"W",
98+
]
99+
ignore = [
100+
"D100",
101+
"D101",
102+
"D102",
103+
"D103",
104+
"D104",
105+
"D205",
106+
"D203",
107+
"D213",
108+
]
109+
fix = true
110+
111+
[tool.ruff.per-file-ignores]
112+
"docs/source/conf.py" = ["A001", "E501"]
113+
"pythonbible/__init__.py" = ["F401"]
114+
"pythonbible/bible/bible.py" = ["PLR0913", "FBT"]
115+
"pythonbible/counters/book_counter.py" = ["TCH001"]
116+
"pythonbible/counters/chapter_counter.py" = ["TCH001"]
117+
"pythonbible/counters/verse_counter.py" = ["TCH001"]
118+
"pythonbible/errors.py" = ["PLR0913"]
119+
"pythonbible/formatter.py" = ["ANN401", "FBT", "PLR0911"]
120+
"pythonbible/parser.py" = ["PLR2004"]
121+
"pythonbible/regular_expressions.py" = ["ISC001"]
122+
"pythonbible/roman_numeral_util.py" = ["E741"]
123+
"tests/*.py" = ["D100", "D103", "D104", "PLR2004", "S101", "TRY301"]
124+
"tests/conftest.py" = ["E501", "RUF"]
125+
"tests/errors_test.py" = ["PT017"]
126+
127+
[tool.ruff.isort]
128+
force-single-line = true

pythonbible/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
The pythonbible library.
1+
"""The pythonbible library.
32
43
pythonbible includes features for parsing texts for scripture references,
54
converting references into integer verse ids for efficient use/storage,
@@ -9,7 +8,7 @@
98

109
from __future__ import annotations
1110

12-
__version__ = "0.9"
11+
__version__ = "0.9.1"
1312

1413
from .bible.bible import Bible
1514
from .book_groups import BOOK_GROUPS

pythonbible/bible/bible.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
from __future__ import annotations
33

44
from functools import lru_cache
5+
from typing import TYPE_CHECKING
56

67
from pythonbible.errors import InvalidVerseError
78
from pythonbible.validator import is_valid_verse_id
8-
from pythonbible.versions import Version
9+
10+
if TYPE_CHECKING:
11+
from pythonbible.versions import Version
912

1013

1114
class Bible:
12-
"""
13-
The Bible class.
15+
"""The Bible class.
1416
1517
The Bible class contains the scripture content for a version and format along with
1618
the functionality necessary to get the scripture content for a verse or range of
@@ -25,26 +27,34 @@ def __init__(
2527
verse_end_indices: dict[int, int],
2628
is_html: bool = False,
2729
) -> None:
30+
"""Initialize a Bible object.
31+
32+
:param version: The version of the Bible.
33+
:param scripture_content: The scripture content for the Bible.
34+
:param verse_start_indices: The start indices for each verse.
35+
:param verse_end_indices: The end indices for each verse.
36+
"""
2837
self.version: Version = version
2938
self.scripture_content: str = scripture_content
3039
self.verse_start_indices: dict[int, int] = verse_start_indices
3140
self.verse_end_indices: dict[int, int] = verse_end_indices
3241
self.is_html: bool = is_html
3342

34-
@lru_cache()
3543
def get_scripture(
3644
self: Bible,
3745
start_verse_id: int,
3846
end_verse_id: int | None = None,
3947
) -> str:
4048
if not is_valid_verse_id(start_verse_id):
49+
msg = f"start verse id ({start_verse_id}) is not a valid verse id."
4150
raise InvalidVerseError(
42-
f"start verse id ({start_verse_id}) is not a valid verse id.",
51+
msg,
4352
)
4453

4554
if end_verse_id and not is_valid_verse_id(end_verse_id):
55+
msg = f"end verse id ({end_verse_id}) is not a valid verse id."
4656
raise InvalidVerseError(
47-
f"end verse id ({end_verse_id}) is not a valid verse id.",
57+
msg,
4858
)
4959

5060
end_verse_id = end_verse_id or start_verse_id

pythonbible/bible/bibles.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import TYPE_CHECKING
4+
35
import pythonbible.bible.asv.html as asv_html
46
import pythonbible.bible.asv.html_notes as asv_html_notes
57
import pythonbible.bible.asv.html_readers as asv_html_readers
@@ -12,10 +14,12 @@
1214
import pythonbible.bible.kjv.plain_text as kjv_plain_text
1315
import pythonbible.bible.kjv.plain_text_notes as kjv_plain_text_notes
1416
import pythonbible.bible.kjv.plain_text_readers as kjv_plain_text_readers
15-
from pythonbible.bible.bible import Bible
1617
from pythonbible.errors import MissingVerseFileError
1718
from pythonbible.versions import Version
1819

20+
if TYPE_CHECKING:
21+
from pythonbible.bible.bible import Bible
22+
1923
BIBLES = {
2024
Version.AMERICAN_STANDARD: {
2125
"html": asv_html.bible,
@@ -37,8 +41,7 @@
3741

3842

3943
def get_bible(version: Version, bible_type: str) -> Bible:
40-
"""
41-
Return the Bible for the given version and format.
44+
"""Return the Bible for the given version and format.
4245
4346
:param version: The version of the Bible
4447
:type version: Version
@@ -50,4 +53,4 @@ def get_bible(version: Version, bible_type: str) -> Bible:
5053
try:
5154
return BIBLES[version][bible_type]
5255
except KeyError as e:
53-
raise MissingVerseFileError() from e
56+
raise MissingVerseFileError from e

pythonbible/book_groups.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99

1010
class BookGroup(Enum):
11-
"""
12-
BookGroup is an ``Enum`` containing the default Bible book groupings.
11+
"""BookGroup is an ``Enum`` containing the default Bible book groupings.
1312
1413
:param name: the unique text identifier of the book group
1514
:type name: str

pythonbible/books.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66

77
class Book(IntEnum):
8-
"""
9-
Book is an IntEnum that contains all of the books of the Bible.
8+
"""Book is an IntEnum that contains all of the books of the Bible.
109
1110
:param name: the unique text identifier of the book
1211
:type name: str

0 commit comments

Comments
 (0)