hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.56k stars 290 forks source link

`autopep8` over Language Server Protocol and VS Code extension #624

Closed karthiknadig closed 1 year ago

karthiknadig commented 2 years ago

The Python team for VS Code has been working on putting various tools we support behind LSP and breaking them out into their own extensions This work is now far enough along that we wanted to share the extension prototypes for your tool with you and see if you had any interest in owning the extension or the Python-based LSP server backing it yourself?

If you don't want to take on that reponsibility that's totally fine and understandable! If you want to leave the extension to us we would then publish the extension on the VS Code Marketplace ourselves. We also plan to publish the extension as open source and support the extension for as long as we felt it made sense to based on usage numbers. But due to the difficulty of migrating extension ownership, we wanted to ask early whether you wanted to own the extension from the start? If you did want to own the extension we would give you the code, help you publish to the VS Code Marketplace, and do anything else we can to help you be successful with this.

We have attached a zip file to this issue containing a prototype extension to give you an idea of what we are planning. You can download it, extract the .vsix file, and then install the VSIX to try it out python-autopep8.zip. This prototype version was built with python 3.10 and bundles autopep8 v1.6.0 (as fallback if nothing is found in your environment).

To be very clear, there's no pressure or expectations from us. We just want to make sure you as a project had an opportunity to own this extension instead of us from the get-go before the extension gained traction.

karthiknadig commented 2 years ago

For testing this you can follow these steps, after installing. Suppose you have code like this:

import unittest
class TestSum2(unittest.TestCase):
    def test_sum2(self):
        self.assertEqual(sum([1, 2, 3]), 6, "Should be 6")

    def test_sum2_tuple(self):
        self.assertEqual(sum((1, 2, 2)), 6, "Should be 6")
if __name__ == "__main__":
    unittest.main()

Right click in the document and select "Format Document With ...": image

You should see two formatters, Select "autopep8": image

That is, it!

If you want this to happen automatically, set Autopep8 as the default formatter, and enable format on save. Then on save the content will be formatted.

hhatto commented 2 years ago

Thanks for opening the issue.

In this repository, we want to provide autopep8 itself as a tool, so we don't plan to own LSP and VS Code extension. Feel free to implement it 👍

karthiknadig commented 1 year ago

This is now available to download https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8

agherasim commented 11 months ago

@karthiknadig, having reproduced this issue in one particular file, I was able to eliminate the problem by renaming the file, main_test.py -> main2_test.py. Renaming the file back causes the issue to reappear. It looks like some sort of cache? could be involved. Any ideas?

karthiknadig commented 11 months ago

Are you using the Autopep8 extension if so, could you open a bug there with logs from Output > autopep8