Skip to content

Commit

Permalink
fixed file not found error when installed using pip
Browse files Browse the repository at this point in the history
  • Loading branch information
aseemsavio committed Oct 22, 2022
1 parent b05c7a0 commit 42319c8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions catholic/core/canon/canon_law.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from catholic.core.canon.services import get_canon_law_by_id, get_canon_laws_with_given_substring, \
get_canon_law_paragraphs_by_paragraph_ids
from catholic.core.utils.files import load_pickle
from catholic.core.utils.files import load_pickle_by_name
from catholic.core.utils.console import error, markdown, blue_text, red_text
from catholic.core.utils.query import decode_query


def execute_canon_command(law, search):
canon_law_dict = load_pickle("pickles/canon.pickle")
canon_law_dict = load_pickle_by_name("canon.pickle")
if law:
if law.isdigit():
_display_canon_law(canon_law_dict, law)
Expand Down
4 changes: 2 additions & 2 deletions catholic/core/catechism/catechism.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from catholic.core.catechism.services import get_catechism_by_paragraph, \
get_catechism_paragraphs_with_given_substring, get_catechism_paragraphs_by_paragraph_ids
from catholic.core.utils.files import load_pickle
from catholic.core.utils.files import load_pickle_by_name
from catholic.core.utils.console import markdown, error, blue_text, red_text

from catholic.core.utils.query import decode_query
Expand All @@ -13,7 +13,7 @@ def execute_catechism_command(paragraph, search):
:param paragraph: Paragraph_number
:return: None
"""
catechism_dict = load_pickle("pickles/catechism.pickle")
catechism_dict = load_pickle_by_name("catechism.pickle")
if paragraph:
if paragraph.isdigit():
_display_catechism_paragraph(catechism_dict, paragraph)
Expand Down
4 changes: 2 additions & 2 deletions catholic/core/missal/missal.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from catholic.core.missal.services import get_roman_missal_by_number, \
get_roman_missal_paragraphs_with_given_substring, get_roman_missal_paragraphs_by_numbers
from catholic.core.utils.files import load_pickle
from catholic.core.utils.files import load_pickle_by_name
from catholic.core.utils.console import markdown, error, blue_text, red_text
from catholic.core.utils.query import decode_query


def execute_missal_command(missal_id, search):
missal_dict = load_pickle("pickles/girm.pickle")
missal_dict = load_pickle_by_name("girm.pickle")
if missal_id:
if missal_id.isdigit():
_display_missal_paragraph(missal_dict, missal_id)
Expand Down
13 changes: 13 additions & 0 deletions catholic/core/utils/files.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import os
import pickle

from pickles import read_pickle


def load_pickle(pickle_name: str):
"""
TIP: DO NOT use this
Reads the contents of the given pickle, and returns a dict.
:param pickle_name: Name of the pickle file
:return: dict
"""
with open(pickle_name, 'rb') as handle:
return pickle.load(handle)


def load_pickle_by_name(name: str):
"""
Reads the contents of the given pickle, and returns a dict.
:param name: Name of the pickle file
:return: dict
"""
return read_pickle(name)
14 changes: 14 additions & 0 deletions pickles/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import pickle


def read_pickle(name: str) -> dict:
"""
Reads pickles by name
:param name:
:return:
"""
this_dir, _ = os.path.split(__file__)
data_path = os.path.join(this_dir, name)
with open(data_path, 'rb') as handle:
return pickle.load(handle)

0 comments on commit 42319c8

Please sign in to comment.