@@ -333,10 +333,12 @@ def get_corpus_path(name: str, version: str = "") -> Optional[str]:
333333 # Corpus not in local catalog; download it unless in offline mode
334334 if is_offline_mode ():
335335 raise FileNotFoundError (
336- f"Corpus '{ name } ' not found locally. "
337- f"PYTHAINLP_OFFLINE is set; automatic downloading is disabled. "
338- f"To download, unset PYTHAINLP_OFFLINE and run: "
339- f"pythainlp.corpus.download('{ name } ')"
336+ f"corpus-not-found name={ name !r} \n "
337+ f" Corpus '{ name } ' not found locally.\n "
338+ f" PYTHAINLP_OFFLINE is set; automatic downloading is disabled.\n "
339+ f" To download, unset PYTHAINLP_OFFLINE, then run:\n "
340+ f" Python: pythainlp.corpus.download('{ name } ')\n "
341+ f" CLI: thainlp data get { name } "
340342 )
341343 if not download (name , version = version ):
342344 return None
@@ -354,10 +356,12 @@ def get_corpus_path(name: str, version: str = "") -> Optional[str]:
354356 # File is registered in catalog but missing from disk
355357 if is_offline_mode ():
356358 raise FileNotFoundError (
357- f"Corpus '{ name } ' expected at '{ path } ' but file not found. "
358- f"PYTHAINLP_OFFLINE is set; automatic re-downloading is disabled. "
359- f"To re-download, unset PYTHAINLP_OFFLINE and run: "
360- f"pythainlp.corpus.download('{ name } ', force=True)"
359+ f"corpus-not-found name={ name !r} expected-path={ path !r} \n "
360+ f" Corpus '{ name } ' expected at '{ path } ' but file not found.\n "
361+ f" PYTHAINLP_OFFLINE is set; automatic re-downloading is disabled.\n "
362+ f" To re-download, unset PYTHAINLP_OFFLINE, then run:\n "
363+ f" Python: pythainlp.corpus.download('{ name } ', force=True)\n "
364+ f" CLI: thainlp data get { name } "
361365 )
362366 if not download (name , version = version , force = True ):
363367 return None
@@ -625,6 +629,12 @@ def download(
625629 The available corpus names can be seen in this file:
626630 https://pythainlp.org/pythainlp-corpus/db.json
627631
632+ This function always performs the download regardless of the
633+ ``PYTHAINLP_OFFLINE`` environment variable, because an explicit call
634+ to ``download()`` is a deliberate user action.
635+ ``PYTHAINLP_OFFLINE`` only blocks the *automatic* download triggered
636+ by :func:`pythainlp.corpus.get_corpus_path`.
637+
628638 :param str name: corpus name
629639 :param bool force: force downloading
630640 :param str url: URL of the corpus catalog
@@ -651,12 +661,7 @@ def download(
651661 if _CHECK_MODE == "1" :
652662 print ("PyThaiNLP is read-only mode. It can't download." )
653663 return False
654- if is_offline_mode ():
655- print (
656- "PYTHAINLP_OFFLINE is set. Cannot download. "
657- "To enable downloading, unset PYTHAINLP_OFFLINE."
658- )
659- return False
664+
660665 if not url :
661666 url = corpus_db_url ()
662667
@@ -833,8 +838,10 @@ def get_path_folder_corpus(name: str, version: str, *path: str) -> str:
833838 corpus_path = get_corpus_path (name , version )
834839 if not corpus_path :
835840 raise FileNotFoundError (
836- f"Corpus '{ name } ' (version { version } ) not found. "
837- f"To download: pythainlp.corpus.download('{ name } ')"
841+ f"corpus-not-found name={ name !r} version={ version !r} \n "
842+ f" Corpus '{ name } ' (version { version } ) not found.\n "
843+ f" Python: pythainlp.corpus.download('{ name } ')\n "
844+ f" CLI: thainlp data get { name } "
838845 )
839846 return os .path .join (corpus_path , * path )
840847
0 commit comments