News

Community Dev Gives VS Code Python Some YAPF

The latest update to Python in Visual Studio Code includes a new extension for Python formatting that was contributed by a member of the open source community.

The tool, titled simply yapf, is currently in preview, published by "EeyoreLee" to provide functionality that originated with Google's YAPF initiative, commonly understood to stand for "yet another Python formatter," though that description isn't mentioned in Google's YAPF GitHub repo.

The repo does say that YAPF (Goole uses uppercase, Microsoft/EeyoreLee use lowercase) is based on Daniel Jasper's clang-format and provides an algorithm to take code and calculate the best formatting that conforms to the configured style in order to lessen the drudgery of maintaining the code. "The ultimate goal is that the code YAPF produces is as good as the code that a programmer would write if they were following the style guide," Google's repo says.

Microsoft, meanwhile, this month said, "This extension provides yapf formatting support for Python files and Notebook cells" in announcing the September 2023 update to Python in VS Code. "Yapf support built into the Python extension will be deprecated in favor of the extension support. Subsequently, the corresponding setting python.formatting.yapf will be removed from the Python extension."

[Click on image for larger view.] yapf (source: VS Code Marketplace).

The extension, which was last updated today (Sept. 25), is nearing 3,000 installs at the time of this writing, receiving a perfect 5.0 rating from one developer who reviewed it.

Then removal of the bits from Microsoft's main Python extension is part of the team's effort started last year to break up its big extension into separate tools. "Our team is working towards breaking the tools support we offer in the Python extension into separate extensions, with the intent of improving performance, stability and no longer requiring the tools to be installed in a Python environment -- as they can be shipped alongside an extension," Microsoft said last year.

The new update also features an experiment in which the Python extension uses environment variables to activate terminals implicitly on terminal launch to provide a faster experience, especially for conda users.

"This month, we are beginning the rollout of terminal activation using environment variables that activate the selected environment in the terminal without requiring any activation commands," the announcement post said. As an experiment, it will be rolled out as the default for 25 percent of pre-release users via a flag that devs can use to opt in or out of the test.

The team also updated the Python: Create Environment command to let devs choose to either recreate or use the existing environment when working on a project working within a workspace that already contains a .venv folder.

The team is responsible for the Python extension (98 million installs) and the Jupyter extension (70.5 million installs) in the VS Code Marketplace. Along with the company's Pylance extension, those tools are the top three most popular offerings in the marketplace.

Other changes and enhancements as listed in the post include:

  • Unresolved import errors now indicate in which environment Pylance is looking for packages (pylance-release#4368)
  • There's a new experimental setting called python.analysis.enableSyncServer that enables multi-file IntelliSense support in vscode.dev. Support for github.dev and virtual workspaces is coming soon.
  • Pylance no longer crashes on Jupyter Notebook cell deletion (@pylance-release#4685)
  • There is a new dedicated topic on Python formatting in our docs where you'll learn how to set a default formatter such as autopep8 or Black formatter and customize it through various settings.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube