7272from itertools import chain
7373import string
7474from threading import Lock
75- from typing import cast , TYPE_CHECKING , Dict , Iterator , Iterable , List , Optional , Set , Sequence
75+ from typing import (
76+ cast ,
77+ TYPE_CHECKING ,
78+ Dict ,
79+ Iterator ,
80+ Iterable ,
81+ List ,
82+ Optional ,
83+ Set ,
84+ Sequence ,
85+ )
7686
7787from pyroaring import BitMap # pylint: disable=no-name-in-module
7888
7989from . import _yaml
8090from ._variables import Variables
8191from ._versions import BST_CORE_ARTIFACT_VERSION
82- from ._exceptions import BstError , LoadError , ImplError , SourceCacheError , CachedFailure
92+ from ._exceptions import (
93+ BstError ,
94+ LoadError ,
95+ ImplError ,
96+ SourceCacheError ,
97+ CachedFailure ,
98+ )
8399from .exceptions import ErrorDomain , LoadErrorReason
84100from .utils import FileListResult , BST_ARBITRARY_TIMESTAMP
85101from . import utils
90106from .sandbox import _SandboxFlags , SandboxCommandError
91107from .sandbox ._config import SandboxConfig
92108from .sandbox ._sandboxremote import SandboxRemote
93- from .types import _Scope , _CacheBuildTrees , _KeyStrength , OverlapAction , _DisplayKey
109+ from .types import (
110+ _Scope ,
111+ _CacheBuildTrees ,
112+ _KeyStrength ,
113+ OverlapAction ,
114+ _DisplayKey ,
115+ )
94116from ._artifact import Artifact
95117from ._elementproxy import ElementProxy
96118from ._elementsources import ElementSources
@@ -136,7 +158,13 @@ def __init__(
136158 collect : Optional [str ] = None ,
137159 temporary : bool = False ,
138160 ):
139- super ().__init__ (message , detail = detail , domain = ErrorDomain .ELEMENT , reason = reason , temporary = temporary )
161+ super ().__init__ (
162+ message ,
163+ detail = detail ,
164+ domain = ErrorDomain .ELEMENT ,
165+ reason = reason ,
166+ temporary = temporary ,
167+ )
140168
141169 self .collect = collect
142170
@@ -438,7 +466,10 @@ def sources(self) -> Iterator["Source"]:
438466 return self .__sources .sources ()
439467
440468 def dependencies (
441- self , selection : Optional [Sequence ["Element" ]] = None , * , recurse : bool = True
469+ self ,
470+ selection : Optional [Sequence ["Element" ]] = None ,
471+ * ,
472+ recurse : bool = True ,
442473 ) -> Iterator ["Element" ]:
443474 """A generator function which yields the build dependencies of the given element.
444475
@@ -529,7 +560,8 @@ def node_subst_vars(self, node: "ScalarNode") -> str:
529560 """
530561 # FIXME: remove this
531562 warnings .warn (
532- "configuration is now automatically expanded, this is a no-op and will be removed." , DeprecationWarning
563+ "configuration is now automatically expanded, this is a no-op and will be removed." ,
564+ DeprecationWarning ,
533565 )
534566 return node .as_str ()
535567
@@ -550,12 +582,17 @@ def node_subst_sequence_vars(self, node: "SequenceNode[ScalarNode]") -> List[str
550582 """
551583 # FIXME: remove this
552584 warnings .warn (
553- "configuration is now automatically expanded, this is a no-op and will be removed." , DeprecationWarning
585+ "configuration is now automatically expanded, this is a no-op and will be removed." ,
586+ DeprecationWarning ,
554587 )
555588 return node .as_str_list ()
556589
557590 def compute_manifest (
558- self , * , include : Optional [List [str ]] = None , exclude : Optional [List [str ]] = None , orphans : bool = True
591+ self ,
592+ * ,
593+ include : Optional [List [str ]] = None ,
594+ exclude : Optional [List [str ]] = None ,
595+ orphans : bool = True ,
559596 ) -> str :
560597 """Compute and return this element's selective manifest
561598
@@ -653,7 +690,12 @@ def stage_artifact(
653690 #
654691 with overlap_collector .session (action , path ):
655692 result = self ._stage_artifact (
656- sandbox , path = path , action = action , include = include , exclude = exclude , orphans = orphans
693+ sandbox ,
694+ path = path ,
695+ action = action ,
696+ include = include ,
697+ exclude = exclude ,
698+ orphans = orphans ,
657699 )
658700
659701 return result
@@ -698,7 +740,14 @@ def stage_dependency_artifacts(
698740
699741 with overlap_collector .session (action , path ):
700742 for dep in self .dependencies (selection ):
701- dep ._stage_artifact (sandbox , path = path , include = include , exclude = exclude , orphans = orphans , owner = self )
743+ dep ._stage_artifact (
744+ sandbox ,
745+ path = path ,
746+ include = include ,
747+ exclude = exclude ,
748+ orphans = orphans ,
749+ owner = self ,
750+ )
702751
703752 def integrate (self , sandbox : "Sandbox" ) -> None :
704753 """Integrate currently staged filesystem against this artifact.
@@ -718,7 +767,12 @@ def integrate(self, sandbox: "Sandbox") -> None:
718767 if bstdata is not None :
719768 with sandbox .batch ():
720769 for command in bstdata .get_str_list ("integration-commands" , []):
721- sandbox .run (["sh" , "-e" , "-c" , command ], env = environment , cwd = "/" , label = command )
770+ sandbox .run (
771+ ["sh" , "-e" , "-c" , command ],
772+ env = environment ,
773+ cwd = "/" ,
774+ label = command ,
775+ )
722776
723777 def stage_sources (self , sandbox : "Sandbox" , directory : str ) -> None :
724778 """Stage this element's sources to a directory in the sandbox
@@ -888,7 +942,10 @@ def visit(element, scope, visited):
888942 visited [0 ].add (element ._unique_id )
889943 visited [1 ].add (element ._unique_id )
890944
891- for dep in chain (element .__build_dependencies , element .__runtime_dependencies ):
945+ for dep in chain (
946+ element .__build_dependencies ,
947+ element .__runtime_dependencies ,
948+ ):
892949 if dep ._unique_id not in visited [0 ] and dep ._unique_id not in visited [1 ]:
893950 yield from visit (dep , _Scope .ALL , visited )
894951
@@ -987,7 +1044,11 @@ def _stage_artifact(
9871044 "No artifacts have been cached yet for that element\n "
9881045 + "Try building the element first with `bst build`\n "
9891046 )
990- raise ElementError ("No artifacts to stage" , detail = detail , reason = "uncached-checkout-attempt" )
1047+ raise ElementError (
1048+ "No artifacts to stage" ,
1049+ detail = detail ,
1050+ reason = "uncached-checkout-attempt" ,
1051+ )
9911052
9921053 # Time to use the artifact, check once more that it's there
9931054 self .__assert_cached ()
@@ -1030,10 +1091,26 @@ def _stage_artifact(
10301091 # yet produced artifacts, or if forbidden overlaps
10311092 # occur.
10321093 #
1033- def _stage_dependency_artifacts (self , sandbox , scope , * , path = None , include = None , exclude = None , orphans = True ):
1094+ def _stage_dependency_artifacts (
1095+ self ,
1096+ sandbox ,
1097+ scope ,
1098+ * ,
1099+ path = None ,
1100+ include = None ,
1101+ exclude = None ,
1102+ orphans = True ,
1103+ ):
10341104 with self ._overlap_collectors [sandbox ].session (OverlapAction .WARNING , path ):
10351105 for dep in self ._dependencies (scope ):
1036- dep ._stage_artifact (sandbox , path = path , include = include , exclude = exclude , orphans = orphans , owner = self )
1106+ dep ._stage_artifact (
1107+ sandbox ,
1108+ path = path ,
1109+ include = include ,
1110+ exclude = exclude ,
1111+ orphans = orphans ,
1112+ owner = self ,
1113+ )
10371114
10381115 # _new_from_load_element():
10391116 #
@@ -1519,7 +1596,11 @@ def _stage_sources_at(self, vdirectory):
15191596 import_dir = staged_sources
15201597
15211598 # Set update_mtime to ensure deterministic mtime of sources at build time
1522- vdirectory ._import_files_internal (import_dir , update_mtime = BST_ARBITRARY_TIMESTAMP , collect_result = False )
1599+ vdirectory ._import_files_internal (
1600+ import_dir ,
1601+ update_mtime = BST_ARBITRARY_TIMESTAMP ,
1602+ collect_result = False ,
1603+ )
15231604
15241605 # Ensure deterministic owners of sources at build time
15251606 vdirectory ._set_deterministic_user ()
@@ -1716,7 +1797,10 @@ def _assemble(self):
17161797
17171798 # Print the environment at the beginning of the log file.
17181799 env_dump = _yaml .roundtrip_dump_string (sandbox ._get_configured_environment () or self .get_environment ())
1719- self .log ("Build environment for element {}" .format (self .name ), detail = env_dump )
1800+ self .log (
1801+ "Build environment for element {}" .format (self .name ),
1802+ detail = env_dump ,
1803+ )
17201804
17211805 # Step 2 - Stage
17221806 self .__stage (sandbox )
@@ -1925,7 +2009,12 @@ def _load_artifact(self, *, pull, strict=None):
19252009 return False
19262010
19272011 # In non-strict mode retry with weak cache key
1928- artifact = Artifact (self , context , strict_key = self .__strict_cache_key , weak_key = self .__weak_cache_key )
2012+ artifact = Artifact (
2013+ self ,
2014+ context ,
2015+ strict_key = self .__strict_cache_key ,
2016+ weak_key = self .__weak_cache_key ,
2017+ )
19292018 artifact .query_cache ()
19302019
19312020 # Attempt to pull artifact with the weak cache key
@@ -2060,7 +2149,16 @@ def _push(self):
20602149 # usebuildtree (bool): Use the buildtree as its source
20612150 #
20622151 # Returns: Exit code
2063- def _shell (self , scope = None , * , mounts = None , isolate = False , prompt = None , command = None , usebuildtree = False ):
2152+ def _shell (
2153+ self ,
2154+ scope = None ,
2155+ * ,
2156+ mounts = None ,
2157+ isolate = False ,
2158+ prompt = None ,
2159+ command = None ,
2160+ usebuildtree = False ,
2161+ ):
20642162
20652163 with self ._prepare_sandbox (scope , shell = True , usebuildtree = usebuildtree ) as sandbox :
20662164 environment = sandbox ._get_configured_environment () or self .get_environment ()
@@ -2132,7 +2230,10 @@ def _open_workspace(self):
21322230 # additional support from Source implementations.
21332231 #
21342232 os .makedirs (context .builddir , exist_ok = True )
2135- with utils ._tempdir (dir = context .builddir , prefix = "workspace-{}" .format (self .normal_name )) as temp :
2233+ with utils ._tempdir (
2234+ dir = context .builddir ,
2235+ prefix = "workspace-{}" .format (self .normal_name ),
2236+ ) as temp :
21362237 self .__sources .init_workspace (temp )
21372238
21382239 # Now hardlink the files into the workspace target.
@@ -2283,7 +2384,8 @@ def _fetch(self, fetch_original=False):
22832384 self .__sources .stage_and_cache ()
22842385 except (SourceCacheError , DirectoryError ) as e :
22852386 raise ElementError (
2286- "Error trying to stage sources for {}: {}" .format (self .name , e ), reason = "stage-sources-fail"
2387+ "Error trying to stage sources for {}: {}" .format (self .name , e ),
2388+ reason = "stage-sources-fail" ,
22872389 )
22882390
22892391 # _calculate_cache_key():
@@ -2671,7 +2773,11 @@ def __load_sources(self, load_element):
26712773 #
26722774 def __get_dependency_artifact_names (self ):
26732775 return [
2674- os .path .join (dep .project_name , _get_normal_name (dep .name ), dep ._get_cache_key ())
2776+ os .path .join (
2777+ dep .project_name ,
2778+ _get_normal_name (dep .name ),
2779+ dep ._get_cache_key (),
2780+ )
26752781 for dep in self ._dependencies (_Scope .BUILD )
26762782 ]
26772783
@@ -3154,7 +3260,8 @@ def __init_splits(self):
31543260 splits = bstdata .get_mapping ("split-rules" )
31553261 self .__splits = {
31563262 domain : re .compile (
3157- "^(?:" + "|" .join ([utils ._glob2re (r ) for r in rules .as_str_list ()]) + ")$" , re .MULTILINE | re .DOTALL
3263+ "^(?:" + "|" .join ([utils ._glob2re (r ) for r in rules .as_str_list ()]) + ")$" ,
3264+ re .MULTILINE | re .DOTALL ,
31583265 )
31593266 for domain , rules in splits .items ()
31603267 }
@@ -3317,9 +3424,15 @@ def __update_cache_keys(self):
33173424 # encode the dependency's weak cache key instead of it's name.
33183425 #
33193426 dependencies = [
3320- [e .project_name , e .name , e ._get_cache_key (strength = _KeyStrength .WEAK )]
3321- if self .BST_STRICT_REBUILD or e in self .__strict_dependencies
3322- else [e .project_name , e .name ]
3427+ (
3428+ [
3429+ e .project_name ,
3430+ e .name ,
3431+ e ._get_cache_key (strength = _KeyStrength .WEAK ),
3432+ ]
3433+ if self .BST_STRICT_REBUILD or e in self .__strict_dependencies
3434+ else [e .project_name , e .name ]
3435+ )
33233436 for e in self ._dependencies (_Scope .BUILD )
33243437 ]
33253438 self .__weak_cache_key = self ._calculate_cache_key (dependencies )
0 commit comments