Skip to content

Commit 4c008ed

Browse files
committed
Merge pull request #14 from jmchilton/python26
Extended CI Testing and Python 2.6 Support
2 parents 6f95dcf + 2def3a1 commit 4c008ed

File tree

8 files changed

+48
-14
lines changed

8 files changed

+48
-14
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
.tox/
2+
.eggs
3+
*.egg-info/
4+
*pyc

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ os:
44
- linux
55
env:
66
- TOX_ENV=py27-lint
7+
- TOX_ENV=py26-lint
8+
- TOX_ENV=py27-unit
9+
- TOX_ENV=py26-unit
710

811
install:
912
- pip install tox

schema_salad/jsonld_context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def pred(datatype, field, name, context, defaultBase, namespaces):
3232

3333
if field and "jsonldPredicate" in field:
3434
if isinstance(field["jsonldPredicate"], dict):
35-
v = {("@"+k[1:] if k.startswith("_") else k): v
36-
for k,v in field["jsonldPredicate"].items() }
35+
v = {}
36+
for k, val in field["jsonldPredicate"].items():
37+
v[("@"+k[1:] if k.startswith("_") else k)] = val
3738
else:
3839
v = field["jsonldPredicate"]
3940
elif "jsonldPredicate" in datatype:

schema_salad/makedoc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ def avrold_doc(j, outdoc, renderlist, redirects, brand, brandlink):
460460
s.append(j)
461461

462462
primitiveType = args.primtype
463-
464-
redirect = {r.split("=")[0]:r.split("=")[1] for r in args.redirect} if args.redirect else {}
463+
redirect = {}
464+
for r in (args.redirect or []):
465+
redirect[r.split("=")[0]] = r.split("=")[1]
465466
renderlist = args.only if args.only else []
466467
avrold_doc(s, sys.stdout, renderlist, redirect, args.brand, args.brandlink)

schema_salad/ref_resolver.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def add_context(self, newcontext, baseuri=""):
162162
self.vocab = {}
163163
self.rvocab = {}
164164

165-
self.ctx.update({k: v for k,v in newcontext.iteritems() if k != "@context"})
165+
self.ctx.update(_copy_dict_without_key(newcontext, "@context"))
166166

167167
_logger.debug("ctx is %s", self.ctx)
168168

@@ -266,7 +266,7 @@ def resolve_ref(self, ref, base_url=None):
266266
raise RuntimeError("Reference `%s` is not in the index. Index contains:\n %s" % (url, "\n ".join(self.idx)))
267267

268268
if "$graph" in obj:
269-
metadata = {k: v for k,v in obj.items() if k != "$graph"}
269+
metadata = _copy_dict_without_key(obj, "$graph")
270270
obj = obj["$graph"]
271271
return obj, metadata
272272
else:
@@ -314,7 +314,7 @@ def resolve_all(self, document, base_url, file_base=None):
314314
loader = newctx
315315

316316
if "$graph" in document:
317-
metadata = {k: v for k,v in document.items() if k != "$graph"}
317+
metadata = _copy_dict_without_key(document, "$graph")
318318
document = document["$graph"]
319319
metadata, _ = loader.resolve_all(metadata, base_url, file_base)
320320

@@ -500,3 +500,11 @@ def validate_links(self, document):
500500
else:
501501
raise errors[0]
502502
return
503+
504+
505+
def _copy_dict_without_key(from_dict, filtered_key):
506+
new_dict = {}
507+
for key, value in from_dict.items():
508+
if key != filtered_key:
509+
new_dict[key] = value
510+
return new_dict

schema_salad/schema.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,18 @@ def extend_and_specialize(items, loader):
301301
"""Apply 'extend' and 'specialize' to fully materialize derived record
302302
types."""
303303

304-
types = {t["name"]: t for t in items}
304+
types = {}
305+
for t in items:
306+
types[t["name"]] = t
305307
n = []
306308

307309
for t in items:
308310
t = copy.deepcopy(t)
309311
if "extends" in t:
312+
spec = {}
310313
if "specialize" in t:
311-
spec = {sp["specializeFrom"]: sp["specializeTo"] for sp in aslist(t["specialize"])}
312-
else:
313-
spec = {}
314+
for sp in aslist(t["specialize"]):
315+
spec[sp["specializeFrom"]] = sp["specializeTo"]
314316

315317
exfields = []
316318
exsym = []
@@ -357,7 +359,9 @@ def extend_and_specialize(items, loader):
357359

358360
n.append(t)
359361

360-
ex_types = {t["name"]: t for t in n}
362+
ex_types = {}
363+
for t in n:
364+
ex_types[t["name"]] = t
361365

362366
extended_by = {}
363367
for t in n:
@@ -380,7 +384,10 @@ def make_avro_schema(j, loader):
380384

381385
j = extend_and_specialize(j, loader)
382386

383-
j2 = make_valid_avro(j, {t["name"]: t for t in j}, set())
387+
name_dict = {}
388+
for t in j:
389+
name_dict[t["name"]] = t
390+
j2 = make_valid_avro(j, name_dict, set())
384391

385392
j3 = [t for t in j2 if isinstance(t, dict) and not t.get("abstract") and t.get("type") != "documentation"]
386393

tests/__init__.py

Whitespace-only changes.

tox.ini

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
[tox]
2-
envlist = py27-lint
2+
envlist = py27-lint,py26-lint,py27-unit,py26-unit
33
skipsdist = True
44

55
[testenv:py27-lint]
66
commands = flake8 schema_salad
77
whitelist_externals = flake8
88
deps = flake8
9+
10+
[testenv:py26-lint]
11+
commands = flake8 schema_salad
12+
whitelist_externals = flake8
13+
deps = flake8
14+
15+
[testenv:py27-unit]
16+
commands = python setup.py test
17+
18+
[testenv:py26-unit]
19+
commands = python setup.py test

0 commit comments

Comments
 (0)