44sys .path .append (os .environ .get ("BBLAB_UTIL_PATH" , "fail" ))
55
66import io
7- import html
87import traceback
98from pathlib import Path
10- from typing import Tuple
119
1210# Add the parent directory to sys.path to enable isoforms_plot imports
1311CURDIR = Path (__file__ ).parent .absolute ()
2018
2119
2220# -- Utility helpers -------------------------------------------------------
23- def _read_csv_text (csv_data ) -> Tuple [ str , str ] :
21+ def _read_csv_text (csv_data ) -> str :
2422 """Return CSV text or (None, error_message)."""
25- try :
26- if hasattr (csv_data , "read" ):
27- raw = csv_data .read ()
28- if isinstance (raw , bytes ):
29- raw = raw .decode ("utf8" )
30- return raw , ""
31- # allow path-like input
32- text = Path (csv_data ).read_text (encoding = "utf8" )
33- return text , ""
34- except Exception as exc :
35- return "" , f"Could not read input CSV: { html .escape (str (exc ))} "
23+ if hasattr (csv_data , "read" ):
24+ raw = csv_data .read ()
25+ if isinstance (raw , bytes ):
26+ raw = raw .decode ("utf8" )
27+ return raw
28+ # allow path-like input
29+ text = Path (csv_data ).read_text (encoding = "utf8" )
30+ return text
3631
3732
3833def get_default_csv () -> str :
@@ -46,7 +41,7 @@ def get_default_csv() -> str:
4641# -- Main runner ----------------------------------------------------------
4742
4843
49- def run (csv_data ):
44+ def run (csv_file ):
5045 """Orchestrate plotting. Returns dict with results.
5146
5247 Returns:
@@ -57,17 +52,17 @@ def run(csv_data):
5752 - 'error_details': str (if not success, traceback)
5853 """
5954
60- # Read CSV text
61- csv_text , read_err = _read_csv_text (csv_data )
62- if read_err :
63- return {"success" : False , "error_message" : read_err , "error_details" : None }
64-
6555 # Try to generate plot - all validation happens in the plotter
6656 try :
6757 import isoforms_plot .parser as parser
6858 import isoforms_plot .compiler as compiler
6959 import isoforms_plot .plotter as plotter
7060
61+ # Read CSV text
62+ file_bytes = csv_file .read ()
63+ csv_data = file_bytes .decode ("utf-8" )
64+ csv_text = _read_csv_text (csv_data )
65+
7166 # Parse
7267 input_stream = io .StringIO (csv_text )
7368 parsed = parser .parse (input_stream )
0 commit comments