summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Johnson <atagar@torproject.org>2015-03-02 09:23:07 -0800
committerDamian Johnson <atagar@torproject.org>2015-03-02 09:25:28 -0800
commitb8411f0dafab408f42f2b00ab6622fa64c6d120d (patch)
tree5ff3ad4466cbdb2ca458931cc1c864e655249f0e
parent8264bebc278a20a6bdf31391d72854c712fefc9a (diff)
Clear orphaned pyc files for python3
Task to ensure we don't test against bytecode for deleted or renamed files. Initial patch thanks to dumindux. https://trac.torproject.org/projects/tor/ticket/14628
-rw-r--r--stem/util/test_tools.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/stem/util/test_tools.py b/stem/util/test_tools.py
index 2e4dd0b2..c8fe76a7 100644
--- a/stem/util/test_tools.py
+++ b/stem/util/test_tools.py
@@ -53,17 +53,22 @@ def clean_orphaned_pyc(paths):
for path in paths:
for pyc_path in stem.util.system.files_with_suffix(path, '.pyc'):
+ py_path = pyc_path[:-1]
+
# If we're running python 3 then the *.pyc files are no longer bundled
# with the *.py. Rather, they're in a __pycache__ directory.
- # TODO: At the moment there's no point in checking for orphaned bytecode
- # with python 3 because it's an exported copy of the python 2 codebase,
- # so skipping. However, we might want to address this for other callers.
+ pycache = '%s__pycache__%s' % (os.path.sep, os.path.sep)
+
+ if pycache in pyc_path:
+ directory, pycache_filename = pyc_path.split(pycache, 1)
+
+ if not pycache_filename.endswith('.pyc'):
+ continue # should look like 'test_tools.cpython-32.pyc'
- if '__pycache__' in pyc_path:
- continue
+ py_path = os.path.join(directory, pycache_filename.split('.')[0] + '.py')
- if not os.path.exists(pyc_path[:-1]):
+ if not os.path.exists(py_path):
orphaned_pyc.append(pyc_path)
os.remove(pyc_path)