fix AttributeError: 'thread._local' object has no attribute 'indentatation' by BrownTruck · Pull Request #3733 · pypa/pip (original) (raw)

when i run main command from python under Django, logging fails with this error because threadig state has no attribute indentation, this solution uses helper for optional indentation

Exception:
Traceback (most recent call last):
  File "/srv/leonardo/sites/majklk/local/lib/python2.7/site-packages/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/srv/leonardo/sites/majklk/local/lib/python2.7/site-packages/pip/commands/install.py", line 344, in run
    requirement_set.cleanup_files()
  File "/srv/leonardo/sites/majklk/local/lib/python2.7/site-packages/pip/req/req_set.py", line 589, in cleanup_files
    with indent_log():
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/srv/leonardo/sites/majklk/local/lib/python2.7/site-packages/pip/utils/logging.py", line 38, in indent_log
    _log_state.indentation -= num
AttributeError: 'thread._local' object has no attribute 'indentation'

This was automatically migrated from #3161 to reparent it to the master branch. Please see original pull request for any previous discussion.