11# -*- coding: UTF-8 -*-
2- import re
3- from itertools import chain
4- from termcolor import colored
5- from tinyscript .helpers import is_function , BorderlessTable , Path
6-
72from .logger import *
83
94
@@ -94,15 +89,17 @@ def __str__(self):
9489 continue
9590 r = ["N" , "Y" ][r ]
9691 if v == "" :
92+ from tinyscript .helpers import colored
9793 n , v , r = map (lambda s : colored (s , "red" , attrs = ['bold' ]), [n , v , r ])
9894 data .append ([n , v , r , d ])
9995 if len (data ) > 1 :
96+ from tinyscript .helpers import BorderlessTable
10097 try :
10198 prefix = self .console .opt_prefix
10299 except AttributeError :
103100 prefix = None
104101 return BorderlessTable (data ).table if prefix is None else \
105- BorderlessTable (data , "%s options" % prefix ).table
102+ BorderlessTable (data , f" { prefix } options" ).table
106103 return ""
107104
108105 def __run_callback (self , key , name ):
@@ -181,6 +178,7 @@ def items(self, fail=True):
181178
182179 def keys (self , glob = False ):
183180 """ Return string keys (like original dict). """
181+ from itertools import chain
184182 l = [k for k in self ._d .keys ()]
185183 if glob :
186184 for k in chain (self ._d .keys (), Config ._g .keys ()):
@@ -325,6 +323,7 @@ def bind(self, parent):
325323 @property
326324 def choices (self ):
327325 """ Pre- or lazy-computed list of choices. """
326+ from tinyscript .helpers import is_function
328327 c = self ._choices
329328 if not is_function (c ):
330329 return c
@@ -369,9 +368,11 @@ def value(self):
369368 value = Config ._g .get (self .name , value )
370369 if self .required and value is None :
371370 raise ValueError (f"{ self .name } must be defined" )
372- try : # try to expand format variables using console's attributes
371+ # try to expand format variables using console's attributes
372+ from re import findall
373+ try :
373374 kw = {}
374- for n in re . findall (r'\{([a-z]+)\}' , str (value )):
375+ for n in findall (r'\{([a-z]+)\}' , str (value )):
375376 kw [n ] = self .config .console .__dict__ .get (n , "" )
376377 try :
377378 value = value .format (** kw )
@@ -381,6 +382,7 @@ def value(self):
381382 pass
382383 # expand and resolve paths
383384 if self .name .endswith ("FOLDER" ) or self .name .endswith ("WORKSPACE" ):
385+ from tinyscript .helpers import Path
384386 # this will ensure that every path is expanded
385387 value = str (Path (value , expand = True ))
386388 # convert common formats to their basic types
0 commit comments