I am currently re-doing some exercises I lost in the LMP3THW.
In ex46:
I tend to hack away at stuff to figure it out, and realized on the first uninstall that all the old build, dist, and egg-info directories were left behind after uninstall.
If I want to start from scratch on a module modification and a new setup, I would want these removed yes?
So I made this little file to clean it up, so I can go modify away and not have to go through and delete each thing. I can run clean_up.py from my skeleton dir and it’ll remove the old stuff setup.py placed.
Should this be a common thing to include in modules?
#!usr/bin/python3
# Clean up old version of module in skeleton directory
# sys.argv[1] will be project_name.egg-info
#TO-DO:
# make a clean-up for __pychache__ and *.pyc
import os
import sys
import shutil
#get current directory path
cwd = os.getcwd()
cwd = cwd + "/"
#get module name egg-info
egg_dir = sys.argv[1]
#directories to be removed:
dist_path = cwd + 'dist'
build_path = cwd + 'build'
egg_path = cwd + egg_dir
#----------------------#
# remove egg directory #
#----------------------#
try:
shutil.rmtree(egg_path)
except OSError as e:
print("file not found: ", egg_path)
print("OSERROR: ", e.strerror)
#-----------------------------------#
# remove build and dist directories #
#-----------------------------------#
try:
shutil.rmtree(dist_path)
except OSError as e:
print("OSERROR: ", e.strerror)
print("shutil not found, or directory not found:", dist_path)
try:
shutil.rmtree(build_path)
except OSError as e:
print("OSERROR: ", e.strerror)
print("shutil not found, or directory not found:", build_path)