Skip to content

Commit 11ca8dc

Browse files
committed
Modified the django patch check action from [14474] (for django issue #28772) to work with arbitrary locations of the virtual Python environment, rather than assuming a particular location of the virtual environment directory.
- Legacy-Id: 14487 Note: SVN reference [14474] has been migrated to Git commit bb92c0a
1 parent 4695ec5 commit 11ca8dc

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

ietf/checks.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,21 @@ def check_svn_import(app_configs, **kwargs):
351351
return errors
352352

353353
@checks.register('files')
354-
def maybe_patch_django_db_model_fields_unicode_comparison(app_configs, **kwargs):
354+
def maybe_patch_django(app_configs, **kwargs):
355355
errors = []
356-
for patch_file in settings.CHECKS_PATCHES_TO_APPLY:
357-
patch_set = patch.fromfile(patch_file)
356+
# Change path to our copy of django (this assumes we're running in a
357+
# virtualenv, which we should)
358+
import os, django
359+
django_path = os.path.dirname(django.__file__)
360+
parent_path = os.path.dirname(django_path)
361+
saved_cwd = os.getcwd()
362+
os.chdir(parent_path)
363+
# All patches in settings.CHECKS_DJANGO_PATCHES_TO_APPLY must have a
364+
# relative file path rooted in the django dir, for instance
365+
# 'django/db/models/fields/__init__.py'
366+
for patch_file in settings.CHECKS_DJANGO_PATCHES_TO_APPLY:
367+
patch_path = os.path.join(saved_cwd, patch_file)
368+
patch_set = patch.fromfile(patch_path)
358369
if patch_set:
359370
if not patch_set.apply():
360371
errors.append(checks.Warning(
@@ -368,6 +379,7 @@ def maybe_patch_django_db_model_fields_unicode_comparison(app_configs, **kwargs)
368379
hint="Make sure that the patch file contains a unified diff",
369380
id="datatracker.W0001",
370381
))
382+
os.chdir(saved_cwd)
371383
return errors
372384

373385
@checks.register('security')

ietf/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ def skip_unreadable_post(record):
927927
"fields.W342", # Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
928928
]
929929

930-
CHECKS_PATCHES_TO_APPLY = [
930+
CHECKS_DJANGO_PATCHES_TO_APPLY = [
931931
'patch/fix-django-unicode-comparison-bug.patch',
932932
]
933933

patch/fix-django-unicode-comparison-bug.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- ./../yang/env/lib/python2.7/site-packages/django/db/models/fields/__init__.py 2017-06-14 08:43:21.665812000 -0700
2-
+++ env/lib/python2.7/site-packages/django/db/models/fields/__init__.py 2017-12-17 14:34:03.023976702 -0800
1+
--- django/db/models/fields/__init__.py.old 2017-06-14 08:43:21.665812000 -0700
2+
+++ django/db/models/fields/__init__.py 2017-12-17 14:34:03.023976702 -0800
33
@@ -2323,7 +2323,7 @@
44
if self.has_default() and not callable(self.default):
55
return self.default

0 commit comments

Comments
 (0)