[Python-checkins] bpo-46678: Fix Invalid cross device link in Lib/test/support/import_helper.py (GH-31204)
miss-islington
webhook-mailer at python.org
Mon Feb 7 20:09:28 EST 2022
https://github.com/python/cpython/commit/da576e08296490e94924421af71001bcfbccb317
commit: da576e08296490e94924421af71001bcfbccb317
branch: main
author: Jason Wilkes <notarealdeveloper at gmail.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-02-07T17:09:07-08:00
summary:
bpo-46678: Fix Invalid cross device link in Lib/test/support/import_helper.py (GH-31204)
In [Lib/test/support/import_helper.py](https://github.com/python/cpython/blob/master/Lib/test/support/import_helper.py), the function `make_legacy_pyc` makes a call to `os.rename` which can fail when the source and target live on different devices. This happens (for example) when `PYTHONPYCACHEPREFIX` is set to a directory anywhere on disk, while a ramdisk is mounted on `/tmp` (the latter of which is the default on various Linux distros). Replacing `os.rename` with `shutil.move` fixes this.
Automerge-Triggered-By: GH:brettcannon
files:
A Misc/NEWS.d/next/Tests/2022-02-07-12-40-45.bpo-46678.zfOrgL.rst
M Lib/test/support/import_helper.py
diff --git a/Lib/test/support/import_helper.py b/Lib/test/support/import_helper.py
index 9bce29895249a..5201dc84cf6df 100644
--- a/Lib/test/support/import_helper.py
+++ b/Lib/test/support/import_helper.py
@@ -3,6 +3,7 @@
import importlib
import importlib.util
import os
+import shutil
import sys
import unittest
import warnings
@@ -59,7 +60,7 @@ def make_legacy_pyc(source):
pyc_file = importlib.util.cache_from_source(source)
up_one = os.path.dirname(os.path.abspath(source))
legacy_pyc = os.path.join(up_one, source + 'c')
- os.rename(pyc_file, legacy_pyc)
+ shutil.move(pyc_file, legacy_pyc)
return legacy_pyc
diff --git a/Misc/NEWS.d/next/Tests/2022-02-07-12-40-45.bpo-46678.zfOrgL.rst b/Misc/NEWS.d/next/Tests/2022-02-07-12-40-45.bpo-46678.zfOrgL.rst
new file mode 100644
index 0000000000000..e369cb1f67baf
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2022-02-07-12-40-45.bpo-46678.zfOrgL.rst
@@ -0,0 +1,3 @@
+The function ``make_legacy_pyc`` in ``Lib/test/support/import_helper.py`` no
+longer fails when ``PYTHONPYCACHEPREFIX`` is set to a directory on a
+different device from where tempfiles are stored.
More information about the Python-checkins
mailing list