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 Anything goes Discord bot written in python and uses the wrapper Discord.py

GerardTheWizard A Anything goes Discord bot written in python and uses the wrapper Discord.py What can he do? Allow users to level up through typing,

1 May 05, 2022
Purpose To make a cloudflare challenge pass successfully, Can be use cf_clearance bypassed by cloudflare

Purpose To make a cloudflare challenge pass successfully, Can be use cf_clearance bypassed by cloudflare, However, with the cf_clearance, make sure you use the same IP and UA as when you got it.

vvanglro 129 Jan 09, 2023
troposphere - Python library to create AWS CloudFormation descriptions

troposphere - Python library to create AWS CloudFormation descriptions

4.8k Jan 06, 2023
Some 3Commas helper bots, AltRank, GalaxyScore, Watchlist, Auto-Compound

3Commas Cyber Bot Helpers A collection of 3Commas bot helpers I wrote. (collection will grow over time) Disclaimer THE SOFTWARE IS PROVIDED "AS IS", W

Ron Klinkien 176 Jan 02, 2023
Best Buy purchase bot

B3 Best-Buy-Bot. Written in Python NOTICE: Don't be a disgrace to society. Don't use this for any mass buying/reselling purposes. About B3 is a bot th

Dogey11 8 Aug 15, 2022
A Simple Telegram Bot To Download And Upload Files

AquaDLBot ➠ I Can Download And Upload files To Telegram DEMO Copyright (C) 2020-2026 by [ema

Asia Argento 8 Feb 15, 2022
just another discord bot

boredbot just another discord bot made to learn python this bots main function is to cache teams meeting links and send them right before the classes

macky 3 Sep 03, 2021
A simple versatile telgeram bot written in Python using pyTelegramBotAPI library.

A simple versatile telgeram bot written in Python using pyTelegramBotAPI library.

Benyamin Zojaji 15 Jun 17, 2022
Python Paxful API wrapper.

PyPaxful Python Paxful API wrapper. Description Just a Paxful exchange API implementation in python. Final objective is to have just one python packag

1 Dec 19, 2021
Deploy your apps on any Cloud provider in just a few seconds

The simplest way to deploy your apps in the Cloud Deploy your apps on any Cloud providers in just a few seconds ⚡ Qovery Engine is an open-source abst

Qovery 1.9k Dec 26, 2022
Telegram music & video bot direct play music

⚡ NOINOI MUSIC PLAYER 🎵 SUPERFAST MUSIC BOT WHO CAN DIRECT PLAY SONG ON TELEGRAM VOICE CHAT ALSO CAN PLAY VIDEO ON VOICE CHATS ✨ Heroku Deploy YOU CA

noinoi-X 1 Dec 28, 2021
LavaAPI - A simple library for accepting payments and using the LAVA Wallet

This library was created to simplify the LAVA api provided on the official websi

Vlad Baccara 8 Dec 18, 2022
A Phyton script working for stream twits from twitter by tweepy to mongoDB

twitter-to-mongo A python script that uses the Tweepy library to pull Tweets with specific keywords from Twitter's Streaming API, and then stores the

3 Feb 03, 2022
基于nonebot2开发的群管机器人qbot,支持上传并运行python代码以及一些基础管理功能

nonebot2-Eleina 基于nonebot2开发的群管机器人qbot,支持上传并运行python代码以及一些基础管理功能 Readme 环境:python3.7.3+,go-cqhttp 安装及配置:参见(https://v2.nonebot.dev/guide/installation.h

1 Dec 06, 2022
Dodo - A graphical, hackable email client based on notmuch

Dodo Dodo is a graphical email client written in Python/PyQt5, based on the comm

Aleks Kissinger 44 Nov 12, 2022
Python Client Library to interface with the Phoenix Realtime Server

supabase-realtime-client Python Client Library to interface with the Phoenix Realtime Server This is a fork of the supabase community realtime client

Anand 2 May 24, 2022
An Python SDK for QQ based on mirai-api-http v2.

Argon 一个基于 graia-broadcast 和 mirai-api-http v2 的 Python SDK。 本项目适用于 mirai-api-http 2.0 以上版本。 目前仍处于开发阶段,内部接口可能会有较大的变化。 The Stasis / 停滞 为维持 GraiaProject

BlueGlassBlock 1 Oct 29, 2021
A fast, easy to set up telegram userbot running Python 3 which uses fork of the Telethon Library.

forked from friendly-telegram/friendly-telegram Friendly Telegram Userbot A fast, easy to set up telegram userbot running Python 3 which uses fork of

GeekTG 75 Jan 04, 2023
Bringing Ethereum Virtual Machine to StarkNet at warp speed!

Warp Warp brings EVM compatible languages to StarkNet, making it possible to transpile Ethereum smart contracts to Cairo, and use them on StarkNet. Ta

Nethermind 700 Dec 26, 2022
This is a crypto trading bot that scans the Binance Annoucements page for new coins, and places trades on Gateio

gateio-trading-bot-binance-announcements This Gateio x Binance cryptocurrency trading bot scans the Binance Announcements page and picks up on new coi

Andrei 1.2k Jan 01, 2023