diff --git a/makefile b/makefile index 084c757..2a4d2d6 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 255ce98..efd7ce8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }, ] diff --git a/setup.py b/setup.py index 315b585..84edd93 100644 --- a/setup.py +++ b/setup.py @@ -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": @@ -73,7 +27,4 @@ def run(self): extra_compile_args=flags, ) ], - cmdclass={ - "build_py": CustomBuild, # Override the build_py step - }, ) diff --git a/src/multi_bible_search/bible_downloader.py b/src/multi_bible_search/bible_downloader.py new file mode 100644 index 0000000..ddeb61e --- /dev/null +++ b/src/multi_bible_search/bible_downloader.py @@ -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) diff --git a/src/multi_bible_search/bible_search_adapter.py b/src/multi_bible_search/bible_search_adapter.py index ea112d6..cc1d698 100644 --- a/src/multi_bible_search/bible_search_adapter.py +++ b/src/multi_bible_search/bible_search_adapter.py @@ -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"}