PyCQA / flake8-import-order

Flake8 plugin that checks import order against various Python Style Guides
GNU Lesser General Public License v3.0
278 stars 72 forks source link

Use package parents for namespace package support #128

Closed taion closed 6 years ago

taion commented 6 years ago

This is a different stab at https://github.com/PyCQA/flake8-import-order/pull/126 or https://github.com/PyCQA/flake8-import-order/commit/79540957450b20e7a8a382f6827f0f0a4c2c64cc, per https://github.com/PyCQA/flake8-import-order/issues/111#issuecomment-319143763, and it has Python 2 support.

Instead of caring about namespace packages per se, we just walk up the chain of all the parent packages, and take the first "hit". That way if you specify foo.bar in application_package_names and foo in application_import_names, foo.bar.baz will get picked up under IMPORT_APP_PACKAGE without reference to what foo.bar actually is.

I haven't updated the changelog or the other docs from https://github.com/PyCQA/flake8-import-order/commit/79540957450b20e7a8a382f6827f0f0a4c2c64cc. Want to hear if this is reasonable first.

pgjones commented 6 years ago

I've been unsure about this approach (not a namespace special case), but I can't see any obvious downsides so I'll merge this and follow up with a commit making some cosmetic changes.

taion commented 6 years ago

Thanks for merging this and cleaning it up!

I agree with you that my use case is a bit weird. I think ultimately it is a bit neater to not try to resolve imports when just trying to validate ordering, though.

Thanks again.