Skip to content

Commit 4113304

Browse files
committed
Make migrations python3 friendly
Under python3 `makemigrations` complains that `package_monitor` has changes in models which are not reflected in its migrations. It's caused by b'' strings.
1 parent d190bf3 commit 4113304

9 files changed

+49
-23
lines changed
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
2+
from __future__ import unicode_literals
33

44
from django.db import migrations, models
55
import semantic_version.django_fields
@@ -15,15 +15,15 @@ class Migration(migrations.Migration):
1515
name='PackageVersion',
1616
fields=[
1717
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
18-
('raw', models.CharField(help_text=b'The line specified in the requirements file.', max_length=200)),
19-
('package_name', models.CharField(help_text=b'The name of the package on PyPI.', unique=True, max_length=100)),
20-
('current_version', semantic_version.django_fields.VersionField(help_text=b'The current version as specified in the requirements file. ', max_length=200, null=True, blank=True)),
21-
('latest_version', semantic_version.django_fields.VersionField(help_text=b'Latest version available from PyPI.', max_length=200, null=True, blank=True)),
22-
('licence', models.CharField(help_text=b'The licence used (extracted from PyPI info).', max_length=100, blank=True)),
23-
('diff_status', models.CharField(default=b'unknown', help_text=b'The diff between current and latest versions. Updated via update_latest_version.', max_length=10, choices=[(b'unknown', b'Unknown'), (b'none', b'Up-to-date'), (b'major', b'Major'), (b'minor', b'Minor'), (b'patch', b'Patch'), (b'other', b'Other')])),
24-
('checked_pypi_at', models.DateTimeField(help_text=b'When PyPI was last checked for this package.', null=True, blank=True)),
25-
('is_editable', models.BooleanField(default=False, help_text=b"True if this requirement is specified with '-e' flag.")),
26-
('url', models.URLField(help_text=b'The URL to check - PyPI or repo (if editable).', null=True, blank=True)),
18+
('raw', models.CharField(help_text='The line specified in the requirements file.', max_length=200)),
19+
('package_name', models.CharField(help_text='The name of the package on PyPI.', unique=True, max_length=100)),
20+
('current_version', semantic_version.django_fields.VersionField(help_text='The current version as specified in the requirements file. ', max_length=200, null=True, blank=True)),
21+
('latest_version', semantic_version.django_fields.VersionField(help_text='Latest version available from PyPI.', max_length=200, null=True, blank=True)),
22+
('licence', models.CharField(help_text='The licence used (extracted from PyPI info).', max_length=100, blank=True)),
23+
('diff_status', models.CharField(default='unknown', help_text='The diff between current and latest versions. Updated via update_latest_version.', max_length=10, choices=[('unknown', 'Unknown'), ('none', 'Up-to-date'), ('major', 'Major'), ('minor', 'Minor'), ('patch', 'Patch'), ('other', 'Other')])),
24+
('checked_pypi_at', models.DateTimeField(help_text='When PyPI was last checked for this package.', null=True, blank=True)),
25+
('is_editable', models.BooleanField(default=False, help_text="True if this requirement is specified with '-e' flag.")),
26+
('url', models.URLField(help_text='The URL to check - PyPI or repo (if editable).', null=True, blank=True)),
2727
],
2828
),
2929
]

package_monitor/migrations/0002_auto_20151126_1453.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
2+
from __future__ import unicode_literals
33

44
from django.db import migrations, models
55

package_monitor/migrations/0003_packageversion_next_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
2+
from __future__ import unicode_literals
33

44
from django.db import migrations, models
55
import semantic_version.django_fields
@@ -15,6 +15,6 @@ class Migration(migrations.Migration):
1515
migrations.AddField(
1616
model_name='packageversion',
1717
name='next_version',
18-
field=semantic_version.django_fields.VersionField(help_text=b'Next available version available from PyPI.', max_length=200, null=True, blank=True),
18+
field=semantic_version.django_fields.VersionField(help_text='Next available version available from PyPI.', max_length=200, null=True, blank=True),
1919
),
2020
]

package_monitor/migrations/0004_auto_20160109_1339.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
2+
from __future__ import unicode_literals
33

44
from django.db import migrations, models
55

@@ -14,11 +14,11 @@ class Migration(migrations.Migration):
1414
migrations.AlterField(
1515
model_name='packageversion',
1616
name='is_editable',
17-
field=models.BooleanField(default=False, help_text=b"True if this requirement is specified with '-e' flag.", verbose_name=b'Editable (-e)'),
17+
field=models.BooleanField(default=False, help_text="True if this requirement is specified with '-e' flag.", verbose_name='Editable (-e)'),
1818
),
1919
migrations.AlterField(
2020
model_name='packageversion',
2121
name='url',
22-
field=models.URLField(help_text=b'The PyPI URL to check - (blank if editable).', null=True, blank=True),
22+
field=models.URLField(help_text='The PyPI URL to check - (blank if editable).', null=True, blank=True),
2323
),
2424
]

package_monitor/migrations/0005_packageversion_is_parseable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
2+
from __future__ import unicode_literals
33

44
from django.db import migrations, models
55

@@ -14,6 +14,6 @@ class Migration(migrations.Migration):
1414
migrations.AddField(
1515
model_name='packageversion',
1616
name='is_parseable',
17-
field=models.BooleanField(default=False, help_text=b'True if the version can be parsed as a valid semver version.', verbose_name=b'Parseable'),
17+
field=models.BooleanField(default=False, help_text='True if the version can be parsed as a valid semver version.', verbose_name='Parseable'),
1818
),
1919
]

package_monitor/migrations/0006_add_python_version_info.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
2+
from __future__ import unicode_literals
33

44
from django.db import migrations, models
55

@@ -14,12 +14,12 @@ class Migration(migrations.Migration):
1414
migrations.AddField(
1515
model_name='packageversion',
1616
name='python_support',
17-
field=models.CharField(default='', help_text=b'Python version support as specified in the PyPI classifiers.', max_length=100),
17+
field=models.CharField(default='', help_text='Python version support as specified in the PyPI classifiers.', max_length=100),
1818
preserve_default=False,
1919
),
2020
migrations.AddField(
2121
model_name='packageversion',
2222
name='supports_py3',
23-
field=models.NullBooleanField(default=None, help_text=b'Does this package support Python3?'),
23+
field=models.NullBooleanField(default=None, help_text='Does this package support Python3?'),
2424
),
2525
]

package_monitor/migrations/0007_add_django_version_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class Migration(migrations.Migration):
1414
migrations.AddField(
1515
model_name='packageversion',
1616
name='django_support',
17-
field=models.CharField(help_text=b'Django version support as specified in the PyPI classifiers.', max_length=100, null=True, blank=True),
17+
field=models.CharField(help_text='Django version support as specified in the PyPI classifiers.', max_length=100, null=True, blank=True),
1818
),
1919
migrations.AlterField(
2020
model_name='packageversion',
2121
name='python_support',
22-
field=models.CharField(help_text=b'Python version support as specified in the PyPI classifiers.', max_length=100, null=True, blank=True),
22+
field=models.CharField(help_text='Python version support as specified in the PyPI classifiers.', max_length=100, null=True, blank=True),
2323
),
2424
]

package_monitor/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# *-8 coding: utf-8 -*-
22
"""Parse requirements file, and work out whether there are any updates."""
3+
from __future__ import unicode_literals
4+
35
import logging
46

57
from django.db import models
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import unicode_literals
2+
3+
from django.apps import apps
4+
from django.db import connection
5+
from django.db.migrations.autodetector import MigrationAutodetector
6+
from django.db.migrations.executor import MigrationExecutor
7+
from django.db.migrations.state import ProjectState
8+
from django.test import TestCase
9+
10+
11+
class MigrationsTests(TestCase):
12+
13+
def test_for_missing_migrations(self):
14+
"""Checks if there're models changes which aren't reflected in migrations."""
15+
migrations_loader = MigrationExecutor(connection).loader
16+
migrations_detector = MigrationAutodetector(
17+
from_state=migrations_loader.project_state(),
18+
to_state=ProjectState.from_apps(apps)
19+
)
20+
if migrations_detector.changes(graph=migrations_loader.graph):
21+
self.fail(
22+
'Your models have changes that are not yet reflected '
23+
'in a migration. You should add them now.'
24+
)

0 commit comments

Comments
 (0)