Skip to content

Commit a137384

Browse files
authored
Merge pull request #408 from apdavison/internalise-tagging
Internalise code for tag management
2 parents fe5bf09 + cc625cc commit a137384

11 files changed

Lines changed: 465 additions & 25 deletions

File tree

LICENSE

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,63 @@ Redistribution and use in source and binary forms, with or without modification,
77

88
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
99

10-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11+
12+
13+
Some of the Sumatra code is taken from/based on the django-tagging package:
14+
15+
Django Tagging
16+
--------------
17+
18+
Copyright (c) 2007-2015, Jonathan Buchanan, Julien Fache
19+
20+
Permission is hereby granted, free of charge, to any person obtaining a copy of
21+
this software and associated documentation files (the "Software"), to deal in
22+
the Software without restriction, including without limitation the rights to
23+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
24+
the Software, and to permit persons to whom the Software is furnished to do so,
25+
subject to the following conditions:
26+
27+
The above copyright notice and this permission notice shall be included in all
28+
copies or substantial portions of the Software.
29+
30+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
32+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
33+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
34+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36+
37+
Initially based on code from James Bennett's Cab:
38+
39+
Cab
40+
---
41+
42+
Copyright (c) 2007, James Bennett
43+
All rights reserved.
44+
45+
Redistribution and use in source and binary forms, with or without
46+
modification, are permitted provided that the following conditions are
47+
met:
48+
49+
* Redistributions of source code must retain the above copyright
50+
notice, this list of conditions and the following disclaimer.
51+
* Redistributions in binary form must reproduce the above
52+
copyright notice, this list of conditions and the following
53+
disclaimer in the documentation and/or other materials provided
54+
with the distribution.
55+
* Neither the name of the author nor the names of other
56+
contributors may be used to endorse or promote products derived
57+
from this software without specific prior written permission.
58+
59+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
60+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
61+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
62+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
63+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
64+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
65+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
66+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
67+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
68+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
69+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Requirements
5050
============
5151

5252
Sumatra requires Python version 3.9 or later The web interface requires
53-
Django (>= 4.2) and the django-tagging package.
53+
Django (>= 4.2).
5454
Sumatra requires that you keep your own code in a version control
5555
system (currently Subversion, Mercurial, Git and Bazaar are supported). If you
5656
are already using Bazaar there is nothing else to install. If you

doc/authors.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ Licence
6262
=======
6363

6464
Sumatra is freely available under the BSD 2-clause license.
65+
66+
67+
django-tagging
68+
==============
69+
70+
Some of the code in Sumatra's `django_store` module is taken from or based on
71+
the django-tagging package, by Jonathan Buchanan and Julien Fache,
72+
which in turn was based on the Cab package by James Bennett.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ hg = ["mercurial", "hgapi"]
5555

5656
web = [
5757
"docutils",
58-
"Django<6",
59-
"django-tagging@git+https://github.com/jazzband/django-tagging"
58+
"Django<6"
6059
]
6160

6261
remote = ["httplib2"]

sumatra/recordstore/django_store/__init__.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
from urllib.request import urlparse
2727
from io import StringIO
2828

29-
# Check that django-tagging is available. It would be better to try importing
30-
# it, but that seems to mess with Django's internals.
31-
importlib.util.find_spec("tagging")
32-
3329

3430
def db_id(db):
3531
"""Return a unique identifier for a database, for comparison purposes."""
@@ -49,8 +45,7 @@ def __init__(self):
4945
'DEBUG': True,
5046
'DATABASES': {},
5147
'INSTALLED_APPS': ['sumatra.recordstore.django_store',
52-
'django.contrib.contenttypes', # needed for tagging
53-
'tagging'],
48+
'django.contrib.contenttypes'],
5449
'MIDDLEWARE_CLASSES': [],
5550
'READ_ONLY': 0,
5651
'SERVERSIDE': 0,
@@ -329,8 +324,8 @@ def clear(self):
329324
cmds = ["BEGIN;"] + ['DROP TABLE "django_store_{0}";'.format(x)
330325
for x in ("record", "record_input_data", "record_dependencies",
331326
"record_platforms", "platforminformation", "datakey", "datastore", "launchmode",
327+
"taggeditem", "tag",
332328
"parameterset", "repository", "dependency", "executable", "project")] + ["COMMIT;"]
333-
# todo: also drop tagging_taggeditem, tagging_tag
334329
from django.db import connection
335330
cur = connection.cursor()
336331
for cmd in cmds:
@@ -344,7 +339,7 @@ def _dump(self, indent=2):
344339
import sys
345340
data = StringIO()
346341
sys.stdout = data
347-
management.call_command('dumpdata', 'django_store', 'tagging', indent=indent)
342+
management.call_command('dumpdata', 'django_store', indent=indent)
348343
sys.stdout = sys.__stdout__
349344
data.seek(0)
350345
return data.read()

sumatra/recordstore/django_store/migrations/0001_initial.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Generated by Django 5.2 on 2025-04-16 08:53
22

33
import django.db.models.deletion
4-
import tagging.fields
54
from django.db import migrations, models
65

6+
from ..models import TagField
7+
78

89
class Migration(migrations.Migration):
910

@@ -139,7 +140,7 @@ class Migration(migrations.Migration):
139140
('version', models.CharField(max_length=50)),
140141
('outcome', models.TextField(blank=True)),
141142
('timestamp', models.DateTimeField()),
142-
('tags', tagging.fields.TagField(blank=True, max_length=255)),
143+
('tags', TagField(blank=True, max_length=255)),
143144
('diff', models.TextField(blank=True)),
144145
('user', models.CharField(max_length=100)),
145146
('script_arguments', models.TextField(blank=True)),
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Generated by Django 5.2 on 2025-04-18 14:15
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('contenttypes', '0002_remove_content_type_name'),
11+
('django_store', '0001_initial'),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='Tag',
17+
fields=[
18+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('name', models.CharField(db_index=True, max_length=50, unique=True, verbose_name='name')),
20+
],
21+
options={
22+
'verbose_name': 'tag',
23+
'verbose_name_plural': 'tags',
24+
'ordering': ('name',),
25+
},
26+
),
27+
migrations.CreateModel(
28+
name='TaggedItem',
29+
fields=[
30+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
31+
('object_id', models.PositiveIntegerField(db_index=True, verbose_name='object id')),
32+
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype', verbose_name='content type')),
33+
('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='django_store.tag', verbose_name='tag')),
34+
],
35+
options={
36+
'verbose_name': 'tagged item',
37+
'verbose_name_plural': 'tagged items',
38+
'unique_together': {('tag', 'content_type', 'object_id')},
39+
},
40+
),
41+
]

sumatra/recordstore/django_store/models.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66
:license: BSD 2-clause, see LICENSE for details.
77
"""
88

9+
from datetime import datetime
910
import json
11+
12+
from packaging.version import parse as parse_version
1013
from django.db import models
14+
import django
15+
1116
from sumatra import programs, launch, datastore, records, versioncontrol, parameters, dependency_finder
1217
from sumatra.datastore import get_data_store
13-
from datetime import datetime
14-
import django
15-
from packaging.version import parse as parse_version
1618
from sumatra.core import get_registered_components
17-
import warnings
18-
with warnings.catch_warnings():
19-
warnings.simplefilter("ignore")
20-
import tagging.fields
21-
from tagging.models import Tag
19+
20+
from .tagging import TagField, Tag, TaggedItem, TagManager
2221

2322

2423
class SumatraObjectsManager(models.Manager):
@@ -257,7 +256,7 @@ class Record(BaseModel):
257256
input_datastore = models.ForeignKey(Datastore, related_name="input_to_records", on_delete=models.PROTECT)
258257
outcome = models.TextField(blank=True)
259258
timestamp = models.DateTimeField()
260-
tags = tagging.fields.TagField()
259+
tags = TagField()
261260
dependencies = models.ManyToManyField(Dependency)
262261
platforms = models.ManyToManyField(PlatformInformation)
263262
diff = models.TextField(blank=True)

0 commit comments

Comments
 (0)