atom-community / ide-python

Python language support for Atom-IDE :atom: :snake:
https://atom.io/packages/ide-python
Other
237 stars 39 forks source link

How to configure autopep8? #135

Open caballerofelipe opened 6 years ago

caballerofelipe commented 6 years ago

Hi, I am trying to use autopep8 but it doesn't work as I was expecting. When doing Code Format: Format Code some parts of my code are formatted and others aren't. I tried the autopep8 command in CLI and it formatted a lot more my code which is what I was looking for. I also tried using atom-beautify and it also did a lot more formatting.

So, I would like to know: 1) Why isn't ide-python formatting as much as autopep8 on CLI or atom-beautify? 2) Is there a configuration that is preventing ide-python to do this? 3) Is there a configuration file I should change (or create) to have the formatting I would like?

I am fairly new to autopep8 and I haven't used much this package but I think there should be a little more documentation on these topics as someone new to them. I feel a little lost on what steps to take to have this package working as I'd like.

Notes: python -m pyls --help shows the desired output I'm on macOS 10.13.6 Atom version 1.29.0 When seeing a Python file in Atom, pycodestyle shows a lot of errors that aren't corrected by the autopep8 setting.

lgeiger commented 5 years ago

autopep8 should use the pycodestyle config so there is no need to add a configuration file. The language server supports both formatting ranges as well as the entire document. So make sure no part of the file is selected when formatting code in order to format the whole document. Please also make sure that Yapf is disabled and autopep8 enabled in the settings. Otherwise Yapf would be used for the formatting.

I agree our documentation is currently lacking. This is mostly due to a lack of time. Do you want to send a PR to fix this?

stefanitsky commented 5 years ago

@lgeiger Hi! Im not sure that this is the place where its better to write about it, but please, add the keyboard shortcut Code Format: Format Code - ctrl-shift-C for autopep8 in the documentation, because i couldnt understand for a long time why it doesnt work. Also, thanks @caballerofelipe, you saved my time.

MattiooFR commented 4 years ago

Hey, I'm having the same question ! I cant find how to make the format code more aggressive with python-ide on atom. Did you find how to do ?

lgeiger commented 4 years ago

autopep8 should use the pycodestyle config so if you change the pycodestyle config autopep8 will respect that.

I've personally been very happy with pyls-black for running black formatting and disabled both autopep8 and yapf.

MattiooFR commented 4 years ago

Thanks for your reply, I'll try that !

Well what should I put then in the pycodestyle config to make autopep8 behave like the command : "autopep --in-place --aggressive --aggressive "

I want this behavior but when I do right click => Format Code inside Atom editor but I've been struggling all day with no success ><

lgeiger commented 4 years ago

I don't think the language server has support for the aggressive option: https://github.com/palantir/python-language-server/blob/develop/pyls/plugins/autopep8_format.py

Feel free to send a PR, and we can start supporting it in ide-python as well

MattiooFR commented 4 years ago

Ok, black seems to work well thank for the suggestion !

Except it doesnt correct import sys, math to import sys import math

And it doesnt change deprecated fonction like "has_key()" to "in".

If you know a way to make it with black I would be super happy !

I'll do a PR to language server to implement the aggressive option in autopep8 !