PyCharm 2016.3 Help

Command Line Formatter

On this page:

Introduction

Command-line source code formatter is a special functionality within PyCharm that allows to format arbitrary files outside of a project. So doing, the formatter makes use of XML files with the exported code style settings (Settings/Preferences | Editor | Code Style - Manage - Export Code Style XML File) and a file specification that defines a file or a group of files to be formatted.

For the files to be formatted there should be corresponding plugins which support the required file types.

Formatter launcher script

The script is format.bat/format.sh (Windows/Linux,Mac) in <PyCharm_HOME>/bin directory, where <PyCharm_HOME> is PyCharm's root installation directory. The script launches PyCharm, which formats the specified files and quits. If launched without any parameters or with -h parameter, the script outputs a list of its options.

Usage

format [-h] [-r|-R] [-s|-settings settingsPath] [-m|-mask masks] [path1 [path2]...]

Parameters

ParameterDescription
-hShows a help message and quits.
-r|-RScans directories specified in path1,path2.. recursively.
-s|-settings settingsPathsettingsPath is a path to the file with the exported code style settings.

-m|-mask masksA comma-separated list of file masks, which define the files to be processed. The wildcard characters * (any string), ? (any single character) are supported.
pathNA path to a file or a directory to be processed.

Example

1. Format all the files in C:\Data\src directory, including all subdirectories, using the default code style settings:

format -r C:\Data\src

2. Non-recursively format all .java and .html files in C:\Data\src directory, using code style settings from C:\Data\settings.xml:

format -s C:\Data\settings.xml -m * .java,*.html C:\Data\src

See Also

Last modified: 23 November 2016