Relative imports in clean-text-to-keywords break when used as a module #11

Open
opened 2026-03-19 17:30:41 +00:00 by llabeyrie · 0 comments
Owner

Description

clean-text-to-keywords/infer_json_usage.py lines 7-8 use bare imports:

from keyword_extractor import KeywordExtractor
from json_inference import fill_template_from_keywords

Problem

  • Works when run directly as python infer_json_usage.py (directory is in sys.path)
  • Breaks when imported from the parent directory or by prompt_to_card_pipeline.py which calls it via subprocess
  • The subprocess approach in the pipeline works around this, but it means these modules can never be used as a proper Python package

Fix

Either:

  1. Add an __init__.py and use relative imports: from .keyword_extractor import ...
  2. Or add the directory to sys.path at the top of the script
  3. Long-term: restructure as a proper Python package (see structure issues)
## Description `clean-text-to-keywords/infer_json_usage.py` lines 7-8 use bare imports: ```python from keyword_extractor import KeywordExtractor from json_inference import fill_template_from_keywords ``` ### Problem - Works when run directly as `python infer_json_usage.py` (directory is in `sys.path`) - **Breaks** when imported from the parent directory or by `prompt_to_card_pipeline.py` which calls it via subprocess - The subprocess approach in the pipeline works around this, but it means these modules can never be used as a proper Python package ### Fix Either: 1. Add an `__init__.py` and use relative imports: `from .keyword_extractor import ...` 2. Or add the directory to `sys.path` at the top of the script 3. Long-term: restructure as a proper Python package (see structure issues)
llabeyrie added the priority: mediumstructure labels 2026-03-19 17:31:46 +00:00
Sign in to join this conversation.