Skip to content

Commit

Permalink
Merge pull request #14 from samhaswon/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
samhaswon authored Dec 4, 2024
2 parents 23d98c4 + e75f82f commit aff9aeb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 52 deletions.
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build:
py -m build

install: dist/multi_bible_search-2.1.1.tar.gz
pip install --force-reinstall ./dist/multi_bible_search-2.1.1.tar.gz
install: dist/multi_bible_search-2.1.2.tar.gz
pip install --force-reinstall ./dist/multi_bible_search-2.1.2.tar.gz
copy venv\\Lib\\site-packages\\multi_bible_search\\*.pyd src\\multi_bible_search\\

full: build install
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "multi_bible_search"
version = "2.1.1"
version = "2.1.2"
authors = [
{ name="Samuel Howard" },
]
Expand Down
49 changes: 0 additions & 49 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,9 @@
Set up the multi-bible-search extension.
"""
import os
from typing import List, Tuple
from urllib import request

# pylint: disable=import-error
from setuptools import setup, Extension
from setuptools.command.build_py import build_py


# pylint: disable=too-few-public-methods
class CustomBuild(build_py):
"""
Custom build to download indices at build time from GitHub LFS
"""
indexes = [
"ACV.json.pbz2", "AKJV.json.pbz2", "AllEng.json.pbz2", "AllEs.json.pbz2", "AMP.json.pbz2",
"ASV.json.pbz2", "BBE.json.pbz2", "BSB.json.pbz2", "BTX3.json.pbz2", "CSB.json.pbz2",
"Darby.json.pbz2", "DRA.json.pbz2", "Dynamic.json.pbz2", "EBR.json.pbz2", "EsRV.json.pbz2",
"ESV.json.pbz2", "ExtraEng.json.pbz2", "GNV.json.pbz2", "KJV%201611.json.pbz2",
"KJV-like.json.pbz2", "KJV.json.pbz2", "Literal.json.pbz2", "Literal2.json.pbz2",
"LSV.json.pbz2", "MSG.json.pbz2", "NASB%201995.json.pbz2", "NET.json.pbz2",
"NIV%201984.json.pbz2", "NIV%202011.json.pbz2", "NIV.json.pbz2", "NKJV.json.pbz2",
"NLT.json.pbz2", "RNKJV.json.pbz2", "RSV.json.pbz2", "RV1960.json.pbz2",
"RV2004.json.pbz2", "RWV.json.pbz2", "UKJV.json.pbz2", "WEB.json.pbz2", "YLT.json.pbz2",
]
__index_file_urls: List[Tuple[str, str]] = \
[
(f"https://github.com/samhaswon/bible_search/"
f"raw/refs/heads/main/src/multi_bible_search/data/{x}",
x
)
for x in indexes
]

def run(self):
"""
Build the module
"""
# Perform the normal build
super().run()

# Custom logic: Download files
download_folder = os.path.join(self.build_lib, "multi_bible_search", "data")
os.makedirs(download_folder, exist_ok=True)
# file_url = "https://example.com/somefile.txt"
# destination = os.path.join(download_folder, "somefile.txt")

for file_url, destination in self.__index_file_urls:
print(f"Downloading {file_url} to {destination}")
request.urlretrieve(file_url, destination)


if os.name == "nt":
Expand All @@ -73,7 +27,4 @@ def run(self):
extra_compile_args=flags,
)
],
cmdclass={
"build_py": CustomBuild, # Override the build_py step
},
)
33 changes: 33 additions & 0 deletions src/multi_bible_search/bible_downloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
from typing import List, Tuple
from urllib import request


class BibleDownloader:
indexes = [
"ACV.json.pbz2", "AKJV.json.pbz2", "AllEng.json.pbz2", "AllEs.json.pbz2", "AMP.json.pbz2",
"ASV.json.pbz2", "BBE.json.pbz2", "BSB.json.pbz2", "BTX3.json.pbz2", "CSB.json.pbz2",
"Darby.json.pbz2", "DRA.json.pbz2", "Dynamic.json.pbz2", "EBR.json.pbz2", "EsRV.json.pbz2",
"ESV.json.pbz2", "ExtraEng.json.pbz2", "GNV.json.pbz2", "KJV%201611.json.pbz2",
"KJV-like.json.pbz2", "KJV.json.pbz2", "Literal.json.pbz2", "Literal2.json.pbz2",
"LSV.json.pbz2", "MSG.json.pbz2", "NASB%201995.json.pbz2", "NET.json.pbz2",
"NIV%201984.json.pbz2", "NIV%202011.json.pbz2", "NIV.json.pbz2", "NKJV.json.pbz2",
"NLT.json.pbz2", "RNKJV.json.pbz2", "RSV.json.pbz2", "RV1960.json.pbz2",
"RV2004.json.pbz2", "RWV.json.pbz2", "UKJV.json.pbz2", "WEB.json.pbz2", "YLT.json.pbz2",
]
__index_file_urls: List[Tuple[str, str]] = \
[
(f"https://github.com/samhaswon/bible_search/"
f"raw/refs/heads/main/src/multi_bible_search/data/{x}",
x
)
for x in indexes
]

def download(self):
base_dir = os.path.join(__file__[:-19], "data")
os.makedirs(base_dir, exist_ok=True)
for file_url, destination in self.__index_file_urls:
destination = os.path.join(base_dir, destination.replace("%20", " "))
print(f"Downloading {file_url} to {destination}")
request.urlretrieve(file_url, destination)
12 changes: 12 additions & 0 deletions src/multi_bible_search/bible_search_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ def __init__(self, preload: Union[List[str], None] = None):
# (C) Search object
self.__c_search = cBibleSearch()

try:
if len(os.listdir(os.path.join(__file__[:-23], "data"))) < 40:
from .bible_downloader import BibleDownloader

downloader = BibleDownloader()
downloader.download()
except FileNotFoundError:
from .bible_downloader import BibleDownloader

downloader = BibleDownloader()
downloader.download()

# Common sets
self.__dynamic: set = {"CSB", "NLT", "NET"}
self.__kjv_like: set = {"AKJV", "GNV", "KJV", "KJV 1611", "RNKJV", "UKJV"}
Expand Down

0 comments on commit aff9aeb

Please sign in to comment.