diff --git a/.travis.yml b/.travis.yml index 1a9659f..f30d3f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false language: python python: - "2.7" diff --git a/Makefile b/Makefile index af08188..162ff1f 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ dev: $(DJANGO) check: $(TEST) $(FLAKE8) $(PYLINT) $(TEST) $(FLAKE8) - $(PYLINT) + $(PYLINT) --rcfile=pylint.rc rdflib_django snapshot: $(BUILDOUT) clean check diff --git a/buildout.cfg b/buildout.cfg index ad68c8b..f10952c 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -15,32 +15,29 @@ eggs = rdflib versions = versions -extensions = - buildout.dumppickedversions src-directory = src/rdflib_django develop = . unzip = true [versions] -Django=1.4.1 -collective.recipe.omelette = 0.15 -django-extensions = 0.9 -djangorecipe = 1.3 -flake8 = 1.4 -isodate = 0.4.8 -logilab-astng = 0.24.0 -logilab-common = 0.58.1 -pylint = 0.25.2 -rdflib = 3.2.2 -setuptools = 0.6c12dev-r88846 -zc.buildout = 1.6.3 -zc.recipe.egg = 1.3.2 +Django=1.8.3 +collective.recipe.omelette = 0.16 +django-extensions = 1.5.5 +djangorecipe = 2.1.1 +flake8 = 2.4.1 +isodate = 0.5.1 +logilab-astng = 0.24.3 +logilab-common = 1.0.2 +pylint = 1.4.4 +rdflib = 4.2.0 +setuptools = 12.0.5 +zc.buildout = 2.4.0 +zc.recipe.egg = 2.0.2 [django] recipe = djangorecipe project = ${buildout:name} -projectegg = ${buildout:name} settings = testsettings eggs = ${buildout:eggs} test = ${buildout:name} diff --git a/src/rdflib_django/fields.py b/src/rdflib_django/fields.py index 4b7adcf..3ce3e26 100644 --- a/src/rdflib_django/fields.py +++ b/src/rdflib_django/fields.py @@ -78,7 +78,7 @@ class URIField(models.CharField): description = "Field for storing URIRefs and BNodes." def __init__(self, *args, **kwargs): - if not 'max_length' in kwargs: + if 'max_length' not in kwargs: kwargs['max_length'] = 500 super(URIField, self).__init__(*args, **kwargs) diff --git a/src/rdflib_django/forms.py b/src/rdflib_django/forms.py index 3d8e7d9..f9c564f 100644 --- a/src/rdflib_django/forms.py +++ b/src/rdflib_django/forms.py @@ -12,7 +12,7 @@ class NamespaceForm(forms.ModelForm): Form for editing namespaces. """ - class Meta: + class Meta(object): model = models.NamespaceModel fields = ('prefix', 'uri') diff --git a/src/rdflib_django/management/commands/rdf_export.py b/src/rdflib_django/management/commands/rdf_export.py index 7d1ff6b..239349a 100644 --- a/src/rdflib_django/management/commands/rdf_export.py +++ b/src/rdflib_django/management/commands/rdf_export.py @@ -15,16 +15,14 @@ class Command(BaseCommand): option_list = BaseCommand.option_list + ( make_option('--context', '-c', type='string', dest='context', - help='Only RDF data from the context with this identifier will be exported. If not specified, a new blank ' + - 'context is created.'), + help='Only RDF data from the context with this identifier will be exported. If not specified, a new blank context is created.'), make_option('--store', '-s', type='string', dest='store', - help='RDF data will be exported from the store with this identifier. If not specified, the default store ' + - 'is used.'), + help='RDF data will be exported from the store with this identifier. If not specified, the default store is used.'), - make_option('--format', '-f', type='string', dest='format', default='xml', - help='Format of the RDF data. This option accepts all formats allowed by rdflib. Defaults to xml.') - ) + make_option('--format', '-f', type='string', dest='format', + default='xml', + help='Format of the RDF data. This option accepts all formats allowed by rdflib. Defaults to xml.')) help = """Exports an RDF resource. @@ -45,5 +43,5 @@ def handle(self, *args, **options): else: graph = utils.get_conjunctive_graph(store_id) - #noinspection PyUnresolvedReferences + # noinspection PyUnresolvedReferences graph.serialize(target, format=options.get('format')) diff --git a/src/rdflib_django/management/commands/rdf_import.py b/src/rdflib_django/management/commands/rdf_import.py index 45a98c4..7d69341 100644 --- a/src/rdflib_django/management/commands/rdf_import.py +++ b/src/rdflib_django/management/commands/rdf_import.py @@ -10,6 +10,9 @@ from rdflib_django import utils +atomic_decorator = getattr(transaction, 'atomic', None) or getattr(transaction, 'commit_on_success') + + class Command(BaseCommand): """ Command object for importing RDF. @@ -17,16 +20,14 @@ class Command(BaseCommand): option_list = BaseCommand.option_list + ( make_option('--store', '-s', type='string', dest='store', - help='RDF data will be imported into the store with this identifier. If not specified, the default store ' + - 'is used.'), + help='RDF data will be imported into the store with this identifier. If not specified, the default store is used.'), make_option('--context', '-c', type='string', dest='context', - help='RDF data will be imported into a context with this identifier. If not specified, a new blank ' + - 'context is created.'), + help='RDF data will be imported into a context with this identifier. If not specified, a new blank context is created.'), - make_option('--format', '-f', type='string', dest='format', default='xml', - help='Format of the RDF data. This option accepts all formats allowed by rdflib. Defaults to xml.') - ) + make_option('--format', '-f', type='string', dest='format', + default='xml', + help='Format of the RDF data. This option accepts all formats allowed by rdflib. Defaults to xml.')) help = """Imports an RDF resource. @@ -37,7 +38,7 @@ class Command(BaseCommand): """.format(sys.argv[0]) args = 'file-or-resource' - @transaction.commit_on_success + @atomic_decorator def handle(self, *args, **options): if not args: raise CommandError("No file or resource specified.") @@ -48,7 +49,7 @@ def handle(self, *args, **options): source = args[0] if info: - print("Parsing {0}".format(source)) + print "Parsing {0}".format(source) intermediate = Graph() try: @@ -57,14 +58,14 @@ def handle(self, *args, **options): raise CommandError(e) if info: - print("Parsed {0} triples".format(len(intermediate))) + print "Parsed {0} triples".format(len(intermediate)) identifier = URIRef(context_id) if context_id else BNode() graph = utils.get_named_graph(identifier, store_id=store_id) if info: - print("Storing {0} triples".format(len(intermediate))) + print "Storing {0} triples".format(len(intermediate)) for triple in intermediate: graph.add(triple) if info: - print("Done") + print "Done" diff --git a/src/rdflib_django/models.py b/src/rdflib_django/models.py index d505108..bf987a5 100644 --- a/src/rdflib_django/models.py +++ b/src/rdflib_django/models.py @@ -5,7 +5,7 @@ to be used for publishing resources. """ from django.db import models -from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_lazy as _ from django_extensions.db.fields import UUIDField from rdflib_django import fields @@ -17,12 +17,12 @@ class NamedGraph(models.Model): identifier = fields.URIField(verbose_name=_("Identifier"), unique=True) - class Meta: + class Meta: # pylint: disable=C1001 verbose_name = _("named graph") verbose_name_plural = _("named graphs") def __unicode__(self): - return u"{0}".format(self.identifier, "identifier") + return u"{0}".format(self.identifier) class NamespaceModel(models.Model): @@ -38,7 +38,7 @@ class NamespaceModel(models.Model): uri = models.CharField(max_length=500, verbose_name=_("URI"), db_index=True, unique=True) fixed = models.BooleanField(verbose_name=_("Fixed"), editable=False, default=False) - class Meta: + class Meta: # pylint: disable=C1001 verbose_name = _("namespace") verbose_name_plural = _("namespaces") @@ -57,7 +57,7 @@ class URIStatement(models.Model): object = fields.URIField(_("Object"), db_index=True) context = models.ForeignKey(NamedGraph, verbose_name=_("Context")) - class Meta: + class Meta: # pylint: disable=C1001 unique_together = ('subject', 'predicate', 'object', 'context') def __unicode__(self): @@ -81,7 +81,7 @@ class LiteralStatement(models.Model): object = fields.LiteralField(_("Object"), db_index=True) context = models.ForeignKey(NamedGraph, verbose_name=_("Context")) - class Meta: + class Meta: # pylint: disable=C1001 unique_together = ('subject', 'predicate', 'object', 'context') def __unicode__(self): diff --git a/src/rdflib_django/store.py b/src/rdflib_django/store.py index 177e36b..5a877a1 100644 --- a/src/rdflib_django/store.py +++ b/src/rdflib_django/store.py @@ -48,7 +48,7 @@ def _get_named_graph(context): return models.NamedGraph.objects.get_or_create(identifier=context.identifier)[0] -class DjangoStore(rdflib.store.Store): +class DjangoStore(rdflib.store.Store): # pylint: disable=abstract-method """ RDFlib Store implementation the uses Django Models for storage and retrieval. @@ -170,7 +170,7 @@ def remove(self, (s, p, o), context=None): if o: filter_parameters['object'] = o - query_sets = [qs.filter(**filter_parameters) for qs in query_sets] # pylint: disable=W0142 + query_sets = [qs.filter(**filter_parameters) for qs in query_sets] for qs in query_sets: qs.delete() @@ -192,7 +192,7 @@ def triples(self, (s, p, o), context=None): if o: filter_parameters['object'] = o - query_sets = [qs.filter(**filter_parameters) for qs in query_sets] # pylint: disable=W0142 + query_sets = [qs.filter(**filter_parameters) for qs in query_sets] for qs in query_sets: for statement in qs: diff --git a/src/rdflib_django/test_rdflib.py b/src/rdflib_django/test_rdflib.py index 52c528c..25f86a4 100644 --- a/src/rdflib_django/test_rdflib.py +++ b/src/rdflib_django/test_rdflib.py @@ -527,7 +527,8 @@ def testTriples(self): self.assertEquals(set(c.subject_objects(self.hates)), {(self.bob, self.pizza), (self.bob, self.michel)}) self.assertEquals(set(c.subject_objects(self.likes)), - {(self.tarek, self.cheese), (self.michel, self.cheese), (self.michel, self.pizza), (self.bob, self.cheese), (self.tarek, self.pizza)}) + {(self.tarek, self.cheese), (self.michel, self.cheese), (self.michel, self.pizza), (self.bob, self.cheese), + (self.tarek, self.pizza)}) self.assertEquals(set(c.predicate_objects(self.michel)), {(self.likes, self.cheese), (self.likes, self.pizza)}) self.assertEquals(set(c.predicate_objects(self.bob)), {(self.likes, self.cheese), (self.hates, self.pizza), (self.hates, self.michel)}) @@ -538,8 +539,8 @@ def testTriples(self): self.assertEquals(set(c.subject_predicates(self.michel)), {(self.bob, self.hates)}) self.assertEquals(set(c), {(self.bob, self.hates, self.michel), (self.bob, self.likes, self.cheese), (self.tarek, self.likes, self.pizza), - (self.michel, self.likes, self.pizza), (self.michel, self.likes, self.cheese), (self.bob, self.hates, self.pizza), - (self.tarek, self.likes, self.cheese)}) + (self.michel, self.likes, self.pizza), (self.michel, self.likes, self.cheese), (self.bob, self.hates, self.pizza), + (self.tarek, self.likes, self.cheese)}) # remove stuff and make sure the graph is empty again self.removeStuff() diff --git a/src/rdflib_django/test_seq.py b/src/rdflib_django/test_seq.py index 55e25c5..ce92a88 100644 --- a/src/rdflib_django/test_seq.py +++ b/src/rdflib_django/test_seq.py @@ -27,8 +27,8 @@ def testSeq(self): """ items = self.store.seq(URIRef("http://example.org/Seq")) self.assertEquals(len(items), 6) - self.assertEquals(items[-1].concrete(), URIRef("http://example.org/six")) - self.assertEquals(items[2].concrete(), URIRef("http://example.org/three")) + self.assertEquals(items[-1], URIRef("http://example.org/six")) + self.assertEquals(items[2], URIRef("http://example.org/three")) # just make sure we can serialize self.store.serialize() diff --git a/src/rdflib_django/tests.py b/src/rdflib_django/tests.py index 47d3f0d..5351b08 100644 --- a/src/rdflib_django/tests.py +++ b/src/rdflib_django/tests.py @@ -14,8 +14,8 @@ def suite(): s = unittest.TestSuite() s.addTest(doctest.DocTestSuite(rdflib_django)) s.addTest(doctest.DocTestSuite(store)) - s.addTest(unittest.findTestCases(test_store)) - s.addTest(unittest.findTestCases(test_rdflib)) - s.addTest(unittest.findTestCases(test_seq)) - s.addTest(unittest.findTestCases(test_namespaces)) + s.addTest(unittest.findTestCases(test_store)) # pylint: disable=no-member + s.addTest(unittest.findTestCases(test_rdflib)) # pylint: disable=no-member + s.addTest(unittest.findTestCases(test_seq)) # pylint: disable=no-member + s.addTest(unittest.findTestCases(test_namespaces)) # pylint: disable=no-member return s diff --git a/src/rdflib_django/testsettings.py b/src/rdflib_django/testsettings.py index 71211a9..b0ece4a 100644 --- a/src/rdflib_django/testsettings.py +++ b/src/rdflib_django/testsettings.py @@ -61,3 +61,5 @@ }, } } + +SECRET_KEY = os.urandom(32) diff --git a/src/rdflib_django/urls.py b/src/rdflib_django/urls.py index 62df3b1..70d993e 100644 --- a/src/rdflib_django/urls.py +++ b/src/rdflib_django/urls.py @@ -10,6 +10,5 @@ admin.autodiscover() urlpatterns = patterns('', - (r'^admin/doc/', include('django.contrib.admindocs.urls')), - (r'^admin/', include(admin.site.urls)), - ) + (r'^admin/doc/', include('django.contrib.admindocs.urls')), + (r'^admin/', include(admin.site.urls)),)