Skip to content

Commit

Permalink
if venv/include empty (usually is) delete
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed May 8, 2023
1 parent 8bf06b2 commit 648ec10
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions share/brewkit/python-venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ def run(cmd_array):
logging.debug("+{}".format(" ".join(cmd_array)))
subprocess.run(cmd_array, check=True)

def delete_empty_dirs(directory):
# list all files and directories in the current directory
contents = os.listdir(directory)

# recursively check all subdirectories for emptiness
for item in contents:
path = os.path.join(directory, item)
if os.path.isdir(path):
delete_empty_dirs(path) # recursively check subdirectory
else:
return # exit if a non-empty file is found

# if we reach here, all subdirectories are empty; delete the current directory
os.rmdir(directory)

def main():
parser = argparse.ArgumentParser(description='')
Expand Down Expand Up @@ -123,6 +137,8 @@ def main():
logging.debug("chmod 0o755 {}".format(save_file))
os.chmod(save_file, 0o755)

# usually empty and thus lets delete it
delete_empty_dirs(os.path.join(virtual_env, "include"))

if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
Expand Down

0 comments on commit 648ec10

Please sign in to comment.