fix: use updated pep723 syntax

This commit is contained in:
Daylin Morgan 2023-12-18 12:13:49 -06:00
parent 3bfdf5c095
commit 0085940f58
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
2 changed files with 6 additions and 30 deletions

View file

@ -1,6 +1,5 @@
#!/usr/bin/env -S viv run -s #!/usr/bin/env -S viv run -s
# /// pyproject # /// script
# [run]
# requires-python = ">=3.11" # requires-python = ">=3.11"
# dependencies = [ # dependencies = [
# "requests<3", # "requests<3",

View file

@ -2012,8 +2012,8 @@ METADATA_BLOCK = (
) )
def read_metadata_block(script: str) -> dict: def _read_metadata_block(script: str) -> dict:
name = "pyproject" name = "script"
matches = list( matches = list(
filter(lambda m: m.group("type") == name, re.finditer(METADATA_BLOCK, script)) filter(lambda m: m.group("type") == name, re.finditer(METADATA_BLOCK, script))
) )
@ -2027,29 +2027,6 @@ def read_metadata_block(script: str) -> dict:
return {} 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: def _parse_date(txt: str) -> datetime:
"""attempt to parse datetime string """attempt to parse datetime string
@ -2555,9 +2532,9 @@ class Viv:
script_text = fetch_script(script) script_text = fetch_script(script)
viv_used = uses_viv(script_text) viv_used = uses_viv(script_text)
deps = ( deps = _read_metadata_block(script_text).get("dependencies", [])
read_metadata_block(script_text).get("run", {}).get("dependencies", [])
) # TODO: incorporate python version checking...
if viv_used and deps: if viv_used and deps:
error( error(