@@ -330,9 +330,9 @@ def parse_dimension(spec: str) -> float:
330330class PathConfig (TypedDict ):
331331 """Path configuration options."""
332332
333- data : str
334- pythonpath : str
335- extra_imports : str
333+ data : set [ Path ]
334+ pythonpath : set [ Path ]
335+ extra_imports : set [ Path ]
336336
337337
338338class PGFUtilsConfig (TypedDict ):
@@ -393,7 +393,9 @@ def __init__(self, load_file: bool = True) -> None:
393393 directory and load it after setting the defaults.
394394
395395 """
396- self .paths = dict (data = "." , pythonpath = "" , extra_imports = "" )
396+ self .paths = dict (
397+ data = {Path .cwd ().resolve ()}, pythonpath = set (), extra_imports = set ()
398+ )
397399 self .pgfutils = dict (
398400 preamble = "" ,
399401 preamble_substitute = False ,
@@ -531,6 +533,17 @@ def update(self, new_settings: Mapping[str, Mapping[str, Any]]):
531533 )
532534 section [key ] = val
533535
536+ # For a set, handle based on the type of the set items.
537+ elif origin is set :
538+ if not isinstance (val , (set , list , tuple )):
539+ raise ConfigError (name , key , "value must be a list" )
540+
541+ if args == (Path ,):
542+ for item in val :
543+ section [key ].add (Path (item ).resolve ())
544+ else :
545+ raise RuntimeError (f"unhandled set type { args } " )
546+
534547 # Assume a string.
535548 else :
536549 section [key ] = val
@@ -557,19 +570,17 @@ def in_tracking_dir(type, fn):
557570
558571 """
559572 if type == "data" :
560- paths = config .paths ["data" ]. strip (). splitlines ()
573+ paths = config .paths ["data" ]
561574 elif type == "import" :
562- paths = config .paths ["pythonpath" ].strip ().splitlines ()
563- paths .extend (config .paths ["extra_imports" ].strip ().splitlines ())
575+ paths = config .paths ["pythonpath" ].union (config .paths ["extra_imports" ])
564576 else :
565577 raise ValueError (f"Unknown tracking type { type } ." )
566578
567579 # If we can compute a relative path, it must be within the directory.
568580 fn = Path (fn ).resolve ()
569581 for path in paths :
570- resolved = Path (path ).resolve ()
571582 try :
572- fn .relative_to (resolved )
583+ fn .relative_to (path )
573584 except ValueError :
574585 continue
575586 return True
@@ -737,10 +748,8 @@ def setup_figure(
737748 _interactive = True
738749
739750 # Add any desired entries to sys.path.
740- for newpath in config .paths ["pythonpath" ].splitlines ():
741- newpath = newpath .strip ()
742- if newpath :
743- sys .path .insert (0 , newpath )
751+ for newpath in config .paths ["pythonpath" ]:
752+ sys .path .insert (0 , str (newpath ))
744753
745754 # Set the backend. We don't want to overwrite the current backend if this is an
746755 # interactive run as the PGF backend does not implement a GUI.
0 commit comments