Commit 8ab50177 by Jesse Zoldak

Merge pull request #11777 from edx/zoldak/fix-python-uninstall

Always uninstall python packages on the uninstall list 
parents 62bbea6b 9251a6dc
...@@ -55,6 +55,15 @@ def no_prereq_install(): ...@@ -55,6 +55,15 @@ def no_prereq_install():
return False return False
def create_prereqs_cache_dir():
"""Create the directory for storing the hashes, if it doesn't exist already."""
try:
os.makedirs(PREREQS_STATE_DIR)
except OSError:
if not os.path.isdir(PREREQS_STATE_DIR):
raise
def compute_fingerprint(path_list): def compute_fingerprint(path_list):
""" """
Hash the contents of all the files and directories in `path_list`. Hash the contents of all the files and directories in `path_list`.
...@@ -107,12 +116,7 @@ def prereq_cache(cache_name, paths, install_func): ...@@ -107,12 +116,7 @@ def prereq_cache(cache_name, paths, install_func):
# Update the cache with the new hash # Update the cache with the new hash
# If the code executed within the context fails (throws an exception), # If the code executed within the context fails (throws an exception),
# then this step won't get executed. # then this step won't get executed.
try: create_prereqs_cache_dir()
os.makedirs(PREREQS_STATE_DIR)
except OSError:
if not os.path.isdir(PREREQS_STATE_DIR):
raise
with open(cache_file_path, "w") as cache_file: with open(cache_file_path, "w") as cache_file:
# Since the pip requirement files are modified during the install # Since the pip requirement files are modified during the install
# process, we need to store the hash generated AFTER the installation # process, we need to store the hash generated AFTER the installation
...@@ -162,7 +166,6 @@ PACKAGES_TO_UNINSTALL = [ ...@@ -162,7 +166,6 @@ PACKAGES_TO_UNINSTALL = [
] ]
@task
def uninstall_python_packages(): def uninstall_python_packages():
""" """
Uninstall Python packages that need explicit uninstallation. Uninstall Python packages that need explicit uninstallation.
...@@ -179,6 +182,7 @@ def uninstall_python_packages(): ...@@ -179,6 +182,7 @@ def uninstall_python_packages():
hasher.update(repr(PACKAGES_TO_UNINSTALL)) hasher.update(repr(PACKAGES_TO_UNINSTALL))
expected_version = hasher.hexdigest() expected_version = hasher.hexdigest()
state_file_path = os.path.join(PREREQS_STATE_DIR, "Python_uninstall.sha1") state_file_path = os.path.join(PREREQS_STATE_DIR, "Python_uninstall.sha1")
create_prereqs_cache_dir()
if os.path.isfile(state_file_path): if os.path.isfile(state_file_path):
with open(state_file_path) as state_file: with open(state_file_path) as state_file:
...@@ -238,6 +242,8 @@ def install_python_prereqs(): ...@@ -238,6 +242,8 @@ def install_python_prereqs():
print NO_PREREQ_MESSAGE print NO_PREREQ_MESSAGE
return return
uninstall_python_packages()
# Include all of the requirements files in the fingerprint. # Include all of the requirements files in the fingerprint.
files_to_fingerprint = list(PYTHON_REQ_FILES) files_to_fingerprint = list(PYTHON_REQ_FILES)
...@@ -270,5 +276,4 @@ def install_prereqs(): ...@@ -270,5 +276,4 @@ def install_prereqs():
return return
install_node_prereqs() install_node_prereqs()
uninstall_python_packages()
install_python_prereqs() install_python_prereqs()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment