Skip to content

Commit 0c7cc02

Browse files
authored
Remove pathlib2 because it is only used for one thing but creates dependency issues. (#79)
1 parent f31369c commit 0c7cc02

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
typing==3.5.2.2 ; python_version>="2.7"
22
avro-python3 ; python_version>="3"
33
avro==1.8.1 ; python_version<"3"
4-
pathlib2==2.1.0
54
ruamel.yaml==0.13.7
65
rdflib==4.2.1
76
rdflib-jsonld==0.4.0

schema_salad/ref_resolver.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
import urlparse
99
import re
1010
import copy
11-
import pprint
11+
import urllib
1212
from StringIO import StringIO
13-
import pathlib2
1413

1514
from . import validate
1615
from .aslist import aslist
@@ -37,6 +36,21 @@
3736
DocumentOrStrType = TypeVar(
3837
'DocumentOrStrType', CommentedSeq, CommentedMap, unicode)
3938

39+
def file_uri(path): # type: (unicode) -> unicode
40+
if path.startswith("file://"):
41+
return path
42+
urlpath = urllib.pathname2url(str(path))
43+
if urlpath.startswith("//"):
44+
return "file:%s" % urlpath
45+
else:
46+
return "file://%s" % urlpath
47+
48+
def uri_file_path(url): # type: (unicode) -> unicode
49+
split = urlparse.urlsplit(url)
50+
if split.scheme == "file":
51+
urllib.url2pathname(str(split.path))
52+
else:
53+
raise ValueError("Not a file URI")
4054

4155
class NormDict(CommentedMap):
4256

@@ -110,7 +124,7 @@ def fetch_text(self, url):
110124
return resp.text
111125
elif scheme == 'file':
112126
try:
113-
with open(urllib.url2pathname(str(urlparse.urlparse(url).path))) as fp:
127+
with open(urllib.url2pathname(str(path))) as fp:
114128
read = fp.read()
115129
if hasattr(read, "decode"):
116130
return read.decode("utf-8")
@@ -139,7 +153,7 @@ def check_exists(self, url): # type: (unicode) -> bool
139153
return False
140154
return True
141155
elif scheme == 'file':
142-
return os.path.exists(urllib.url2pathname(str(urlparse.urlparse(url).path)))
156+
return os.path.exists(urllib.url2pathname(str(path)))
143157
else:
144158
raise ValueError('Unsupported scheme in url: %s' % url)
145159

@@ -380,10 +394,10 @@ def resolve_ref(self,
380394
mixin = None # type: Dict[unicode, Any]
381395

382396
if not base_url:
383-
base_url = pathlib2.Path(os.getcwd()).as_uri() + '/'
397+
base_url = file_uri(os.getcwd()) + "/"
384398

385399
if isinstance(ref, (str, unicode)) and os.sep == "\\":
386-
# Convert Windows paths
400+
# Convert Windows path separator in ref
387401
ref = ref.replace("\\", "/")
388402

389403
sl = SourceLine(obj, None, ValueError)

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
'mistune >= 0.7.3, < 0.8',
3737
'typing >= 3.5.2, < 3.6',
3838
'CacheControl >= 0.11.7, < 0.12',
39-
'lockfile >= 0.9',
40-
'pathlib2 >= 2.1.0']
39+
'lockfile >= 0.9']
4140

4241
install_requires.append("avro") # TODO: remove me once cwltool is
4342
# available in Debian Stable, Ubuntu 12.04 LTS

0 commit comments

Comments
 (0)