marker_files.py 823 B

123456789101112131415161718192021222324252627
  1. # The following comment should be removed at some point in the future.
  2. # mypy: disallow-untyped-defs=False
  3. import os.path
  4. DELETE_MARKER_MESSAGE = '''\
  5. This file is placed here by pip to indicate the source was put
  6. here by pip.
  7. Once this package is successfully installed this source code will be
  8. deleted (unless you remove this file).
  9. '''
  10. PIP_DELETE_MARKER_FILENAME = 'pip-delete-this-directory.txt'
  11. def has_delete_marker_file(directory):
  12. return os.path.exists(os.path.join(directory, PIP_DELETE_MARKER_FILENAME))
  13. def write_delete_marker_file(directory):
  14. # type: (str) -> None
  15. """
  16. Write the pip delete marker file into this directory.
  17. """
  18. filepath = os.path.join(directory, PIP_DELETE_MARKER_FILENAME)
  19. with open(filepath, 'w') as marker_fp:
  20. marker_fp.write(DELETE_MARKER_MESSAGE)