Skip to content

Commit

Permalink
Add support for Python 3.13, drop 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed Sep 6, 2024
1 parent 2baf656 commit 7729ba4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
33 changes: 14 additions & 19 deletions zx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,8 +30,6 @@
import codecs
import contextlib
import inspect
import pipes
import re
import shlex
import subprocess
import sys
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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="")

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7729ba4

Please sign in to comment.