diff --git a/pageindex/index/page_index.py b/pageindex/index/page_index.py index 17cc7e4..f284243 100644 --- a/pageindex/index/page_index.py +++ b/pageindex/index/page_index.py @@ -1089,7 +1089,7 @@ async def tree_parser(page_list, opt, doc=None, logger=None): def page_index_main(doc, opt=None): # accept legacy 'yes'/'no' string flags (a bare 'no' is truthy) - from .page_index_md import _coerce_bool + from .utils import _coerce_bool for flag in ('if_add_node_id', 'if_add_node_text', 'if_add_node_summary', 'if_add_doc_description'): if hasattr(opt, flag): diff --git a/pageindex/index/page_index_md.py b/pageindex/index/page_index_md.py index 31eaf14..5a3b2c9 100644 --- a/pageindex/index/page_index_md.py +++ b/pageindex/index/page_index_md.py @@ -3,6 +3,7 @@ import json import re import os from .utils import * +from .utils import _coerce_bool # underscore names aren't star-exported async def get_node_summary(node, summary_token_threshold=200, model=None): node_text = node.get('text') @@ -243,13 +244,6 @@ def clean_tree_for_output(tree_nodes): return cleaned_nodes -def _coerce_bool(value): - """Coerce a legacy 'yes'/'no' string flag to bool (a bare 'no' is truthy).""" - if isinstance(value, str): - return value.strip().lower() in ("yes", "true", "1", "y", "on") - return bool(value) - - async def md_to_tree(md_path, if_thinning=False, min_token_threshold=None, if_add_node_summary=False, summary_token_threshold=None, model=None, if_add_doc_description=False, if_add_node_text=False, if_add_node_id=True): # Accept legacy 'yes'/'no' string flags — a bare 'no' would otherwise be # truthy and wrongly enable the option. diff --git a/pageindex/index/utils.py b/pageindex/index/utils.py index 75db970..7efd0dd 100644 --- a/pageindex/index/utils.py +++ b/pageindex/index/utils.py @@ -941,6 +941,13 @@ def add_node_text_with_labels(node, pdf_pages): return +def _coerce_bool(value): + """Coerce a legacy 'yes'/'no' string flag to bool (a bare 'no' is truthy).""" + if isinstance(value, str): + return value.strip().lower() in ("yes", "true", "1", "y", "on") + return bool(value) + + class ConfigLoader: """Legacy 0.2.x config helper. Defaults now come from IndexConfig; this class no longer reads the packaged ``config.yaml`` (the CLI still uses it diff --git a/run_pageindex.py b/run_pageindex.py index faf7ba7..38b6a29 100644 --- a/run_pageindex.py +++ b/run_pageindex.py @@ -6,7 +6,8 @@ from pageindex.index.page_index import * # a bare ``--flag`` (no value) resolves to True via argparse's ``const``; an # explicit value keeps the legacy yes/no style working, so ``--flag no`` turns # it off. argparse only ever passes a str here (const/default bypass type=). -from pageindex.index.page_index_md import md_to_tree, _coerce_bool as _cli_bool +from pageindex.index.page_index_md import md_to_tree +from pageindex.index.utils import _coerce_bool as _cli_bool from pageindex.config import IndexConfig