Skip to content

Commit

Permalink
Fix cache-clearing to work with directories
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjward committed Jul 21, 2021
1 parent ec55e8e commit c57aafc
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pyop2/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@


import os
import shutil
import subprocess
import sys
import ctypes
Expand Down Expand Up @@ -503,28 +504,26 @@ def clear_cache(prompt=False):
if not os.path.exists(cachedir):
return

files = [os.path.join(cachedir, f) for f in os.listdir(cachedir)
if os.path.isfile(os.path.join(cachedir, f))]
nfiles = len(files)
dirs = [os.path.join(cachedir, dir_) for dir_ in os.listdir(cachedir)]
ndirs = len(dirs)

if nfiles == 0:
if ndirs == 0:
print("No cached libraries to remove")
return

remove = True
if prompt:

user = input("Remove %d cached libraries from %s? [Y/n]: " % (nfiles, cachedir))
user = input("Remove %d cached libraries from %s? [Y/n]: " % (ndirs, cachedir))

while user.lower() not in ['', 'y', 'n']:
print("Please answer y or n.")
user = input("Remove %d cached libraries from %s? [Y/n]: " % (nfiles, cachedir))
user = input("Remove %d cached libraries from %s? [Y/n]: " % (ndirs, cachedir))

if user.lower() == 'n':
remove = False

if remove:
print("Removing %d cached libraries from %s" % (nfiles, cachedir))
[os.remove(f) for f in files]
print("Removing %d cached libraries from %s" % (ndirs, cachedir))
[shutil.rmtree(dir_) for dir_ in dirs]
else:
print("Not removing cached libraries")

0 comments on commit c57aafc

Please sign in to comment.