1010from itertools import chain
1111from pathlib import Path , PurePath
1212from typing import (
13- Deque ,
14- Dict ,
15- List ,
16- Set ,
17- Tuple ,
1813 TypeAlias ,
1914 TypedDict ,
2015 Iterable ,
@@ -31,12 +26,12 @@ class Mount(TypedDict):
3126
3227
3328class Pattern (TypedDict ):
34- onFeatures : List [str ]
35- paths : List [Glob | Mount ]
29+ onFeatures : list [str ]
30+ paths : list [Glob | Mount ]
3631 unsafeFollowSymlinks : bool
3732
3833
39- AllowedPatterns : TypeAlias = Dict [str , Pattern ]
34+ AllowedPatterns : TypeAlias = dict [str , Pattern ]
4035
4136
4237parser = ArgumentParser ("pre-build-hook" )
@@ -59,7 +54,7 @@ class Pattern(TypedDict):
5954parser .add_argument ("-v" , "--verbose" , action = "count" , default = 0 )
6055
6156
62- def symlink_targets (p : Path ) -> List [Path ]:
57+ def symlink_targets (p : Path ) -> list [Path ]:
6358 """Traverses a chain of symlinks to collect every intermediate path up to the final destination."""
6459
6560 out = []
@@ -84,7 +79,7 @@ def symlink_targets(p: Path) -> List[Path]:
8479 return out
8580
8681
87- def symlink_closure (path : Path ) -> List [Path ]:
82+ def symlink_closure (path : Path ) -> list [Path ]:
8883 """Traverses all higher paths towards the final path. Returns all symlink targets on the way."""
8984 path_gen = (
9085 p
@@ -95,7 +90,7 @@ def symlink_closure(path: Path) -> List[Path]:
9590 return sum (map (symlink_targets , path_gen ), [])
9691
9792
98- def get_required_system_features (parsed_drv : dict ) -> List [str ]:
93+ def get_required_system_features (parsed_drv : dict ) -> list [str ]:
9994 # Newer versions of Nix (since https://github.com/NixOS/nix/pull/13263) store structuredAttrs
10095 # in the derivation JSON output.
10196 if "structuredAttrs" in parsed_drv :
@@ -114,8 +109,8 @@ def get_required_system_features(parsed_drv: dict) -> List[str]:
114109
115110def validate_mounts (
116111 pattern : Pattern ,
117- ) -> List [ Tuple [PathString , PathString , bool ]]:
118- roots : List [ Tuple [PathString , PathString , bool ]] = []
112+ ) -> list [ tuple [PathString , PathString , bool ]]:
113+ roots : list [ tuple [PathString , PathString , bool ]] = []
119114 for mount in pattern ["paths" ]:
120115 if isinstance (mount , PathString ):
121116 matches = glob .glob (mount )
@@ -141,9 +136,9 @@ def validate_mounts(
141136
142137
143138def enumerate_patterns (
144- allowed_patterns : AllowedPatterns , required_features : List [str ]
145- ) -> Iterable [Tuple [PathString , PathString , bool ]]:
146- patterns : List [Pattern ] = [
139+ allowed_patterns : AllowedPatterns , required_features : list [str ]
140+ ) -> Iterable [tuple [PathString , PathString , bool ]]:
141+ patterns : list [Pattern ] = [
147142 pattern
148143 for pattern in allowed_patterns .values ()
149144 if any (
@@ -155,11 +150,11 @@ def enumerate_patterns(
155150
156151
157152def discover_reachable_paths (
158- inputs : Iterable [Tuple [PathString , PathString , bool ]],
159- ) -> List [ Tuple [PathString , PathString ]]:
160- queue : Deque [ Tuple [PathString , PathString , bool ]] = deque (inputs )
161- unique_mounts : Set [ Tuple [PathString , PathString ]] = set ()
162- mounts : List [ Tuple [PathString , PathString ]] = []
153+ inputs : Iterable [tuple [PathString , PathString , bool ]],
154+ ) -> list [ tuple [PathString , PathString ]]:
155+ queue : deque [ tuple [PathString , PathString , bool ]] = deque (inputs )
156+ unique_mounts : set [ tuple [PathString , PathString ]] = set ()
157+ mounts : list [ tuple [PathString , PathString ]] = []
163158
164159 while queue :
165160 guest_path_str , host_path_str , follow_symlinks = queue .popleft ()
@@ -190,8 +185,8 @@ def discover_reachable_paths(
190185
191186
192187def prune_paths (
193- inputs : List [ Tuple [PathString , PathString ]],
194- ) -> List [ Tuple [PathString , PathString ]]:
188+ inputs : list [ tuple [PathString , PathString ]],
189+ ) -> list [ tuple [PathString , PathString ]]:
195190 if len (inputs ) < 2 :
196191 return inputs
197192
0 commit comments