From 7729ba48700aea2fbf4ae123d805c3b12ff8a7c5 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 7 Sep 2024 03:31:45 +0530 Subject: [PATCH] Add support for Python 3.13, drop 3.7 --- setup.cfg | 6 ++++-- zx.py | 33 ++++++++++++++------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/setup.cfg b/setup.cfg index b47bc48..6173d7e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = zxpy -version = 1.6.3 +version = 1.3.0 description = Shell scripts made simple long_description = file: README.md long_description_content_type = text/markdown @@ -14,10 +14,12 @@ classifiers = Operating System :: OS Independent Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 + Programming Language :: Python :: 3.13 Programming Language :: Python :: Implementation :: CPython Typing :: Typed diff --git a/zx.py b/zx.py index cabb4ef..dd1559c 100644 --- a/zx.py +++ b/zx.py @@ -21,6 +21,7 @@ ...to the top of your file, and executing it directly like a shell script. Note that this requires you to have zxpy installed globally. """ + from __future__ import annotations import argparse @@ -29,8 +30,6 @@ import codecs import contextlib import inspect -import pipes -import re import shlex import subprocess import sys @@ -59,17 +58,17 @@ def cli() -> None: """ parser = argparse.ArgumentParser() parser.add_argument( - '-i', - '--interactive', - action='store_true', - help='Run in interactive mode', + "-i", + "--interactive", + action="store_true", + help="Run in interactive mode", ) - parser.add_argument('filename', help='Name of file to run', nargs='?') + parser.add_argument("filename", help="Name of file to run", nargs="?") # Everything passed after a `--` is arguments to be used by the script itself. - script_args = ['/bin/sh'] + script_args = ["/bin/sh"] try: - separator_index = sys.argv.index('--') + separator_index = sys.argv.index("--") script_args.extend(sys.argv[separator_index + 1 :]) # Remove everything after `--` so that argparse passes sys.argv = sys.argv[:separator_index] @@ -146,7 +145,7 @@ def create_shell_process(command: str) -> Generator[IO[bytes], None, None]: """Creates a shell process, yielding its stdout to read data from.""" # shell argument support, i.e. $0, $1 etc. - dollar_indices = [index for index, char in enumerate(command) if char == '$'] + dollar_indices = [index for index, char in enumerate(command) if char == "$"] for dollar_index in reversed(dollar_indices): if ( dollar_index >= 0 @@ -194,7 +193,7 @@ def run_shell_print(command: str) -> None: """Version of `run_shell` that prints out the response instead of returning a string.""" with create_shell_process(command) as stdout: decoder = UTF8Decoder() - with open(stdout.fileno(), 'rb', closefd=False) as buff: + with open(stdout.fileno(), "rb", closefd=False) as buff: for text in iter(buff.read1, b""): print(decoder.decode(text), end="") @@ -261,12 +260,8 @@ def quote_fstring_args(fstring: ast.JoinedStr) -> None: if ( isinstance(node.format_spec, ast.JoinedStr) and len(node.format_spec.values) == 1 - and ( - isinstance(node.format_spec.values[0], ast.Str) - and node.format_spec.values[0].s == "raw" - or isinstance(node.format_spec.values[0], ast.Constant) - and node.format_spec.values[0].value == "raw" - ) + and isinstance(node.format_spec.values[0], ast.Constant) + and node.format_spec.values[0].value == "raw" ): node.format_spec = None continue @@ -290,7 +285,7 @@ def modify_expr( if ( isinstance(expr, ast.UnaryOp) and isinstance(expr.op, ast.Invert) - and isinstance(expr.operand, (ast.Str, ast.JoinedStr)) + and isinstance(expr.operand, (ast.Constant, ast.JoinedStr)) ): if isinstance(expr.operand, ast.JoinedStr): quote_fstring_args(expr.operand) @@ -362,7 +357,7 @@ def runsource( # First, check if it could be incomplete input, return True if it is. # This will allow it to keep taking input with contextlib.suppress(SyntaxError, OverflowError): - if code.compile_command(source) == None: + if code.compile_command(source) is None: return True try: