Skip to content

Commit

Permalink
Merge pull request #948 from qwcode/global_build_cleanup
Browse files Browse the repository at this point in the history
write pip delete marker into global build dir upon creation
  • Loading branch information
qwcode committed May 19, 2013
2 parents 6c924b3 + 66d8e7b commit 6042140
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
20 changes: 20 additions & 0 deletions pip/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
26 changes: 4 additions & 22 deletions pip/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -1228,7 +1216,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):
Expand Down Expand Up @@ -1343,13 +1331,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)
Expand Down

0 comments on commit 6042140

Please sign in to comment.