py31compat.py 553 B

123456789101112131415161718192021
  1. import os
  2. import errno
  3. import sys
  4. def _makedirs_31(path, exist_ok=False):
  5. try:
  6. os.makedirs(path)
  7. except OSError as exc:
  8. if not exist_ok or exc.errno != errno.EEXIST:
  9. raise
  10. # rely on compatibility behavior until mode considerations
  11. # and exists_ok considerations are disentangled.
  12. # See https://github.com/pypa/setuptools/pull/1083#issuecomment-315168663
  13. needs_makedirs = (
  14. sys.version_info.major == 2 or
  15. (3, 4) <= sys.version_info < (3, 4, 1)
  16. )
  17. makedirs = _makedirs_31 if needs_makedirs else os.makedirs