google / google/yapf

Implementing precedence over `--style` to `.style.yapf` or `setup.cfg`

Open
#1,006 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

Hello!

Imagine a text editor plugin that runs YAPF with a proprietary style config format (like Sublime Text's PyYapf, which has a `PyYapf.sublime-settings` with a `"config"` parameter for styles), which ultimately sets the `--style` argument for `yapf`. Suppose you want the following behavior:
* Apply settings from the text editor's style config to all Python files
* If a `.style.yapf` or `setup.cfg` file exists nearby, use that instead.

AFAIK, this is not easy to do with YAPF. The text editor will check its settings for `"config"` options, and pass them to `--style`, but how should it check whether a `.style.yapf` file exists and should take precedence? Should the plugin re-implement searching for `.style.yapf`, even though `yapf` already does that?

I propose two possible solutions:
1. A command line flag `--precedence` with the options
* `cli`, the default, which gives precedence to the `--style` flag
* `file`, which gives precedence to `.style.yapf` or `setup.cfg` if they exist ajnd are found, and if they do, ignores `--style` (possibly only ignoring parameters that are defined in both)
2. A command line flag `--found-style-file`, which, when used, does a `yapf` dry run and simply outputs `True` or `False`, depending on whether a `.style.yapf` or `setup.cfg` file is found. Then a plugin could call this function to check whether it should set its own `--style` parameters or not.

Several other open issues relate to style precedence:
* [Respect project `editorconfig` settings #826](https://github.com/google/yapf/issues/826)
* [error: looks for `toml/pyproject.toml` despite explicit `--style` #1000](https://github.com/google/yapf/issues/1000)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.