Fix for #8560 + indentation fix in setup.py

This pull request contains a fix for the pkgrepo fix in #8560, as well as an IndentationError that keeps setup.py from running successfully.

The fix for #8560 is being made here in 0.17 because there has been a bit of churn in the pkgrepo.managed state, and develop works fine. It looks like something got cherrypicked that shouldn't have, or the cherrypick resulted in a merge conflict that was not properly resolved due to the divergence in the logic between 0.17.0 and the current develop branch.