Skip to content

Commit 5b9818b

Browse files
committed
speed up parsing of relative paths with fragments
1 parent af940f3 commit 5b9818b

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

cwltool/resolver.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,33 @@
22
import logging
33
import os
44

5+
from pathlib import Path
56
from six.moves import urllib
67

7-
from schema_salad.ref_resolver import file_uri
88

99
_logger = logging.getLogger("cwltool")
1010

1111

1212
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]
1924

2025
_logger.debug("Search path is %s", shares)
2126

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()
2732
return None
2833

2934

@@ -32,7 +37,6 @@ def tool_resolver(document_loader, uri):
3237
ret = r(document_loader, uri)
3338
if ret is not None:
3439
return ret
35-
return file_uri(os.path.abspath(uri), split_frag=True)
3640

3741

3842
ga4gh_tool_registries = ["https://dockstore.org:8443"]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ rdflib-jsonld==0.4.0
55
shellescape==3.4.1
66
schema-salad>=2.6,<3
77
typing==3.5.3
8+
pathlib2; python_version<"3"

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
'six >= 1.8.0',
5959
],
6060
extras_require={
61+
':python_version<"3"': [ 'pathlib2' ],
6162
'deps': ["galaxy-lib >= 17.09.3"]
6263
},
6364
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4',

0 commit comments

Comments
 (0)