Skip to content

Commit f2d8931

Browse files
authored
Merge pull request #870 from RDFLib/autopep8
a slightly opinionated autopep8 run
2 parents f4c706f + 785e379 commit f2d8931

File tree

163 files changed

+1366
-1139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+1366
-1139
lines changed

.pep8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[pep8]
22
ignore = W806
33
max-line-length = 85
4-
exclude = pyRdfa,host,extras,transform,rdfs,pyMicrodata
4+
exclude = host,extras,transform,rdfs

examples/conjunctive_graphs.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,20 @@
1414
from rdflib.graph import Graph, ConjunctiveGraph
1515
from rdflib.plugins.memory import IOMemory
1616

17-
if __name__=='__main__':
18-
17+
if __name__ == '__main__':
1918

2019
ns = Namespace("http://love.com#")
2120

2221
mary = URIRef("http://love.com/lovers/mary#")
2322
john = URIRef("http://love.com/lovers/john#")
2423

25-
cmary=URIRef("http://love.com/lovers/mary#")
26-
cjohn=URIRef("http://love.com/lovers/john#")
24+
cmary = URIRef("http://love.com/lovers/mary#")
25+
cjohn = URIRef("http://love.com/lovers/john#")
2726

2827
store = IOMemory()
2928

3029
g = ConjunctiveGraph(store=store)
31-
g.bind("love",ns)
30+
g.bind("love", ns)
3231

3332
gmary = Graph(store=store, identifier=cmary)
3433

@@ -38,21 +37,21 @@
3837
gjohn = Graph(store=store, identifier=cjohn)
3938
gjohn.add((john, ns['hasName'], Literal("John")))
4039

41-
#enumerate contexts
40+
# enumerate contexts
4241
for c in g.contexts():
4342
print("-- %s " % c)
4443

45-
#separate graphs
44+
# separate graphs
4645
print(gjohn.serialize(format='n3'))
4746
print("===================")
4847
print(gmary.serialize(format='n3'))
4948
print("===================")
5049

51-
#full graph
50+
# full graph
5251
print(g.serialize(format='n3'))
5352

5453
# query the conjunction of all graphs
5554

5655
print('Mary loves:')
57-
for x in g[mary : ns.loves/ns.hasName]:
56+
for x in g[mary: ns.loves / ns.hasName]:
5857
print(x)

examples/custom_datatype.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@
1414
from rdflib import Graph, Literal, Namespace, XSD
1515
from rdflib.term import bind
1616

17-
if __name__=='__main__':
17+
if __name__ == '__main__':
1818

1919
# complex numbers are not registered by default
2020
# no custom constructor/serializer needed since
2121
# complex('(2+3j)') works fine
2222
bind(XSD.complexNumber, complex)
2323

24-
ns=Namespace("urn:my:namespace:")
24+
ns = Namespace("urn:my:namespace:")
2525

26-
c=complex(2,3)
26+
c = complex(2, 3)
2727

28-
l=Literal(c)
28+
l = Literal(c)
2929

30-
g=Graph()
30+
g = Graph()
3131
g.add((ns.mysubject, ns.myprop, l))
3232

33-
n3=g.serialize(format='n3')
33+
n3 = g.serialize(format='n3')
3434

3535
# round-trip through n3
3636

37-
g2=Graph()
37+
g2 = Graph()
3838
g2.parse(data=n3, format='n3')
3939

40-
l2=list(g2)[0][2]
40+
l2 = list(g2)[0][2]
4141

4242
print(l2)
4343

44-
print(l2.value == c) # back to a python complex object
44+
print(l2.value == c) # back to a python complex object

examples/custom_eval.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def customEval(ctx, part):
4949

5050
raise NotImplementedError()
5151

52-
if __name__=='__main__':
52+
53+
if __name__ == '__main__':
5354

5455
# add function directly, normally we would use setuptools and entry_points
5556
rdflib.plugins.sparql.CUSTOM_EVALS['exampleEval'] = customEval

examples/film.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
film.py http://www.imdb.com/title/tt0105236/
2424
Review the movie "Reservoir Dogs"
2525
"""
26-
import datetime, os, sys, re, time
26+
import datetime
27+
import os
28+
import sys
29+
import re
30+
import time
2731

2832
try:
2933
import imdb
@@ -36,14 +40,15 @@
3640

3741
storefn = os.path.expanduser('~/movies.n3')
3842
#storefn = '/home/simon/codes/film.dev/movies.n3'
39-
storeuri = 'file://'+storefn
43+
storeuri = 'file://' + storefn
4044
title = 'Movies viewed by %s'
4145

4246
r_who = re.compile('^(.*?) <([a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)>$')
4347

4448
IMDB = Namespace('http://www.csd.abdn.ac.uk/~ggrimnes/dev/imdb/IMDB#')
4549
REV = Namespace('http://purl.org/stuff/rev#')
4650

51+
4752
class Store:
4853
def __init__(self):
4954
self.graph = ConjunctiveGraph()
@@ -61,12 +66,14 @@ def who(self, who=None):
6166
if who is not None:
6267
name, email = (r_who.match(who).group(1), r_who.match(who).group(2))
6368
self.graph.add((URIRef(storeuri), DC['title'], Literal(title % name)))
64-
self.graph.add((URIRef(storeuri+'#author'), RDF.type, FOAF['Person']))
65-
self.graph.add((URIRef(storeuri+'#author'), FOAF['name'], Literal(name)))
66-
self.graph.add((URIRef(storeuri+'#author'), FOAF['mbox'], Literal(email)))
69+
self.graph.add((URIRef(storeuri + '#author'), RDF.type, FOAF['Person']))
70+
self.graph.add((URIRef(storeuri + '#author'),
71+
FOAF['name'], Literal(name)))
72+
self.graph.add((URIRef(storeuri + '#author'),
73+
FOAF['mbox'], Literal(email)))
6774
self.save()
6875
else:
69-
return self.graph.objects(URIRef(storeuri+'#author'), FOAF['name'])
76+
return self.graph.objects(URIRef(storeuri + '#author'), FOAF['name'])
7077

7178
def new_movie(self, movie):
7279
movieuri = URIRef('http://www.imdb.com/title/tt%s/' % movie.movieID)
@@ -76,14 +83,14 @@ def new_movie(self, movie):
7683
self.save()
7784

7885
def new_review(self, movie, date, rating, comment=None):
79-
review = BNode() # @@ humanize the identifier (something like #rev-$date)
86+
review = BNode() # @@ humanize the identifier (something like #rev-$date)
8087
movieuri = URIRef('http://www.imdb.com/title/tt%s/' % movie.movieID)
8188
self.graph.add((movieuri, REV['hasReview'], URIRef('%s#%s' % (storeuri, review))))
8289
self.graph.add((review, RDF.type, REV['Review']))
8390
self.graph.add((review, DC['date'], Literal(date)))
8491
self.graph.add((review, REV['maxRating'], Literal(5)))
8592
self.graph.add((review, REV['minRating'], Literal(0)))
86-
self.graph.add((review, REV['reviewer'], URIRef(storeuri+'#author')))
93+
self.graph.add((review, REV['reviewer'], URIRef(storeuri + '#author')))
8794
self.graph.add((review, REV['rating'], Literal(rating)))
8895
if comment is not None:
8996
self.graph.add((review, REV['text'], Literal(comment)))
@@ -92,9 +99,11 @@ def new_review(self, movie, date, rating, comment=None):
9299
def movie_is_in(self, uri):
93100
return (URIRef(uri), RDF.type, IMDB['Movie']) in self.graph
94101

102+
95103
def help():
96104
print(__doc__.split('--')[1])
97105

106+
98107
def main(argv=None):
99108
if not argv:
100109
argv = sys.argv
@@ -136,6 +145,7 @@ def main(argv=None):
136145
else:
137146
help()
138147

148+
139149
if __name__ == '__main__':
140150
if not imdb:
141151
raise Exception('This example requires the IMDB library! Install with "pip install imdbpy"')

examples/foafpaths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from rdflib import URIRef, Graph
3232
from rdflib.namespace import FOAF
3333

34-
if __name__=='__main__':
34+
if __name__ == '__main__':
3535

3636
g = Graph()
3737
g.load("foaf.rdf")

examples/graph_digest_benchmark.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from rdflib.compare import to_isomorphic
1313
from six.moves.urllib.request import urlopen
1414
from six.moves import queue
15-
import sys, csv
15+
import sys
16+
import csv
1617

1718
from io import StringIO
1819
from collections import defaultdict
@@ -49,7 +50,7 @@
4950
'to_hash_runtime',
5051
'canonicalize_triples_runtime',
5152
'error',
52-
]
53+
]
5354

5455

5556
def files_benchmark(ontologies, output_file, threads):
@@ -160,6 +161,7 @@ def worker(q, finished_tasks, dl_lock):
160161
w.flush()
161162
written_tasks += 1
162163

164+
163165
if __name__ == '__main__':
164166
if len(sys.argv) > 4:
165167
files_benchmark(sys.argv[1:-2], sys.argv[-2], sys.argv[-1])

examples/prepared_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
from rdflib.plugins.sparql import prepareQuery
1515
from rdflib.namespace import FOAF
1616

17-
if __name__=='__main__':
17+
if __name__ == '__main__':
1818

1919
q = prepareQuery(
2020
'SELECT ?s WHERE { ?person foaf:knows ?s .}',
21-
initNs = { "foaf": FOAF })
21+
initNs={"foaf": FOAF})
2222

2323
g = rdflib.Graph()
2424
g.load("foaf.rdf")

examples/rdfa_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
schema:name ?title ]
2020
FILTER (LANG(?title) = 'en') } """):
2121

22-
print("%s by %s"%(row.title, row.author))
22+
print("%s by %s" % (row.title, row.author))

examples/resource.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
from rdflib import Graph, RDF, RDFS, Literal
1313
from rdflib.namespace import FOAF
1414

15-
if __name__=='__main__':
15+
if __name__ == '__main__':
1616

1717
g = Graph()
1818

1919
bob = g.resource('urn:bob')
2020

21-
bob.set(RDF.type, FOAF.Person) # .set replaces all other values
21+
bob.set(RDF.type, FOAF.Person) # .set replaces all other values
2222
bob.set(FOAF.name, Literal("Bob"))
2323

24-
2524
bill = g.resource('urn:bill')
2625

27-
bill.add(RDF.type, FOAF.Person) # add adds to existing values
26+
bill.add(RDF.type, FOAF.Person) # add adds to existing values
2827
bill.add(RDF.type, FOAF.Agent)
2928
bill.set(RDFS.label, Literal("Bill"))
3029

@@ -42,8 +41,8 @@
4241

4342
# or even quicker with paths:
4443
print("Bill knows: ")
45-
for friend in bill[FOAF.knows/FOAF.name]:
44+
for friend in bill[FOAF.knows / FOAF.name]:
4645
print(friend)
4746

4847
# setting single properties is also possible:
49-
bill[RDFS.label]=Literal("William")
48+
bill[RDFS.label] = Literal("William")

0 commit comments

Comments
 (0)