Skip to content

Commit cefb22e

Browse files
authored
Merge branch 'master' into adjust-manifest
2 parents dd496a1 + 8edfbc2 commit cefb22e

File tree

8 files changed

+226
-14
lines changed

8 files changed

+226
-14
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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-
ruamel.yaml==0.12.4
4+
pathlib2==2.1.0
5+
ruamel.yaml==0.13.7
56
rdflib==4.2.1
67
rdflib-jsonld==0.4.0
78
html5lib==0.9999999

schema_salad/ref_resolver.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import hashlib
55
import logging
66
import collections
7+
import urllib
78
import urlparse
89
import re
910
import copy
1011
import pprint
1112
from StringIO import StringIO
13+
import pathlib2
1214

1315
from . import validate
1416
from .aslist import aslist
@@ -108,7 +110,7 @@ def fetch_text(self, url):
108110
return resp.text
109111
elif scheme == 'file':
110112
try:
111-
with open(path) as fp:
113+
with open(urllib.url2pathname(str(urlparse.urlparse(url).path))) as fp:
112114
read = fp.read()
113115
if hasattr(read, "decode"):
114116
return read.decode("utf-8")
@@ -137,7 +139,7 @@ def check_exists(self, url): # type: (unicode) -> bool
137139
return False
138140
return True
139141
elif scheme == 'file':
140-
return os.path.exists(path)
142+
return os.path.exists(urllib.url2pathname(str(urlparse.urlparse(url).path)))
141143
else:
142144
raise ValueError('Unsupported scheme in url: %s' % url)
143145

@@ -371,13 +373,19 @@ def resolve_ref(self,
371373
checklinks=True # type: bool
372374
):
373375
# type: (...) -> Tuple[Union[CommentedMap, CommentedSeq, unicode], Dict[unicode, Any]]
374-
base_url = base_url or u'file://%s/' % os.path.abspath('.')
375376

376377
obj = None # type: CommentedMap
377378
resolved_obj = None # type: Union[CommentedMap, CommentedSeq, unicode]
378379
inc = False
379380
mixin = None # type: Dict[unicode, Any]
380381

382+
if not base_url:
383+
base_url = pathlib2.Path(os.getcwd()).as_uri() + '/'
384+
385+
if isinstance(ref, (str, unicode)) and os.sep == "\\":
386+
# Convert Windows paths
387+
ref = ref.replace("\\", "/")
388+
381389
sl = SourceLine(obj, None, ValueError)
382390
# If `ref` is a dict, look for special directives.
383391
if isinstance(ref, CommentedMap):
@@ -418,7 +426,6 @@ def resolve_ref(self,
418426
raise ValueError(u"Expected CommentedMap or string, got %s: `%s`" % (type(ref), unicode(ref)))
419427

420428
url = self.expand_url(ref, base_url, scoped_id=(obj is not None))
421-
422429
# Has this reference been loaded already?
423430
if url in self.idx and (not mixin):
424431
return self.idx[url], {}

schema_salad/sourceline.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def cmap(d, lc=None, fn=None): # type: (Union[int, float, str, unicode, Dict, L
103103
return d
104104
if isinstance(d, dict):
105105
cm = CommentedMap()
106-
for k,v in d.iteritems():
106+
for k in sorted(d.keys()):
107+
v = d[k]
107108
if isinstance(v, CommentedBase):
108109
uselc = [v.lc.line, v.lc.col, v.lc.line, v.lc.col]
109110
vfn = v.lc.filename if hasattr(v.lc, "filename") else fn

schema_salad/tests/frag.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- id: foo1
2+
bar: b1
3+
- id: foo2
4+
bar: b2

schema_salad/tests/test_examples.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def test_examples(self):
243243
self.assertEqual(proc, src)
244244

245245
def test_yaml_float_test(self):
246-
self.assertEqual(ruamel.yaml.load("float-test: 2e-10")["float-test"],
246+
self.assertEqual(ruamel.yaml.safe_load("float-test: 2e-10")["float-test"],
247247
2e-10)
248248

249249
def test_typedsl_ref(self):
@@ -341,13 +341,13 @@ def test_scoped_id(self):
341341
print(g.serialize(format="n3"))
342342

343343
def test_mixin(self):
344+
base_url = "file://" + os.getcwd() + "/tests/"
344345
ldr = schema_salad.ref_resolver.Loader({})
345346
ra = ldr.resolve_ref(cmap({"$mixin": get_data("tests/mixin.yml"), "one": "five"}),
346-
base_url="file://" + os.getcwd() + "/tests/")
347+
base_url=base_url)
347348
self.assertEqual({'id': 'four', 'one': 'five'}, ra[0])
348-
349349
ldr = schema_salad.ref_resolver.Loader({"id": "@id"})
350-
base_url = "file://" + os.getcwd() + "/tests/"
350+
351351
ra = ldr.resolve_all(cmap([{
352352
"id": "a",
353353
"m": {"$mixin": get_data("tests/mixin.yml")}
@@ -368,6 +368,11 @@ def test_mixin(self):
368368
'one': 'two'}
369369
}], ra[0])
370370

371+
def test_fragment(self):
372+
ldr = schema_salad.ref_resolver.Loader({"id": "@id"})
373+
b, _ = ldr.resolve_ref("schema_salad/tests/frag.yml#foo2")
374+
self.assertEquals({"id": b["id"], "bar":"b2"}, b)
375+
371376

372377
if __name__ == '__main__':
373378
unittest.main()

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
install_requires = [
3131
'setuptools',
3232
'requests >= 1.0',
33-
'ruamel.yaml >= 0.12.4, < 0.12.5',
33+
'ruamel.yaml >= 0.12.4',
3434
'rdflib >= 4.2.0, < 4.3.0',
3535
'rdflib-jsonld >= 0.3.0, < 0.5.0',
36-
'html5lib >= 0.90, <= 0.9999999',
3736
'mistune >= 0.7.3, < 0.8',
3837
'typing >= 3.5.2, < 3.6',
3938
'CacheControl >= 0.11.7, < 0.12',
40-
'lockfile >= 0.9']
39+
'lockfile >= 0.9',
40+
'pathlib2 >= 2.1.0']
4141

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

tox.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
#envlist = py35-lint,py34-lint,py33-lint,py27-lint,py35-unit,py34-unit,py33-unit,py27-unit
3-
envlist = py27-lint, py27-unit, py35-mypy
3+
envlist = py27-lint, py27-unit, py35-mypy, py27-pipconflictchecker
44
skipsdist = True
55

66
[tox:travis]
@@ -38,6 +38,12 @@ commands = flake8 schema_salad setup.py
3838
whitelist_externals = flake8
3939
deps = flake8
4040

41+
[testenv:py27-pipconflictchecker]
42+
commands = pipconflictchecker
43+
whitelist_externals = pipconflictchecker
44+
deps = pip-conflict-checker
45+
46+
4147
[testenv:py35-unit]
4248
commands = python setup.py test
4349

typeshed/2.7/pathlib2.pyi

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Stubs for pathlib2 (Python 2)
2+
#
3+
# NOTE: This dynamically typed stub was automatically generated by stubgen.
4+
5+
from typing import Any, AnyStr, Type, TypeVar, Optional, Union
6+
from collections import Sequence
7+
8+
_P = TypeVar('_P', bound='PurePath')
9+
10+
intern = ... # type: Any
11+
basestring = ... # type: Any
12+
supports_symlinks = ... # type: bool
13+
nt = ... # type: Any
14+
15+
class _Flavour:
16+
join = ... # type: Any
17+
def __init__(self) -> None: ...
18+
def parse_parts(self, parts): ...
19+
def join_parsed_parts(self, drv, root, parts, drv2, root2, parts2): ...
20+
21+
class _WindowsFlavour(_Flavour):
22+
sep = ... # type: str
23+
altsep = ... # type: str
24+
has_drv = ... # type: bool
25+
pathmod = ... # type: Any
26+
is_supported = ... # type: Any
27+
drive_letters = ... # type: Any
28+
ext_namespace_prefix = ... # type: str
29+
reserved_names = ... # type: Any
30+
def splitroot(self, part, sep: Any = ...): ...
31+
def casefold(self, s): ...
32+
def casefold_parts(self, parts): ...
33+
def resolve(self, path): ...
34+
def is_reserved(self, parts): ...
35+
def make_uri(self, path): ...
36+
def gethomedir(self, username): ...
37+
38+
class _PosixFlavour(_Flavour):
39+
sep = ... # type: str
40+
altsep = ... # type: str
41+
has_drv = ... # type: bool
42+
pathmod = ... # type: Any
43+
is_supported = ... # type: Any
44+
def splitroot(self, part, sep: Any = ...): ...
45+
def casefold(self, s): ...
46+
def casefold_parts(self, parts): ...
47+
def resolve(self, path): ...
48+
def is_reserved(self, parts): ...
49+
def make_uri(self, path): ...
50+
def gethomedir(self, username): ...
51+
52+
class _Accessor: ...
53+
54+
class _NormalAccessor(_Accessor):
55+
stat = ... # type: Any
56+
lstat = ... # type: Any
57+
open = ... # type: Any
58+
listdir = ... # type: Any
59+
chmod = ... # type: Any
60+
lchmod = ... # type: Any
61+
#def lchmod(self, pathobj, mode): ...
62+
mkdir = ... # type: Any
63+
unlink = ... # type: Any
64+
rmdir = ... # type: Any
65+
rename = ... # type: Any
66+
replace = ... # type: Any
67+
symlink = ... # type: Any
68+
#def symlink(a, b, target_is_directory): ...
69+
#@staticmethod
70+
#def symlink(a, b, target_is_directory): ...
71+
utime = ... # type: Any
72+
def readlink(self, path): ...
73+
74+
class _Selector:
75+
child_parts = ... # type: Any
76+
successor = ... # type: Any
77+
def __init__(self, child_parts) -> None: ...
78+
def select_from(self, parent_path): ...
79+
80+
class _TerminatingSelector: ...
81+
82+
class _PreciseSelector(_Selector):
83+
name = ... # type: Any
84+
def __init__(self, name, child_parts) -> None: ...
85+
86+
class _WildcardSelector(_Selector):
87+
pat = ... # type: Any
88+
def __init__(self, pat, child_parts) -> None: ...
89+
90+
class _RecursiveWildcardSelector(_Selector):
91+
def __init__(self, pat, child_parts) -> None: ...
92+
93+
class _PathParents(Sequence):
94+
def __init__(self, path) -> None: ...
95+
def __len__(self): ...
96+
def __getitem__(self, idx): ...
97+
98+
class PurePath:
99+
def __new__(cls, *args): ...
100+
def __reduce__(self): ...
101+
def as_posix(self): ...
102+
def __bytes__(self): ...
103+
def as_uri(self) -> str: ...
104+
def __eq__(self, other): ...
105+
def __ne__(self, other): ...
106+
def __hash__(self): ...
107+
def __lt__(self, other): ...
108+
def __le__(self, other): ...
109+
def __gt__(self, other): ...
110+
def __ge__(self, other): ...
111+
drive = ... # type: Any
112+
root = ... # type: Any
113+
@property
114+
def anchor(self): ...
115+
@property
116+
def name(self): ...
117+
@property
118+
def suffix(self): ...
119+
@property
120+
def suffixes(self): ...
121+
@property
122+
def stem(self): ...
123+
def with_name(self, name): ...
124+
def with_suffix(self, suffix): ...
125+
def relative_to(self, *other): ...
126+
@property
127+
def parts(self): ...
128+
def joinpath(self, *args): ...
129+
def __truediv__(self, key): ...
130+
def __rtruediv__(self, key): ...
131+
__div__ = ... # type: Any
132+
__rdiv__ = ... # type: Any
133+
@property
134+
def parent(self): ...
135+
@property
136+
def parents(self): ...
137+
def is_absolute(self): ...
138+
def is_reserved(self): ...
139+
def match(self, path_pattern): ...
140+
141+
class PurePosixPath(PurePath): ...
142+
class PureWindowsPath(PurePath): ...
143+
144+
class Path(PurePath):
145+
def __new__(cls: Type[_P], *args: Union[AnyStr, PurePath],
146+
**kwargs: Any) -> _P: ...
147+
def __enter__(self): ...
148+
def __exit__(self, t, v, tb): ...
149+
@classmethod
150+
def cwd(cls): ...
151+
@classmethod
152+
def home(cls): ...
153+
def samefile(self, other_path): ...
154+
def iterdir(self): ...
155+
def glob(self, pattern): ...
156+
def rglob(self, pattern): ...
157+
def absolute(self): ...
158+
def resolve(self): ...
159+
def stat(self): ...
160+
def owner(self): ...
161+
def group(self): ...
162+
def open(self, mode: str = ..., buffering: int = ..., encoding: Optional[Any] = ..., errors: Optional[Any] = ..., newline: Optional[Any] = ...): ...
163+
def read_bytes(self): ...
164+
def read_text(self, encoding: Optional[Any] = ..., errors: Optional[Any] = ...): ...
165+
def write_bytes(self, data): ...
166+
def write_text(self, data, encoding: Optional[Any] = ..., errors: Optional[Any] = ...): ...
167+
def touch(self, mode: int = ..., exist_ok: bool = ...): ...
168+
def mkdir(self, mode: int = ..., parents: bool = ..., exist_ok: bool = ...): ...
169+
def chmod(self, mode): ...
170+
def lchmod(self, mode): ...
171+
def unlink(self): ...
172+
def rmdir(self): ...
173+
def lstat(self): ...
174+
def rename(self, target): ...
175+
def replace(self, target): ...
176+
def symlink_to(self, target, target_is_directory: bool = ...): ...
177+
def exists(self): ...
178+
def is_dir(self): ...
179+
def is_file(self): ...
180+
def is_symlink(self): ...
181+
def is_block_device(self): ...
182+
def is_char_device(self): ...
183+
def is_fifo(self): ...
184+
def is_socket(self): ...
185+
def expanduser(self): ...
186+
187+
class PosixPath(Path, PurePosixPath): ...
188+
class WindowsPath(Path, PureWindowsPath): ...

0 commit comments

Comments
 (0)