Skip to content

Commit e5bc9c2

Browse files
committed
Removed the use of os.chdir() during patching, instead passing the found library path to the patcher.
- Legacy-Id: 14757
1 parent cf9804f commit e5bc9c2

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

ietf/checks.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,23 +358,21 @@ def maybe_patch_library(app_configs, **kwargs):
358358
import os, django
359359
django_path = os.path.dirname(django.__file__)
360360
library_path = os.path.dirname(django_path)
361-
saved_cwd = os.getcwd()
361+
cwd = os.getcwd()
362362
# All patches in settings.CHECKS_LIBRARY_PATCHES_TO_APPLY must have a
363363
# relative file path rooted in the django dir, for instance
364364
# 'django/db/models/fields/__init__.py'
365365
for patch_file in settings.CHECKS_LIBRARY_PATCHES_TO_APPLY:
366366
try:
367-
patch_path = os.path.join(saved_cwd, patch_file)
367+
patch_path = os.path.join(cwd, patch_file)
368368
patch_set = patch.fromfile(patch_path)
369369
if patch_set:
370-
os.chdir(library_path)
371-
if not patch_set.apply():
370+
if not patch_set.apply(root=library_path):
372371
errors.append(checks.Warning(
373372
"Could not apply patch from file '%s'"%patch_file,
374373
hint="Make sure that the patch file contains a unified diff and has valid file paths",
375374
id="datatracker.W0002",
376375
))
377-
os.chdir(saved_cwd)
378376
else:
379377
errors.append(checks.Warning(
380378
"Could not parse patch file '%s'"%patch_file,

0 commit comments

Comments
 (0)