The Eclipse PyDev plugin includes fantastic integrated autopep8
support. It formats the code to PEP8 style automatically on save, with several knobs and options to tailor it to your needs.
But the autopep8
import formatter breaks site.addsitedir()
usage.
import site
site.addsitedir('/opt/path/lib/python')
# 'ourlib' is a package in '/opt/path/lib/python', which
# without the above addsitedir() would otherwise not import.
from ourlib import do_stuff
And after PyDev's autopep8
import formatter, it changes it to:
import site
from ourlib import do_stuff
site.addsitedir('/opt/path/lib/python')
Which breaks from ourlib import do_stuff
with ImportError: No module named ourlib
.
Question:
Is there a PyDev setting or autopep8
command-line option to keep it from moving site.addsitedir()
calls?
Oldie but still relevant as I found this one issue.
I'm using VSCode and autopep8.
You can disable formatting by adding # nopep8
to the relevant lines.
ps. Checked the docs for a link but could not find it :(
The best option I can find is to turn off import sorts in PyDev. This is not a complete solution, but it's better than completely turning off autopep8
code formatting.
Just uncheck the Sort imports on save?
option in the Eclipse/PyDev Preferences.
For Eclipse Kepler, Service Release 2, with PyDev 3.9.2, you can find it here:
Windows -> Preferences
--> PyDev -> Editor -> Save Actions
----> "Sort imports on save?" (uncheck)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With