Skip to content
Snippets Groups Projects
Commit b8411f0d authored by Damian Johnson's avatar Damian Johnson
Browse files

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
parent 8264bebc
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment