configuration.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # coding=utf-8
  2. #
  3. # This file is part of Hypothesis, which may be found at
  4. # https://github.com/HypothesisWorks/hypothesis-python
  5. #
  6. # Most of this work is copyright (C) 2013-2018 David R. MacIver
  7. # (david@drmaciver.com), but it contains contributions by others. See
  8. # CONTRIBUTING.rst for a full list of people who may hold copyright, and
  9. # consult the git log if you need to determine who owns an individual
  10. # contribution.
  11. #
  12. # This Source Code Form is subject to the terms of the Mozilla Public License,
  13. # v. 2.0. If a copy of the MPL was not distributed with this file, You can
  14. # obtain one at http://mozilla.org/MPL/2.0/.
  15. #
  16. # END HEADER
  17. from __future__ import division, print_function, absolute_import
  18. import os
  19. __hypothesis_home_directory_default = os.path.join(os.getcwd(), '.hypothesis')
  20. __hypothesis_home_directory = None
  21. def set_hypothesis_home_dir(directory):
  22. global __hypothesis_home_directory
  23. __hypothesis_home_directory = directory
  24. def mkdir_p(path):
  25. try:
  26. os.makedirs(path)
  27. except OSError:
  28. pass
  29. def hypothesis_home_dir():
  30. global __hypothesis_home_directory
  31. if not __hypothesis_home_directory:
  32. __hypothesis_home_directory = os.getenv(
  33. 'HYPOTHESIS_STORAGE_DIRECTORY')
  34. if not __hypothesis_home_directory:
  35. __hypothesis_home_directory = __hypothesis_home_directory_default
  36. mkdir_p(__hypothesis_home_directory)
  37. return __hypothesis_home_directory
  38. def storage_directory(*names):
  39. path = os.path.join(hypothesis_home_dir(), *names)
  40. mkdir_p(path)
  41. return path
  42. def tmpdir():
  43. return storage_directory('tmp')