From 0085940f583abafae6bd218269d8767d913a6ef2 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 18 Dec 2023 12:13:49 -0600 Subject: [PATCH] fix: use updated pep723 syntax --- examples/pep723.py | 3 +-- src/viv/viv.py | 33 +++++---------------------------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/examples/pep723.py b/examples/pep723.py index 4eb67f4..5f23c6c 100755 --- a/examples/pep723.py +++ b/examples/pep723.py @@ -1,6 +1,5 @@ #!/usr/bin/env -S viv run -s -# /// pyproject -# [run] +# /// script # requires-python = ">=3.11" # dependencies = [ # "requests<3", diff --git a/src/viv/viv.py b/src/viv/viv.py index a5af503..f4b2679 100755 --- a/src/viv/viv.py +++ b/src/viv/viv.py @@ -2012,8 +2012,8 @@ METADATA_BLOCK = ( ) -def read_metadata_block(script: str) -> dict: - name = "pyproject" +def _read_metadata_block(script: str) -> dict: + name = "script" matches = list( filter(lambda m: m.group("type") == name, re.finditer(METADATA_BLOCK, script)) ) @@ -2027,29 +2027,6 @@ def read_metadata_block(script: str) -> dict: return {} -# DEPENDENCY_BLOCK_MARKER = r"(?i)^#\s+script\s+dependencies:\s*$" -# -# def read_dependency_block(txt: str) -> Generator[str, None, None]: -# lines = iter(txt.splitlines()) -# for line in lines: -# if re.match(DEPENDENCY_BLOCK_MARKER, line): -# for line in lines: -# if not line.startswith("#"): -# break -# # Remove comments. An inline comment is introduced by -# # a hash, which must be preceded and followed by a -# # space. The initial hash will be skipped as it has -# # no space before it. -# line = line.split(" # ", maxsplit=1)[0] -# line = line[1:].strip() -# if not line: -# continue -# # let pip handle the requirement errors -# yield line -# break -# - - def _parse_date(txt: str) -> datetime: """attempt to parse datetime string @@ -2555,9 +2532,9 @@ class Viv: script_text = fetch_script(script) viv_used = uses_viv(script_text) - deps = ( - read_metadata_block(script_text).get("run", {}).get("dependencies", []) - ) + deps = _read_metadata_block(script_text).get("dependencies", []) + + # TODO: incorporate python version checking... if viv_used and deps: error(