=============== LIBRARY RULES =============== From library maintainers: - Install with pip install quotes-convert and import from quotes_convert: single_quotes, double_quotes, single_quotes_stream, double_quotes_stream. - The CLI needs pip install "quotes-convert[cli]"; use -s or -d to choose the target quote style and -i to edit files in place. ### Quick start examples for quotes-convert Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Shows basic usage: converting quotes to single or double, using short flags, and checking the version. ```bash # Convert to single quotes echo 'x = "hello"' | quotes-convert --single # Convert to double quotes echo "x = 'hello'" | quotes-convert --double # Use short flags quotes-convert -s file.py quotes-convert -d file.py # Check version quotes-convert --version ``` -------------------------------- ### Install CLI extras with pip install quotes-convert[cli] Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Installs the package with the CLI extra, enabling the quotes-convert command-line tool. ```bash pip install quotes-convert[cli] ``` -------------------------------- ### Install and verify CLI command Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md If the quotes-convert command is not found, install the CLI extras, verify installation, check PATH, or run via python -m. ```bash # Ensure CLI extras are installed pip install quotes-convert[cli] # Verify installation pip show quotes-convert # Check if it's in PATH which quotes-convert # Alternative: run with python -m python -m quotes_convert.cli --help ``` -------------------------------- ### Reinstall CLI extras on import error Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md If you get 'CLI dependencies not installed', reinstall with CLI extras using --force-reinstall. ```bash # Reinstall with CLI extras pip install --force-reinstall quotes-convert[cli] ``` -------------------------------- ### Install quotes-convert with pip Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Install the quotes-convert package using pip. ```bash pip install quotes-convert ``` -------------------------------- ### Shell aliases for quotes-convert Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Defines aliases for common quotes-convert commands and shows usage examples including piping input. ```bash alias sq='quotes-convert --single' alias dq='quotes-convert --double' alias sqi='quotes-convert --single --in-place' alias dqi='quotes-convert --double --in-place' ``` ```bash sq file.py # preview sqi file.py # in-place echo 'x="y"' | sq # pipe ``` -------------------------------- ### Command syntax for quotes-convert Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Shows the general command syntax: quotes-convert [OPTIONS] [FILES]... ```bash quotes-convert [OPTIONS] [FILES]... ``` -------------------------------- ### Error: File not found Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Shows the error message when a specified file does not exist. ```bash $ quotes-convert -s nonexistent.txt Error: Invalid value for '[FILES]...': Path 'nonexistent.txt' does not exist. ``` -------------------------------- ### Check version and test simple input Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md For unexpected results, check the version and test with simple input to isolate issues. ```bash # Check version quotes-convert --version # Test with simple input echo 'test = "value"' | quotes-convert -s ``` -------------------------------- ### Standard input/output pipes with quotes-convert Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Processes text from stdin and outputs to stdout. The first example shows converting an echo string to single quotes, with the output shown in a comment. The second reads from a file via cat, and the third chains with grep. ```bash # From echo echo 'name = "Alice"' | quotes-convert -s # Output: name = 'Alice' # From file via cat cat script.py | quotes-convert -s # Chain with other commands cat data.txt | quotes-convert -s | grep "pattern" ``` -------------------------------- ### Error: Non-UTF-8 file Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Shows the error message when the file is not UTF-8 encoded. ```bash $ quotes-convert -s binary.dat Error: Cannot decode file (not UTF-8): binary.dat ``` -------------------------------- ### File to standard output with quotes-convert Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Displays converted content to stdout without modifying files, useful for previewing changes. ```bash # Display converted content quotes-convert -s myfile.py # Check before applying quotes-convert -s config.py | less ``` -------------------------------- ### Error: Permission denied Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Shows the error message when the file cannot be accessed due to permissions. ```bash $ quotes-convert -s -i /root/protected.py Error: Permission denied: /root/protected.py ``` -------------------------------- ### Batch convert Python files with find Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Shows two ways to batch convert all Python files in a directory tree using find, including a version with a progress indicator. ```bash # Convert all Python files in a directory tree find . -name "*.py" -type f -exec quotes-convert -s -i {} \; # With progress indicator find . -name "*.py" -type f | while read f; do echo "Processing: $f" quotes-convert -s -i "$f" done ``` -------------------------------- ### Output to file with quotes-convert Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Saves converted content to a new file using the -o option, either from stdin or from a file. ```bash # From stdin echo 'x = "test"' | quotes-convert -s -o output.py # From file quotes-convert -s input.py -o output.py ``` -------------------------------- ### CLI quick examples for quotes-convert Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Shows common CLI usage: converting to single quotes (with file or stdin), converting to double quotes, editing in place with -i, and checking the version. The -s flag converts to single quotes, -d to double quotes, and -i edits the file in place. ```bash # Convert to single quotes quotes-convert -s file.py echo 'x = "hello"' | quotes-convert -s # Convert to double quotes quotes-convert -d file.py # Edit file in place quotes-convert -s -i file.py # Check version quotes-convert --version ``` -------------------------------- ### Convert Python files to single quotes with preview Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Shows how to convert Python files to single quotes using the -s flag, and how to preview changes before applying them by redirecting output to a temporary file and diffing. ```bash # Convert Python files to use single quotes quotes-convert -s -i src/*.py tests/*.py # Preview changes first quotes-convert -s main.py > /tmp/preview.py diff main.py /tmp/preview.py ``` -------------------------------- ### Convert JavaScript/TypeScript files to double quotes Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Converts TypeScript and JavaScript files to double quotes using the -d flag. ```bash # Convert to double quotes quotes-convert -d -i src/*.ts src/*.js ``` -------------------------------- ### Error: Missing quote style Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Shows the error message when neither --single nor --double is specified. ```bash $ quotes-convert file.py Error: Must specify either --single or --double ``` -------------------------------- ### Parallel processing with xargs Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Processes Python files in parallel, 4 at a time, using xargs with -P 4. ```bash # Process 4 files at a time in parallel find . -name "*.py" | xargs -P 4 -n 1 quotes-convert -s -i ``` -------------------------------- ### Convert staged or branch-changed Python files with Git Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Shows how to convert only staged Python files or files changed in the current branch vs main, using git diff and grep. ```bash # Convert only staged Python files git diff --cached --name-only | grep '\.py$' | xargs quotes-convert -s -i # Convert files changed in current branch vs main git diff --name-only main | grep '\.py$' | xargs quotes-convert -s -i ``` -------------------------------- ### Error: Conflicting options Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Shows error messages when conflicting options are provided, such as -s -d or -s -i -o. ```bash $ quotes-convert -s -d file.py Error: Cannot specify both --single and --double $ quotes-convert -s -i -o output.py file.py Error: Cannot specify both --in-place and --output ``` -------------------------------- ### Streaming mode for large files Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Use streaming mode (default) to efficiently handle large files without loading them entirely into memory. Redirect output to a file as shown. ```bash # Efficiently handles large files quotes-convert -s huge_file.txt > output.txt ``` -------------------------------- ### Parallel processing with xargs Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Process multiple files in parallel using xargs with -P 4 to run 4 processes at a time. This is useful for many files. ```bash # Process 4 files at a time find . -name "*.py" | xargs -P 4 -n 1 quotes-convert -s -i ``` -------------------------------- ### Streaming conversion with single_quotes_stream Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Processes large files or streams chunk by chunk without loading everything into memory. The generator yields converted chunks; the example prints each chunk without a newline, producing the shown output. ```python from quotes_convert import single_quotes_stream def line_generator(): yield 'line 1: "hello"\n' yield 'line 2: "world"\n' # Process the stream chunk by chunk for chunk in single_quotes_stream(line_generator()): print(chunk, end='') # Output: # line 1: 'hello' # line 2: 'world' ``` -------------------------------- ### In-place file editing with quotes-convert Source: https://github.com/ysskrishna/quotes-convert/blob/main/CLI.md Modifies files directly using the -i flag. Supports single files, multiple files, and glob patterns. Warning: in-place editing modifies files directly; use version control or backups before batch editing. ```bash # Single file quotes-convert -s -i script.py # Multiple files quotes-convert -s -i file1.py file2.py file3.py # Glob patterns (shell expansion) quotes-convert -s -i src/*.py quotes-convert -s -i *.py ``` -------------------------------- ### Basic usage of single_quotes and double_quotes Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Demonstrates converting quotes in a string to single or double quotes. ```python from quotes_convert import single_quotes, double_quotes result = single_quotes('x = "hello"; y = "world"') print(result) # x = 'hello'; y = 'world' result = double_quotes('x = "hello"; y = "world"') print(result) # x = "hello"; y = "world" ``` -------------------------------- ### CLI: quotes-convert Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Command-line interface for converting quotes in files and streams. Supports single-quote and double-quote conversion, in-place editing, and version checking. ```APIDOC ## CLI: quotes-convert ### Description Command-line interface for converting quotes in files and streams. Supports single-quote and double-quote conversion, in-place editing, and version checking. ### Installation ```bash pip install quotes-convert[cli] ``` ### Usage Examples ```bash # Convert to single quotes quotes-convert -s file.py echo 'x = "hello"' | quotes-convert -s # Convert to double quotes quotes-convert -d file.py # Edit file in place quotes-convert -s -i file.py # Check version quotes-convert --version ``` ``` -------------------------------- ### Problem with simple replace vs quotes-convert solution Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Shows why simple replace breaks nested quotes and how single_quotes handles escaping correctly. ```python # The problem with simple replace original = '"result = \'test\'"' broken = original.replace('"', "'") # Result: 'result = 'test'' -> Broken! Unmatched quotes # The solution: quotes-convert handles escaping correctly from quotes_convert import single_quotes fixed = single_quotes(original) # Result: 'result = \'test\'' -> Fixed! Properly escaped ``` -------------------------------- ### double_quotes(text: str) -> str Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Converts matching single-quotes to double-quotes in the given text. Returns the converted string. ```APIDOC ## double_quotes(text: str) -> str ### Description Converts matching single-quotes to double-quotes in the given text. ### Parameters - **text** (str) - Required - The input text to convert. ### Returns - **str** - The converted text with single-quotes replaced by double-quotes. ``` -------------------------------- ### single_quotes(text: str) -> str Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Converts matching double-quotes to single-quotes in the given text. Returns the converted string. ```APIDOC ## single_quotes(text: str) -> str ### Description Converts matching double-quotes to single-quotes in the given text. ### Parameters - **text** (str) - Required - The input text to convert. ### Returns - **str** - The converted text with double-quotes replaced by single-quotes. ``` -------------------------------- ### Handling mixed quotes with automatic escaping Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Shows how single_quotes and double_quotes automatically escape inner quotes. ```python from quotes_convert import single_quotes, double_quotes # Automatically escapes inner quotes result = single_quotes('"it\'s working"') print(result) # 'it\'s working' result = double_quotes("'say \"hi\"'") print(result) # "say \"hi\"" ``` -------------------------------- ### Processing JSON-like strings with double_quotes Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Useful for normalizing JSON strings or Python dict definitions. ```python from quotes_convert import double_quotes json_str = "{'key': 'value', 'nested': {'inner': 'data'}}" result = double_quotes(json_str) # {"key": "value", "nested": {"inner": "data"}} ``` -------------------------------- ### double_quotes_stream(stream: Iterable[str]) -> Generator[str, None, None] Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Converts matching single-quotes to double-quotes in a stream, yielding chunks. Processes large files or streams efficiently without loading the entire content into memory. ```APIDOC ## double_quotes_stream(stream: Iterable[str]) -> Generator[str, None, None] ### Description Converts matching single-quotes to double-quotes in a stream, yielding chunks. Processes large files or streams efficiently without loading the entire content into memory. ### Parameters - **stream** (Iterable[str]) - Required - An iterable of string chunks to process. ### Returns - **Generator[str, None, None]** - A generator yielding converted string chunks. ``` -------------------------------- ### single_quotes_stream(stream: Iterable[str]) -> Generator[str, None, None] Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Converts matching double-quotes to single-quotes in a stream, yielding chunks. Processes large files or streams efficiently without loading the entire content into memory. ```APIDOC ## single_quotes_stream(stream: Iterable[str]) -> Generator[str, None, None] ### Description Converts matching double-quotes to single-quotes in a stream, yielding chunks. Processes large files or streams efficiently without loading the entire content into memory. ### Parameters - **stream** (Iterable[str]) - Required - An iterable of string chunks to process. ### Returns - **Generator[str, None, None]** - A generator yielding converted string chunks. ### Example ```python from quotes_convert import single_quotes_stream def line_generator(): yield 'line 1: "hello"\n' yield 'line 2: "world"\n' # Process the stream chunk by chunk for chunk in single_quotes_stream(line_generator()): print(chunk, end='') # Output: # line 1: 'hello' # line 2: 'world' ``` ``` -------------------------------- ### Shell script processing with single_quotes Source: https://github.com/ysskrishna/quotes-convert/blob/main/README.md Converts double quotes to single quotes in a shell script string. ```python from quotes_convert import single_quotes script = 'echo "Hello $USER"; grep "pattern" file.txt' result = single_quotes(script) # echo 'Hello $USER'; grep 'pattern' file.txt ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.