Skip to main content

Change quote style in Python files

Project description

String Fixer

Simple tool to replace "double quotes" with 'single quotes' in Python files.

There are many tools out there to lint and format Python code. The most popular formatter, Black, prefers double quotes to single quotes. Ruff is a bit more flexible, but doesn't format docstrings with single quotes (it lets you skip formatting them to preserve your own quotation style).

Neither project seems likely to add the option for entirely single-quoted code, so this tool can work as a post-processor to fix that.

Usage

CLI

# run against single file
python -m string_fixer --target my_file.py
# run against directory
python -m string_fixer --target lib/src/
# run against working dir
python -m string_fixer

IDE Plugins

This project has an accompanying VSCode extension.

Configuration

Configuration is done via the pyproject.toml file and the default settings are as follows:

[tool.string-fixer]
# file or folder to format
target = "./"
# set to true to print planned changes but not modify any files (overrides `output` config)
dry_run = false
# write a copy of the files to this directory, rather than modifying them inplace
output = "./"
# list of glob patterns for files to ignore. this value is autopopulated from `.gitignore` files as well
# as a few default values. anything you put in this list will be added to this set, rather than replacing
# it. Use the `include` option to override
ignore = [
    # these are the defaults
    "./**/.*",
    "./**/site-packages",
    "./**/node_modules",
    "./**/build",
    "./**/dist",
    "./**/__pycache__",
    "./**/venv"
]
# list of glob patterns for files to include. This setting overrides `ignore`
include = []
# extend and override options in another pyproject.toml file
extends = ""
# python version to target for compatibility (defaults to current python version)
# this must be a string because `float("3.10") == 3.1`
target_version = "3.12"
# try to produce strings with the least number of escapes, even if that means deviating from the quote style
prefer_least_escapes = true
# preferred quote style. Allowed options are 'single' or "double"
quote_style = "single"

All file paths are resolved relative to the pyproject.toml's location.

See Also

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

string_fixer-0.4.1.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

string_fixer-0.4.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file string_fixer-0.4.1.tar.gz.

File metadata

  • Download URL: string_fixer-0.4.1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for string_fixer-0.4.1.tar.gz
Algorithm Hash digest
SHA256 921318d949e28d549142f5ba9063202ea8722a8c7e0671bbbd991928267cbbcc
MD5 37f7caef20f9ef0f3763a4311b64dd1e
BLAKE2b-256 54b3bee3bc09f49b4cbf55e265c1b7566a022647f68c78fb90c99ce07087c2fc

See more details on using hashes here.

File details

Details for the file string_fixer-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: string_fixer-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for string_fixer-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c55eefb4066c676b4164e14f42f260e30108fd4a78af774a4ee44dd4d082466
MD5 ce3bb5d2ed3102c5176dfc0c82dc0798
BLAKE2b-256 b2eccbe85cbf71f4c3ae1b8926c7637273b0c6155a7820919bcc3a5510d6ccec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page