@@ -22,10 +22,37 @@ namespace PythonInstallation {
2222 pythonRepository = defaultPythonRepository ;
2323 pythonRoot = defaultPythonRoot ;
2424 }
25- if ( Uri . parse ( pythonRepository ) . authority !== 'github.com' ) {
25+
26+ // Consider third party file system providers
27+ try {
28+ let pythonRepositoryUri : Uri | undefined = undefined ;
29+ try {
30+ // Uri.parse throws if the URI is invalid
31+ pythonRepositoryUri = Uri . parse ( pythonRepository ) ;
32+ } catch ( e ) {
33+ Tracer . append ( `${ pythonRepository } is not a valid URI` ) ;
34+ throw e ;
35+ }
36+
37+ if ( ! isGithubUri ( pythonRepositoryUri ) ) {
38+ const binaryLocation = Uri . joinPath ( pythonRepositoryUri , 'python.wasm' ) ;
39+ try {
40+ // fs.stat throws if file doesn't exist
41+ await workspace . fs . stat ( binaryLocation ) ;
42+ Tracer . append ( `Using python library from ${ pythonRepositoryUri } ` ) ;
43+
44+ return { repository : pythonRepositoryUri , root : '/' } ;
45+ } catch ( e ) {
46+ Tracer . append ( `python.wasm not found in ${ binaryLocation } ` ) ;
47+ throw e ;
48+ }
49+ }
50+ } catch {
51+ Tracer . append ( `Falling back to default repository` ) ;
2652 pythonRepository = defaultPythonRepository ;
2753 pythonRoot = defaultPythonRoot ;
2854 }
55+
2956 const extname = path . extname ( pythonRepository ) ;
3057 if ( extname === '.git' ) {
3158 pythonRepository = pythonRepository . substring ( 0 , pythonRepository . length - extname . length ) ;
@@ -71,28 +98,31 @@ namespace PythonInstallation {
7198 }
7299 try {
73100 const token = ++ preloadToken ;
74- const remoteHubApi = await RemoteRepositories . getApi ( ) ;
75- if ( remoteHubApi . loadWorkspaceContents !== undefined ) {
76- await remoteHubApi . loadWorkspaceContents ( repository ) ;
101+
102+ if ( isGithubUri ( repository ) ) {
103+ const remoteHubApi = await RemoteRepositories . getApi ( ) ;
104+ if ( remoteHubApi . loadWorkspaceContents !== undefined ) {
105+ await remoteHubApi . loadWorkspaceContents ( repository ) ;
106+ }
77107 Tracer . append ( `Successfully loaded workspace content for repository ${ repository . toString ( ) } ` ) ;
78- const binaryLocation = root !== undefined ? Uri . joinPath ( repository , root , 'python.wasm' ) : Uri . joinPath ( repository , 'python.wasm' ) ;
79- try {
80- const bytes = await workspace . fs . readFile ( binaryLocation ) ;
81- // We didn't start another preload.
82- if ( token === preloadToken ) {
83- const buffer = new SharedArrayBuffer ( bytes . byteLength ) ;
84- new Uint8Array ( buffer ) . set ( bytes ) ;
85- Tracer . append ( `Successfully cached WASM file ${ binaryLocation . toString ( ) } ` ) ;
86- wasmBytes = buffer ;
108+ }
109+ const binaryLocation = root !== undefined ? Uri . joinPath ( repository , root , 'python.wasm' ) : Uri . joinPath ( repository , 'python.wasm' ) ;
110+ try {
111+ const bytes = await workspace . fs . readFile ( binaryLocation ) ;
112+ // We didn't start another preload.
113+ if ( token === preloadToken ) {
114+ const buffer = new SharedArrayBuffer ( bytes . byteLength ) ;
115+ new Uint8Array ( buffer ) . set ( bytes ) ;
116+ Tracer . append ( `Successfully cached WASM file ${ binaryLocation . toString ( ) } ` ) ;
117+ wasmBytes = buffer ;
87118
88- } else {
89- wasmBytes = undefined ;
90- }
91- } catch ( error ) {
119+ } else {
92120 wasmBytes = undefined ;
93- Tracer . append ( `Caching WASM file ${ binaryLocation . toString ( ) } failed` ) ;
94- console . error ( error ) ;
95121 }
122+ } catch ( error ) {
123+ wasmBytes = undefined ;
124+ Tracer . append ( `Caching WASM file ${ binaryLocation . toString ( ) } failed` ) ;
125+ console . error ( error ) ;
96126 }
97127 } catch ( error ) {
98128 Tracer . append ( `Loading workspace content for repository ${ repository . toString ( ) } failed: ${ error instanceof Error ? error . toString ( ) : 'Unknown reason' } ` ) ;
@@ -118,6 +148,9 @@ namespace PythonInstallation {
118148 }
119149 return wasmBytes ;
120150 }
121- }
122151
152+ function isGithubUri ( uri : Uri ) : boolean {
153+ return uri . authority === 'github.com' ;
154+ }
155+ }
123156export default PythonInstallation ;
0 commit comments