YAPF Beautifier
About
YAPF beautifier for Unibeautify
Package | Docs | Latest |
---|---|---|
@unibeautify/beautifier-yapf | v0.3.0 | |
unibeautify | v0.17.1 |
Prerequisites
Please install the following prerequisites.
YAPF executable
YAPF executable should not be confused with YAPF beautifier with the same name. Executables are non-Node.js tools for code formatting while beautifiers are Node.js packages which wrap an executable to be used by Unibeautify.
YAPF executable is a third-party program you must install manually and is required for beautification.
Install
Install with npm
:
npm install --save-dev unibeautify @unibeautify/beautifier-yapf
Or with yarn
:
yarn add --dev unibeautify @unibeautify/beautifier-yapf
Usage
Add YAPF
to beautifiers
language option.
A .unibeautifyrc.json
file would look like the following:
{
"Python": {
"beautifiers": [
"YAPF"
]
}
}
Advanced
The following beautifier option(s) are supported:
prefer_beautifier_config
See beautifier options docs for more information.
Example advanced configuration:
{
"Python": {
"beautifiers": [
"YAPF"
],
"YAPF": {
"prefer_beautifier_config": true,
"YAPF": {
"path": "/absolute/path/to/yapf"
}
}
}
}
Options
Option | Python |
---|---|
Indent Size | ✅ |
Indent Style | ✅ |
FAQ
How to use YAPF in Atom, VSCode, and other editors?
See the editor integration documentation for installation instructions for your editor of choice.
How to use YAPF configuration file?
You can override Unibeautify configuration and use YAPF's own configuration file instead with prefer_beautifier_config
beautifier option.
{
"LANGUAGE_NAME": {
"beautifiers": [
"YAPF"
],
"YAPF": {
"prefer_beautifier_config": "path/to/YAPF/config/file"
}
}
}
See beautifier options docs for more information.
How to enable YAPF to format on save?
See the editor integration documentation for format on save instructions for your editor of choice.
How to run YAPF on all files?
You can run YAPF on all of your files for every commit with Unibeautify CI.
Is there a YAPF sandbox or playground?
You can quickly try YAPF online with Unibeautify Playground.
Troubleshooting
Below are instructions for each of the supported Operating Systems.
Windows
Open the Command Prompt.
Show me how to open the Command Prompt.
Find the path to YAPF by running the command:
where yapf
Which will return an absolute path like one of the following:
C:\absolute\path\to\yapf
C:\absolute\path\to\yapf.exe
C:\absolute\path\to\yapf.bat
If where
fails to return an executable path then you need to fix your PATH
Environment Variable.
Show me how to change my
PATH
environment variable.
If you know the executable path go to the Configure section and replace /absolute/path/to/yapf
with your specific executable path value.
macOS
Open the Terminal application.
Show me how to open the Terminal.
Find the path to YAPF by running the command:
which yapf
Which will return an absolute path like one of the following:
/absolute/path/to/yapf
/absolute/path/to/yapf.sh
/absolute/path/to/yapf.bash
If which
fails to return an executable path then you need to fix your PATH
Environment Variable:
Show me how to change my
PATH
environment variable.
If you know the executable path go to the Configure section and replace /absolute/path/to/yapf
with your specific executable path value.
Linux
Open the Terminal application.
Show me how to open the Terminal.
Find the path to YAPF by running the command:
which yapf
Which will return an absolute path like one of the following:
/absolute/path/to/yapf
/absolute/path/to/yapf.sh
/absolute/path/to/yapf.bash
If which
fails to return an executable path then you need to fix your PATH
Environment Variable.
Show me how to change my
PATH
environment variable.
If you know the executable path go to the Configure section replace /absolute/path/to/yapf
with your specific executable path value.