Restructure project into kjvstudy package

- Move kjv.py and server files into kjvstudy package directory
- Add package __init__.py with module imports
- Move tests to tests/ directory with path configuration
- Add .envrc to prevent Python bytecode generation
- Update imports to use relative imports within package
- Create global bible instance for reuse across modules
This commit is contained in:
2025-05-26 12:35:20 -04:00
parent 2b1738668d
commit 61ce5521a8
6 changed files with 38 additions and 27 deletions
+1
View File
@@ -0,0 +1 @@
export PYTHONDONTWRITEBYTECODE=1
+2
View File
@@ -0,0 +1,2 @@
from . import kjv
from . import server
View File
+25 -22
View File
@@ -1,8 +1,11 @@
import json
from pydantic import BaseModel
import json
class Bible:
"""Represents a Bible."""
def __init__(self, fname=None):
self.fname = fname or "verses-1769.json"
@@ -11,9 +14,7 @@ class Bible:
self.verses = json.load(f)
def __getitem__(self, verse):
"""
Returns the text of the verse.
"""
"""Returns the text of the verse."""
# Check if the verse exists in the dictionary.
if verse not in self.verses:
@@ -22,24 +23,30 @@ class Bible:
return self.verses[verse]
def iter_verses(self):
"""
Iterates over the verses in the Bible.
"""
"""Iterates over the verses in the Bible."""
for verse in self.verses:
verse_ref = VerseReference.from_string(verse)
# Remove the leading "# " and brackets from the text.
# This is a workaround for the JSON format.
# The text is stored as a string with leading "# " and brackets.
# Example: "# [In the beginning God created the heaven and the earth.]"
text = self.verses[verse]
text.replace("# ", "")
text.replace("[", "")
text.replace("]", "")
yield Verse(
book=verse_ref.book,
chapter=verse_ref.chapter,
verse=verse_ref.verse,
text=self.verses[verse],
text=text,
)
def iter_books(self):
"""
Iterates over the books in the Bible.
"""
"""Iterates over the books in the Bible."""
yielded = set()
for verse in self.verses:
@@ -50,9 +57,7 @@ class Bible:
yield verse_ref.book
def iter_chapters(self):
"""
Iterates over the chapters in the Bible.
"""
"""Iterates over the chapters in the Bible."""
yielded = set()
@@ -64,9 +69,7 @@ class Bible:
yield verse_ref.book, verse_ref.chapter
def iter_chapters_by_book(self):
"""
Iterates over the chapters in the Bible, grouped by book.
"""
"""Iterates over the chapters in the Bible, grouped by book."""
yielded = set()
@@ -78,9 +81,7 @@ class Bible:
yield verse_ref.book, verse_ref.chapter
def iter_verse_references(self):
"""
Iterates over the verse references in the Bible.
"""
"""Iterates over the verse references in the Bible."""
for verse in self.verses:
yield VerseReference.from_string(verse)
@@ -123,14 +124,16 @@ class VerseReference(BaseModel):
return cls(book=book, chapter=int(chapter), verse=int(verse))
# Create an instance of the Bible class.
bible = Bible()
if __name__ == "__main__":
print(VerseReference.from_string("Genesis 1:1"))
print(VerseReference.from_string("I Corinthians 1:1"))
print(VerseReference.from_string("John 3:16"))
bible = Bible()
print(bible["Genesis 1:1"])
# print()
# print(verse)
+3 -3
View File
@@ -2,7 +2,9 @@ from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import kjv # assuming your kjv module is available and contains the Bible class
from .kjv import bible
app = FastAPI()
@@ -10,8 +12,6 @@ app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
bible = kjv.Bible()
@app.get("/", response_class=HTMLResponse)
def read_root(request: Request):
+7 -2
View File
@@ -1,6 +1,11 @@
def test_verse_references():
from kjv import VerseReference
# PATH HACK
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from kjvstudy.kjv import VerseReference
def test_verse_references():
# Test the parsing of a verse reference string
assert VerseReference.from_string("Genesis 1:1") == VerseReference(
book="Genesis", chapter=1, verse=1