1
1
from __future__ import annotations
2
2
3
3
import importlib .abc
4
- import importlib .util
5
4
import importlib .machinery
6
- import importlib .readers # Might be Python version specific?
5
+
6
+ # TODO: importlib.readers is Python version specific
7
+ import importlib .readers # type: ignore[import-not-found]
8
+ import importlib .util
7
9
import os
8
10
import subprocess
9
11
import sys
13
15
TYPE_CHECKING = False
14
16
if TYPE_CHECKING :
15
17
from importlib .machinery import ModuleSpec
18
+ from pathlib import Path
16
19
17
20
18
21
DIR = os .path .abspath (os .path .dirname (__file__ ))
@@ -78,11 +81,12 @@ def release(self) -> None:
78
81
fcntl .flock (self .lock_file_fd , fcntl .LOCK_UN )
79
82
os .close (self .lock_file_fd )
80
83
84
+
81
85
# Note: This solution relies on importlib's call stack in Python 3.11. Python 3.9 looks
82
86
# different, so might require a different solution, but I haven't gone deeper into that
83
87
# yet since I don't have a solution for the 3.11 case yet anyway.
84
- class ScikitBuildRedirectingReader (importlib .readers .FileReader ):
85
- def files (self ):
88
+ class ScikitBuildRedirectingReader (importlib .readers .FileReader ): # type: ignore[misc]
89
+ def files (self ) -> Path :
86
90
# ATTENTION: This is where the problem is. The expectation is that this returns
87
91
# a Traversable object. We could hack together an object that satisfies that
88
92
# API, but methods like `joinpath` don't have sensible implementations if
@@ -91,11 +95,11 @@ def files(self):
91
95
# representation that knows both possible roots and checks for existence when
92
96
# necessary, but that seriously violates the principle of least surprise for the
93
97
# user so I'd be quite skeptical.
94
- return self .path
98
+ return self .path # type: ignore[no-any-return]
95
99
96
100
97
101
class ScikitBuildRedirectingLoader (importlib .machinery .SourceFileLoader ):
98
- def get_resource_reader (self , module ):
102
+ def get_resource_reader (self , module : str ) -> ScikitBuildRedirectingReader : # type: ignore[override]
99
103
return ScikitBuildRedirectingReader (self )
100
104
101
105
@@ -175,7 +179,9 @@ def find_spec(
175
179
submodule_search_locations = submodule_search_locations
176
180
if redir .endswith (("__init__.py" , "__init__.pyc" ))
177
181
else None ,
178
- loader = ScikitBuildRedirectingLoader (fullname , os .path .join (self .dir , redir )),
182
+ loader = ScikitBuildRedirectingLoader (
183
+ fullname , os .path .join (self .dir , redir )
184
+ ),
179
185
)
180
186
if fullname in self .known_source_files :
181
187
redir = self .known_source_files [fullname ]
0 commit comments