2
2
import logging
3
3
import os
4
4
5
+ from pathlib import Path
5
6
from six .moves import urllib
6
7
7
- from schema_salad .ref_resolver import file_uri
8
8
9
9
_logger = logging .getLogger ("cwltool" )
10
10
11
11
12
12
def resolve_local (document_loader , uri ):
13
- if uri .startswith ("/" ):
14
- return None
15
- shares = [os .environ .get ("XDG_DATA_HOME" , os .path .join (os .path .expanduser ('~' ), ".local" , "share" ))]
16
- shares .extend (os .environ .get ("XDG_DATA_DIRS" , "/usr/local/share/:/usr/share/" ).split (":" ))
17
- shares = [os .path .join (s , "commonwl" , uri ) for s in shares ]
18
- shares .insert (0 , os .path .join (os .getcwd (), uri ))
13
+ if uri .startswith ("/" ) and os .path .exists (uri ):
14
+ return Path (uri ).as_uri ()
15
+ if os .path .exists (urllib .parse .urlparse (
16
+ urllib .parse .urldefrag (
17
+ "{}/{}" .format (Path .cwd ().as_uri (), uri ))[0 ])[2 ]):
18
+ return "{}/{}" .format (Path .cwd ().as_uri (), uri )
19
+ sharepaths = [os .environ .get ("XDG_DATA_HOME" , os .path .join (
20
+ os .path .expanduser ('~' ), ".local" , "share" ))]
21
+ sharepaths .extend (os .environ .get (
22
+ "XDG_DATA_DIRS" , "/usr/local/share/:/usr/share/" ).split (":" ))
23
+ shares = [os .path .join (s , "commonwl" , uri ) for s in sharepaths ]
19
24
20
25
_logger .debug ("Search path is %s" , shares )
21
26
22
- for s in shares :
23
- if os .path .exists (s ):
24
- return file_uri ( s )
25
- if os .path .exists ("%s .cwl" % s ):
26
- return file_uri ( s )
27
+ for path in shares :
28
+ if os .path .exists (path ):
29
+ return Path ( uri ). as_uri ( )
30
+ if os .path .exists ("{} .cwl" . format ( path ) ):
31
+ return Path ( "{}.cwl" . format ( path )). as_uri ( )
27
32
return None
28
33
29
34
@@ -32,7 +37,6 @@ def tool_resolver(document_loader, uri):
32
37
ret = r (document_loader , uri )
33
38
if ret is not None :
34
39
return ret
35
- return file_uri (os .path .abspath (uri ), split_frag = True )
36
40
37
41
38
42
ga4gh_tool_registries = ["https://dockstore.org:8443" ]
0 commit comments