From da77259862b36b9d75d40ee2098ee1135fca3bc7 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Wed, 27 Sep 2023 12:42:32 -0500 Subject: [PATCH] fix: accept args with -s to make shebangs work better --- examples/pep722.py | 8 ++------ src/viv/viv.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/pep722.py b/examples/pep722.py index 2b28e70..f89fcd5 100755 --- a/examples/pep722.py +++ b/examples/pep722.py @@ -4,14 +4,10 @@ # Script Dependencies: # requests # rich # Needed for the output -# -# # Not needed - just to show that fragments in URLs do not -# # get treated as comments -# pip @ https://github.com/pypa/pip/archive/1.3.1.zip#sha1=2e15a2d4e7e9f394a9c7a6c905c6a239402a6442 import requests -from rich.pretty import pprint +from rich import print resp = requests.get("https://peps.python.org/api/peps.json") data = resp.json() -pprint([(k, v["title"]) for k, v in data.items()][:10]) +print([(k, v["title"]) for k, v in data.items()][:10]) diff --git a/src/viv/viv.py b/src/viv/viv.py index f69e3fe..d2932fe 100755 --- a/src/viv/viv.py +++ b/src/viv/viv.py @@ -52,7 +52,7 @@ from typing import ( Union, ) -__version__ = "2023.1002" +__version__ = "2023.1002-dev" class Spinner: @@ -1792,7 +1792,9 @@ class Viv: examples: viv r pycowsay -- "viv isn't venv\!" viv r rich -b python -- -m rich - viv r -s + viv r -s + + note: any args after `-s ` will be passed on """ spec = combined_spec(reqs, requirements) @@ -2127,6 +2129,10 @@ class Cli: i = sys.argv.index("--") args = self.parser.parse_args(sys.argv[1:i]) args.rest = sys.argv[i + 1 :] + elif flag := list({"-s", "--script"} & set(sys.argv)): + i = sys.argv.index(flag[0]) + args = self.parser.parse_args(sys.argv[1 : i + 2]) + args.rest = sys.argv[i + 2 :] else: args = self.parser.parse_args() if args.func.__name__ in ("cmd_run", "cmd_exe"):