bh / atom-python-isort

Atom.io plugin to sort Python imports
https://atom.io/packages/python-isort
MIT License
19 stars 10 forks source link

atom-python-isort runs on saved file, rather than editor content #34

Open arl-o opened 7 years ago

arl-o commented 7 years ago

The expected behavior of 'python-isort:sortImports' is that it runs on the current editor's contents, using isort to directly convert text.

eg:

new_contents = SortImports(file_contents=old_contents).output

Instead, the sortImports function runs isort on 'getFilePath', which means that isort doesn't appear to do anything if the file has not been saved immediately before running sortImports.

I think it's probably bad form to directly edit the focused .py file, rather than changing the editor's contents, because it doesn't allow for the user to view and/or revert the changes that isort makes.

I'd be happy to update this behavior, if nobody else wants to.

lexicalunit commented 7 years ago

That would be a nice feature but the package works by calling the command line tool isort on the file. The isort tool itself is implemented in python so there's no simple and straight-forward way to call it from the js/coffee source of the atom-python-isort package as you've suggested. Also, please consider https://github.com/lexicalunit/atom-isort instead, as this package seems to have become defunct.

arl-o commented 7 years ago

Thanks a lot for the redirect, and for keeping this package updated!

I went ahead and wrote a version that just runs on the editor's contents, by way of

this.provider = require('child_process').spawn(
      'python', [__dirname + '/editor-isort.py'], env: process.env
    )

(as is done in python-tools)

Would you (or other people) be interested in using it? I'd be happy+willing to integrate my solution with lexicalunit/atom-isort, if you're ok with helping me some to make my implementation less hack-y.

Thanks again!

lexicalunit commented 7 years ago

Nice! I'm definitely interested in this feature! If you make a PR against lexicalunit/atom-isort we can iterate on it through the review process until we come up with something we're both happy with. I'm gonna be out for a bit though as I'm getting sinus surgery tomorrow morning.

arl-o commented 7 years ago

Awesome! I'll try to clean up what I have, will make a PR when I have some free time, (probably this weekend.)

Hope the surgery goes well!