_cmdline module

exception pyflyby._cmdline.AbortActions
exception pyflyby._cmdline.ConfigurationError

Exception class indicating a configuration error.

exception pyflyby._cmdline.Exit1
class pyflyby._cmdline.Modifier(modifier, filename)
_tempfile()
Return type:

Tuple[Any, Filename]

filename: Filename
property input_content: FileText
property input_content_filename: Filename
modifier: Callable[[FileText], Any]
property output_content: FileText
property output_content_filename: Filename
pyflyby._cmdline._default_on_error(filename)
Return type:

None

pyflyby._cmdline._get_pyproj_toml_config()

Return the toml contents of the current pyproject.toml.

If no pyproject.toml can be found in cwd or parent directories, None is returned.

Return type:

Optional[Dict[str, Any]]

pyflyby._cmdline._get_pyproj_toml_file()

Try to find the location of the current project pyproject.toml in cwd or parents directories.

If no pyproject.toml can be found, None is returned.

Return type:

Optional[Path]

pyflyby._cmdline._sigpipe_handler(*args)
Return type:

None

pyflyby._cmdline.action_changedexit1(m)

Exit with code 1 if there were changes.

Return type:

None

pyflyby._cmdline.action_exit1(m)
Return type:

NoReturn

pyflyby._cmdline.action_external_command(command)
Return type:

Callable[[Modifier], Any]

pyflyby._cmdline.action_ifchanged(m)
Return type:

None

pyflyby._cmdline.action_nothing(m)
Return type:

None

pyflyby._cmdline.action_print(m)
Return type:

None

pyflyby._cmdline.action_query(prompt='Proceed?')
Return type:

Callable[[Modifier], Any]

pyflyby._cmdline.action_replace(m)
Return type:

None

pyflyby._cmdline.filename_args(args, on_error=<function _default_on_error>)

Return list of filenames given command-line arguments.

Return type:

List[Filename] list of Filename

pyflyby._cmdline.hfmt(s)
Return type:

str

pyflyby._cmdline.maindoc()
Return type:

str

pyflyby._cmdline.parse_args(addopts=None, modify_action_params=False)

Do setup for a top-level script and parse arguments.

Performs common setup for pyflyby command-line tools: installs a SIGPIPE handler, builds an optparse.OptionParser, registers the standard options (--debug, --verbose, --quiet, --version), optionally adds groups of action and/or pretty-printing options, parses sys.argv, and post-processes the result.

The --uniform/--unaligned shortcuts and the default --symlinks value are applied after parsing, and (when import_format_params is set) the import-formatting options are collected into an ImportFormatParams instance attached as options.params.

Parameters:
  • addopts (callable or None) – Optional callback invoked as addopts(parser) to register additional, script-specific options on the parser before arguments are parsed.

  • import_format_params (bool) – If true, add the “Pretty-printing options” group (e.g. --align-imports, --from-spaces, --width, --black, --hanging-indent, --uniform, --unaligned) and attach the resulting ImportFormatParams as options.params.

  • modify_action_params (bool) – If true, add the “Action options” group (e.g. --actions, --print, --diff, --replace, --interactive) and the --symlinks option, which control what is done with files that would be modified.

Return type:

tuple of (optparse.Values, list of str)

Returns:

A (options, args) pair, where options holds the parsed option values and args is the list of remaining positional arguments (typically filenames).

pyflyby._cmdline.print_version_and_exit(extra=None)
Return type:

NoReturn

pyflyby._cmdline.process_actions(filenames, actions, modify_function, reraise_exceptions=(), exclude=())
Return type:

NoReturn

Return type:

None

Return type:

None

Return type:

None

Return type:

None

Return type:

None

pyflyby._cmdline.syntax(message=None, usage=None)
Return type:

NoReturn