129129import sys
130130import traceback
131131from contextlib import contextmanager , suppress
132- from typing import IO , Any , Callable , Generator , Optional , Sequence , Dict , Tuple , TypeVar , Union , TYPE_CHECKING
132+ from typing import (
133+ IO ,
134+ Any ,
135+ Callable ,
136+ Generator ,
137+ Optional ,
138+ Sequence ,
139+ Dict ,
140+ Tuple ,
141+ TypeVar ,
142+ Union ,
143+ TYPE_CHECKING ,
144+ )
133145from weakref import WeakValueDictionary
134146
135147from . import utils , _signals
160172_STR_BYTES_PATH = Union [str , bytes , "os.PathLike[str]" , "os.PathLike[bytes]" ]
161173_CMD = Union [_STR_BYTES_PATH , Sequence [_STR_BYTES_PATH ]]
162174
175+
163176# _background_job_wrapper()
164177#
165178# Wrapper for running jobs in the background, transparently for users
172185# target: function to execute in the background
173186# args: positional arguments to give to the target function
174187#
175- def _background_job_wrapper (result_queue : multiprocessing .Queue , target : Callable [..., T1 ], args : Any ) -> None :
188+ def _background_job_wrapper (
189+ result_queue : multiprocessing .Queue , target : Callable [..., T1 ], args : Any
190+ ) -> None :
176191 result = None
177192
178193 try :
@@ -265,7 +280,8 @@ class Foo(Source):
265280
266281 try :
267282 __multiprocessing_context : Union [
268- multiprocessing .context .ForkServerContext , multiprocessing .context .SpawnContext
283+ multiprocessing .context .ForkServerContext ,
284+ multiprocessing .context .SpawnContext ,
269285 ] = multiprocessing .get_context ("forkserver" )
270286 except ValueError :
271287 # We are on a system without `forkserver` support. Let's default to
@@ -286,7 +302,6 @@ def __init__(
286302 type_tag : str ,
287303 unique_id : Optional [int ] = None ,
288304 ):
289-
290305 self .name = name
291306 """The plugin name
292307
@@ -371,7 +386,9 @@ def configure(self, node: MappingNode) -> None:
371386
372387 """
373388 raise ImplError (
374- "{tag} plugin '{kind}' does not implement configure()" .format (tag = self .__type_tag , kind = self .get_kind ())
389+ "{tag} plugin '{kind}' does not implement configure()" .format (
390+ tag = self .__type_tag , kind = self .get_kind ()
391+ )
375392 )
376393
377394 def preflight (self ) -> None :
@@ -393,7 +410,9 @@ def preflight(self) -> None:
393410 will raise an error automatically informing the user that a host tool is needed.
394411 """
395412 raise ImplError (
396- "{tag} plugin '{kind}' does not implement preflight()" .format (tag = self .__type_tag , kind = self .get_kind ())
413+ "{tag} plugin '{kind}' does not implement preflight()" .format (
414+ tag = self .__type_tag , kind = self .get_kind ()
415+ )
397416 )
398417
399418 def get_unique_key (self ) -> SourceRef :
@@ -440,7 +459,9 @@ def get_kind(self) -> str:
440459 """
441460 return self .__kind
442461
443- def node_get_project_path (self , node , * , check_is_file = False , check_is_dir = False ) -> str :
462+ def node_get_project_path (
463+ self , node , * , check_is_file = False , check_is_dir = False
464+ ) -> str :
444465 """Fetches a project path from a dictionary node and validates it
445466
446467 Paths are asserted to never lead to a directory outside of the
@@ -476,7 +497,9 @@ def node_get_project_path(self, node, *, check_is_file=False, check_is_dir=False
476497
477498 """
478499
479- return self .__project .get_path_from_node (node , check_is_file = check_is_file , check_is_dir = check_is_dir )
500+ return self .__project .get_path_from_node (
501+ node , check_is_file = check_is_file , check_is_dir = check_is_dir
502+ )
480503
481504 def debug (self , brief : str , * , detail : Optional [str ] = None ) -> None :
482505 """Print a debugging message
@@ -514,7 +537,13 @@ def info(self, brief: str, *, detail: Optional[str] = None) -> None:
514537 """
515538 self .__message (MessageType .INFO , brief , detail = detail )
516539
517- def warn (self , brief : str , * , detail : Optional [str ] = None , warning_token : Optional [str ] = None ) -> None :
540+ def warn (
541+ self ,
542+ brief : str ,
543+ * ,
544+ detail : Optional [str ] = None ,
545+ warning_token : Optional [str ] = None ,
546+ ) -> None :
518547 """Print a warning message, checks warning_token against project configuration
519548
520549 Args:
@@ -533,7 +562,9 @@ def warn(self, brief: str, *, detail: Optional[str] = None, warning_token: Optio
533562
534563 if project ._warning_is_fatal (warning_token ):
535564 detail = detail if detail else ""
536- raise PluginError (message = "{}\n {}" .format (brief , detail ), reason = warning_token )
565+ raise PluginError (
566+ message = "{}\n {}" .format (brief , detail ), reason = warning_token
567+ )
537568
538569 self .__message (MessageType .WARN , brief = brief , detail = detail )
539570
@@ -551,7 +582,11 @@ def log(self, brief: str, *, detail: Optional[str] = None) -> None:
551582
552583 @contextmanager
553584 def timed_activity (
554- self , activity_name : str , * , detail : Optional [str ] = None , silent_nested : bool = False
585+ self ,
586+ activity_name : str ,
587+ * ,
588+ detail : Optional [str ] = None ,
589+ silent_nested : bool = False ,
555590 ) -> Generator [None , None , None ]:
556591 """Context manager for performing timed activities in plugins
557592
@@ -589,7 +624,7 @@ def blocking_activity(
589624 activity_name : str ,
590625 * ,
591626 detail : Optional [str ] = None ,
592- silent_nested : bool = False
627+ silent_nested : bool = False ,
593628 ) -> T1 :
594629 """Execute a blocking activity in the background.
595630
@@ -616,7 +651,10 @@ def blocking_activity(
616651 the return value from `target`.
617652 """
618653 with self .__context .messenger .timed_activity (
619- activity_name , element_name = self ._get_full_name (), detail = detail , silent_nested = silent_nested
654+ activity_name ,
655+ element_name = self ._get_full_name (),
656+ detail = detail ,
657+ silent_nested = silent_nested ,
620658 ):
621659 result_queue = self .__multiprocessing_context .Queue ()
622660 proc = None
@@ -636,7 +674,10 @@ def resume_proc():
636674 with suppress (ProcessLookupError ):
637675 os .kill (proc .pid , signal .SIGCONT )
638676
639- with _signals .suspendable (suspend_proc , resume_proc ), _signals .terminator (kill_proc ):
677+ with (
678+ _signals .suspendable (suspend_proc , resume_proc ),
679+ _signals .terminator (kill_proc ),
680+ ):
640681 proc = self .__multiprocessing_context .Process (
641682 target = _background_job_wrapper , args = (result_queue , target , args )
642683 )
@@ -659,16 +700,24 @@ def resume_proc():
659700 should_continue = False
660701 continue
661702 else :
662- raise PluginError ("Background process died with error code {}" .format (proc .exitcode ))
703+ raise PluginError (
704+ "Background process died with error code {}" .format (
705+ proc .exitcode
706+ )
707+ )
663708
664709 try :
665710 proc .join (timeout = 15 )
666711 proc .terminate ()
667712 except TimeoutError :
668- raise PluginError ("Background process didn't exit after 15 seconds and got killed." )
713+ raise PluginError (
714+ "Background process didn't exit after 15 seconds and got killed."
715+ )
669716
670717 if err is not None :
671- raise PluginError ("An error happened while running a blocking activity" , detail = err )
718+ raise PluginError (
719+ "An error happened while running a blocking activity" , detail = err
720+ )
672721
673722 return result
674723
@@ -944,10 +993,15 @@ def __call(
944993
945994 self .__note_command (output_file , args , cwd )
946995
947- exit_code , output = utils ._call (args , cwd = cwd , env = env , stdin = stdin , stdout = stdout , stderr = stderr )
996+ exit_code , output = utils ._call (
997+ args , cwd = cwd , env = env , stdin = stdin , stdout = stdout , stderr = stderr
998+ )
948999
9491000 if fail and exit_code :
950- raise PluginError ("{plugin}: {message}" .format (plugin = self , message = fail ), temporary = fail_temporarily )
1001+ raise PluginError (
1002+ "{plugin}: {message}" .format (plugin = self , message = fail ),
1003+ temporary = fail_temporarily ,
1004+ )
9511005
9521006 return (exit_code , output )
9531007
@@ -999,7 +1053,9 @@ def __get_full_name(self):
9991053
10001054# A local table for _prefix_warning()
10011055#
1002- __CORE_WARNINGS = [value for name , value in CoreWarnings .__dict__ .items () if not name .startswith ("__" )]
1056+ __CORE_WARNINGS = [
1057+ value for name , value in CoreWarnings .__dict__ .items () if not name .startswith ("__" )
1058+ ]
10031059
10041060
10051061# _prefix_warning():
0 commit comments