From 66d8e7b8c7d61bdda84a3860a5b4cf965a3e4179 Mon Sep 17 00:00:00 2001 From: Marcus Smith Date: Sat, 18 May 2013 18:05:25 -0700 Subject: [PATCH] write pip delete marker into global build dir upon creation --- pip/locations.py | 20 ++++++++++++++++++++ pip/req.py | 26 ++++---------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/pip/locations.py b/pip/locations.py index 10580cfd432..9f555b4a21d 100644 --- a/pip/locations.py +++ b/pip/locations.py @@ -11,6 +11,25 @@ default_cert_path = os.path.join(os.path.dirname(__file__), 'cacert.pem') +DELETE_MARKER_MESSAGE = '''\ +This file is placed here by pip to indicate the source was put +here by pip. + +Once this package is successfully installed this source code will be +deleted (unless you remove this file). +''' +PIP_DELETE_MARKER_FILENAME = 'pip-delete-this-directory.txt' + +def write_delete_marker_file(directory): + """ + Write the pip delete marker file into this directory. + """ + filepath = os.path.join(directory, PIP_DELETE_MARKER_FILENAME) + marker_fp = open(filepath, 'w') + marker_fp.write(DELETE_MARKER_MESSAGE) + marker_fp.close() + + def running_under_virtualenv(): """ Return True if we're running inside a virtualenv, False otherwise. @@ -38,6 +57,7 @@ def _get_build_prefix(): return path try: os.mkdir(path) + write_delete_marker_file(path) except OSError: file_uid = None try: diff --git a/pip/req.py b/pip/req.py index 90809f6bd2b..5b69fa07b89 100644 --- a/pip/req.py +++ b/pip/req.py @@ -10,7 +10,8 @@ import zipfile from distutils.util import change_root -from pip.locations import bin_py, running_under_virtualenv +from pip.locations import (bin_py, running_under_virtualenv,PIP_DELETE_MARKER_FILENAME, + write_delete_marker_file) from pip.exceptions import (InstallationError, UninstallationError, BestVersionAlreadyInstalled, DistributionNotFound, PreviousBuildDirError) @@ -33,10 +34,6 @@ import pip.wheel from pip.wheel import move_wheel_files - -PIP_DELETE_MARKER_FILENAME = 'pip-delete-this-directory.txt' - - class InstallRequirement(object): def __init__(self, req, comes_from, source_dir=None, editable=False, @@ -801,15 +798,6 @@ def delete_marker_filename(self): return os.path.join(self.source_dir, PIP_DELETE_MARKER_FILENAME) -DELETE_MARKER_MESSAGE = '''\ -This file is placed here by pip to indicate the source was put -here by pip. - -Once this package is successfully installed this source code will be -deleted (unless you remove this file). -''' - - class Requirements(object): def __init__(self): @@ -1220,7 +1208,7 @@ def unpack_url(self, link, location, only_download=False): self.download_cache = os.path.expanduser(self.download_cache) retval = unpack_http_url(link, location, self.download_cache, self.download_dir) if only_download: - _write_delete_marker_message(os.path.join(location, PIP_DELETE_MARKER_FILENAME)) + write_delete_marker_file(location) return retval def install(self, install_options, global_options=(), *args, **kwargs): @@ -1335,13 +1323,7 @@ def _clean_zip_name(self, name, prefix): def _make_build_dir(build_dir): os.makedirs(build_dir) - _write_delete_marker_message(os.path.join(build_dir, PIP_DELETE_MARKER_FILENAME)) - - -def _write_delete_marker_message(filepath): - marker_fp = open(filepath, 'w') - marker_fp.write(DELETE_MARKER_MESSAGE) - marker_fp.close() + write_delete_marker_file(build_dir) _scheme_re = re.compile(r'^(http|https|file):', re.I)