How can I run autopep8 to reformat a file from within komdo? From my searches of the forum, it seems to require knowledge of the komodo API to write a function to do this in javascript?
How can I do the equivalent thing easily in komodo? I think the steps needed are to save the file, run autopep8 to modify the file, and then reload the file, right?
Executable to use: /usr/bin/autopep8
Command line arguments: --in-place --aggressive --aggressive
But when I run it with Code->Format document using->autopep8 or set Code->Format->On File Save using->autopep8 and then save the file, it’s not being reformatted.
I must be missing something. I tried Python and Python3 in the Formatter Configuration field- my test script is python 3 and is not modified when I run Code->Format document using->autopep8. It’s not changed at all. There are no error windows popping up or anything.
Hi, would you please post the entire contents of your error log? Despite the fact that there are “Exception start/end” markers, there’s usually some extra helpful information before or after (I forget which). As it stands, I know where the failure occurred, but I don’t know why. Thanks.
I will need to set up a test environment before I can post the entire error log. I see that there were some errors logged because the preferences window was still open after applying changes - could that have an effect on script execution?
I realize that using explicit paths rather than the environment variables used in the examples is less than ideal but did so as a means of troubleshooting. Below is a screenshot of the definition I created - does it look like it should work? I also tried it using - as the last input parameter instead of the --in-place option because it says the text will be passed using stdin.
How would YOU create a formatter to take a python file being edited in komodo and replace it with the same file after it has been reformatted by an external program - in this case: ‘autopep8 --aggressive --aggressive’? The autopep8 website has a nice example file for testing at https://github.com/hhatto/autopep8
autopep8 can be run either with a file argument or with - to read from stdin in the usual unix fashion. When run with a file argument, --in-place can be used to modify the file in place - otherwise, it writes the output to stdout.
Komodo passes the code to be formatted to the STDIN, so you should tell autopep8 to read the code from it. And Komodo waits for the formatted output at STDOUT, so my guess is you should omit --in-place.
OK - that seems to work! Knowing that komodo uses the specified program as a filter is the key.
Changing the autopep8 Command-line Arguments to “–aggressive --aggressive -” has it working! The key being the hyphen at the end telling autopep8 to read input from stdin. As autopep8 sends it’s output to stdout, Komodo then replaces the contents of the buffer with the autopep8 reformatted contents. Just what we need!
Is there any way to create a keybinding to run this formatter? I checked in the preferences->keybindings but code->format didn’t seem to be one of the options. Does the fact that I am using the emacs keybindings matter?