A tool that ensures consistent string quotes in your Python code.

Overview

pyquotes Tests

Single quotes are superior. And if you disagree, there's an option for this as well.

In any case, quotes should be consistent throughout the codebase, and not rely on tools like black that reformat everything. Of course using those tools is perfectly fine if you want this behavior, but sometimes you just want to avoid discussing the quote style during PR reviews).

Installation

Install pyquotes using pip:

$ pip install pyquotes

Usage

$ pyquotes --help
Usage: pyquotes [OPTIONS] FILES...

  A tool that ensures consistent string quotes in your Python code.

  When passing a directory, all *.py files inside will be processed
  recursively.

  If any files needed changes, it exits with a non-zero status code.

Options:
  -V, --version                 Show the version and exit.
  -h, --help                    Show this message and exit.
  -D, --double-quotes           Prefer double quotes.
  -q, --quiet                   Do not output which files have been
                                reformatted.

  -v, --verbose                 Be more verbose and show all files being
                                processed.

  -d, --diff                    Only show diffs without updating files.
  -c, --check-only, --check     Only check files without updating them.
  --exclude PATTERN             Exclude files/directories matching this
                                pattern. Can be used multiple times. Replaces
                                the built-in excludes. Does not apply to
                                explicitly-specified files.

  -X, --extend-exclude PATTERN  Exclude files/directories matching this
                                pattern. Can be used multiple times. Extends
                                the built-in excludes. Does not apply to
                                explicitly-specified files.

Use --diff or --check-only if you want to run this script in CI (usually using flake8-quotes as explained below is the better choice though).

Configuration

exclude, extend-exclude and double-quotes can be configured via the following files (looked up in this order, the first one containing settings is used):

  • .pyquotes.cfg - ConfigParser format, settings or pyquotes section
  • setup.cfg - ConfigParser format, pyquotes or tool:pyquotes section
  • pyproject.toml - TOML format, tool.pyquotes section

Parsing pyproject.toml requires toml to be installed; a warning is emitted if the file exists and no config is found elsewhere and toml is missing.

Note that exclude should not be used in most cases; unless you really need to whitelist something that's excluded by default.

setup.cfg

[pyquotes]
double-quotes = false
extend-exclude =
    htmlcov
    .vscode

The same format can be used in .pyquotes.cfg as well.

pyproject.toml

[tool.pyquotes]
double-quotes = false
extend-exclude = ['htmlcov', '.vscode']

flake8

If you use flake8, you may want to install flake8-quotes to also get warnings if the code currently has incorrect quotes. You can use the following options if you want single quotes:

[flake8]
inline-quotes = single
multiline-quotes = single
docstring-quotes = double
avoid-escape = true

Note that flake8-quotes is completely independent from this tool, so inconsistencies are possible. Please open an issue if you discover any such cases.

You might also like...
You can share your Chegg account for answers using this bot with your friends without getting your account blocked/flagged

Chegg-Answer-Bot You can share your Chegg account for answers using this bot with your friends without getting your account blocked/flagged Reuirement

Instagram Story View Bot  Unencrypted Story Views is a helpful tool that allows thousands of people to watch your posts. It is completely free, source is visible for anyone to modify Type your username, wait for the bot to Automate the Task.
A GitHub Action that automatically reports your Advent of Code progress in a table in your README

Advent README Stars This action adds and maintains a stars report in your README based on your Advent of Code progress. Example Table 2021 Results Day

A self-bot for discord, written in Python, which will send you notifications to your desktop if it detects an intruder on your discord server

A self-bot for discord, written in Python, which will send you notifications to your desktop if it detects an intruder on your discord server

A simple python script to send files into your telegram Bot form your PC, Server etc.

telegramSend A simple python script to send files into your telegram Bot form your PC, Server etc. How to Use Install requirements.txt pip3 install -r

Python Tool To Get The Date That Your Account Joined Instagram

Date-Joined-Insta Python Tool To Get The Date That Your Account Joined Instagram You Dont Need To Login Just Enter The UserName If Id Did Not Work Ins

Notion4ever - Python tool for export all your content of Notion page using official Notion API
Notion4ever - Python tool for export all your content of Notion page using official Notion API

NOTION4EVER Notion4ever is a small python tool that allows you to free your cont

A powerful bot to copy your google drive data to your team drive
A powerful bot to copy your google drive data to your team drive

⚛️ Clonebot - Heroku version ⚡ CloneBot is a telegram bot that allows you to copy folder/team drive to team drives. One of the main advantage of this

Comments
  • Resolves #3 and #5

    Resolves #3 and #5

    • #3 Added a minimum version of click
    • #5 Force UTF-8 encoding on reading/writing

    I have not bumped version, and will leave that to you pending acceptance of these changes.

    Thank you.

    opened by ghost 6
  • Encoding issue

    Encoding issue

    OS: Windows 10 21H2 Python: Python 3.10.4

    Steps:

    • pip install pyquotes

    example.py (file is saved as UTF-8 with/without a BOM)

    print('こんにちは世界')
    
    • pyquotes example.py
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 11: character maps to <undefined>
    

    If read_text() and write_text() are replaced with read_bytes() and write_bytes() equivalents, the quote processing is fixed (not tested on Linux). Although, additional new lines are erroneously added, I haven't had a chance to look into why.

    Thank you for your time, this library has saved my many hours.

    opened by ghost 8
  • Parsing error

    Parsing error

    OS: Windows 10 21H2 Python: Python 3.10.4

    Steps:

    • pip install pyquotes

    example.py

    '''
    Example File
    '''
    
    A = "This is a test string."
    B = 'This is a test string.'
    C = "This isn't a test string, or is it?"
    D = f"{A}{B}{C}"
    E = f'{A}{B}{C}'
    
    • pyquotes example.py
    • pyquotes --check example.py
    • pyquotes -D example.py
    • pyquotes -D --check example.py

    All fail with the error

      File "C:\Python310\lib\site-packages\parso\python\tree.py", line 86, in get_doc_node
        c = simple_stmt.parent.children
    AttributeError: 'NoneType' object has no attribute 'children'
    

    If a print('Hello, World!') is added to the file, it behaves as expected.

    Thank you for your time, this library has saved my many hours.

    opened by ghost 4
  • click dependency not bounded

    click dependency not bounded

    OS: Windows 10 21H2 Python: Python 3.10.4

    Steps:

    • pip install "click<7"
    • pip install pyquotes

    example.py

    print("Hello, World!")
    

    pyquotes --check example.py pyquotes -D --check example.py

    Both fail with the error

      File "C:\Python310\lib\site-packages\pyquotes\settings.py", line 96, in __init__
        super().__init__(**settings, project_root=project_root)
    TypeError: _Config.__init__() got an unexpected keyword argument 'check'
    

    This is resolved when using click>=8.

    Thank you for your time, this library has saved my many hours.

    opened by ghost 2
Releases(v1.0.0)
Owner
Adrian
Adrian
A Discord bot that automatically saves SHSH blobs for all of your iOS devices.

AutoTSS AutoTSS is a Discord bot that automatically saves SHSH blobs for all of your iOS devices. Want a CLI automatic blob saver? Check out AutoTSS-c

adam 79 Dec 13, 2022
Open API to list Viet Nam administrative divisions

Viet Nam province API Homepage: https://provinces.open-api.vn This is online tool to let my VietnamProvinces library reach more users. VietnamProvince

Nguyễn Hồng Quân 52 Dec 05, 2022
EZXT - A ccxt wrapped client for binance & ftx

EZXT Open source & beginner-friendly ccxt wrapped client for binance & ftx Want

Shaft 10 Oct 25, 2022
PyDiscord, a maintained fork of discord.py, is a python wrapper for the Discord API.

discord.py A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. The Future of discord.py Please read the gi

Omkaar 1 Jan 16, 2022
CryptoApp - Python code to pull wallet balances from a variety of different chains through nothing other than your public key.

CryptoApp - Python code to pull wallet balances from a variety of different chains through nothing other than your public key.

Zach Frank 4 Dec 13, 2022
SmsSender v3.0.0 - the script is designed to send free SMS to any number and with any text.

SmsSender v3.0.0 - скрипт предназначен для бесплатной отправки SMS на любой номер и с любым текстом. Возможны небольшие баги, в скором времени исправл

Андрей Сергеев 20 Dec 03, 2021
A simple python discord bot which give you a yogurt brand name, basing on a large database often updated.

YaourtBot A discord simple bot by Lopinosaurus Before using this code : ・Move env file to .env ・Change the channel ID on line 38 of bot.py to your #pi

The only one bunny who can dev. 0 May 09, 2022
PlexAutoSkip - Automatically skip content in Plex

PlexAutoSkip Automatically skip tagged content in Plex A background python scrip

Michael Higgins 97 Dec 21, 2022
Telegram-Voice Recoginiton Project (Python)

Telegram-Voice Recoginiton Project (Python) It is a telegram bot that analyses voice messages and convert it to text and reply back response on bot's

Krishnadev P Melevila 1 Jan 28, 2022
Monitoring plugin for MikroTik devices

check_routeros - Monitoring MikroTik devices This is a monitoring plugin for Icinga, Nagios and other compatible monitoring solutions to check MikroTi

DinoTools 6 Dec 24, 2022
Example of Telegram local API and aiogram 3.x

Telegram Local Full example of Telegram local application. Contains Telegram Bot API Local Telegram Bot API server based on aiogram Bot API Server ima

Oleg A. 9 Sep 16, 2022
A python tool to Automate Whatsapp through Whatsapp web

This python tool is used to Automate Whatsapp through Whatsapp web. We can add number of contacts whom we want to send text messages on perticular time

5 Jul 21, 2022
The most versatile torrent leecher and youtube-dl bot for telegram

TorToolkit Telegram So basically Tortoolkit is aimed to be the most versatile torrent leecher and youtube-dl bot for telegram. This bot is highly cust

αвιנтн 1 Nov 11, 2021
Git Plan - a better workflow for git

git plan A better workflow for git. Git plan inverts the git workflow so that you can write your commit message first, before you start writing code.

Rory Byrne 178 Dec 11, 2022
Popcorn-time-api - Python API for interacting with the Popcorn Time Servers

Popcorn Time API 📝 CONTRIBUTIONS Before doing any contribution read CONTRIBUTIN

Antonio 3 Oct 31, 2022
AI-El-Yazisini-Tanima - Fotoğraflardaki El Yazını Yapay Zeka İle Otomatik Tanıma Yazılımı

AI-El Yazısını Tanıma Fotoğraflardaki El Yazını Yapay Zeka İle Otomatik Tanıma Yazılımı Amaç : Birden fazla makine öğrenmesi modelini bir arada kullan

Özgür Tokay 3 Mar 02, 2022
A Telegram Bot to Play Audio in Voice Chats With Youtube and Deezer support. Supports Live streaming from youtube Supports Mega Radio Fm Streamings

Bot To Stream Musics on PyTGcalls with Channel Support. A Telegram Bot to Play Audio in Voice Chats With Supports Live streaming from youtube and Mega

Shamil Habeeb 37 Dec 15, 2022
Self-adjusting, auto-compounding multi-pair DCA crypto trading bot using Python, AWS Lambda & 3Commas API

Self-adjusting, auto-compounding multi-pair DCA crypto trading bot using Python, AWS Lambda & 3Commas API The following code describes how we can leve

Jozef Jaroščiak 21 Dec 07, 2022
Client library for accessing IQM quantum computers

IQM Client Client-side library for connecting to an IQM quantum computer. Installation IQM client is not intended to be used directly by human users.

IQM 10 Dec 21, 2022
Terraform Cloud CLI for Managing Workspace Terraform Versions

Terraform Cloud Version Manager This tiny script makes it easy to update the Terraform Version on all of the Workspaces inside Terraform Cloud. It wil

Robert Hafner 1 Jan 07, 2022