refactor: update standalone for remote release

This commit is contained in:
Daylin Morgan 2023-05-27 15:00:21 -05:00
parent 1abe3af385
commit 94bc35147a
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -35,7 +35,7 @@ from dataclasses import dataclass
from datetime import datetime from datetime import datetime
from itertools import zip_longest from itertools import zip_longest
from pathlib import Path from pathlib import Path
from textwrap import dedent, wrap from textwrap import dedent, fill, wrap
from types import TracebackType from types import TracebackType
from typing import ( from typing import (
Any, Any,
@ -52,7 +52,7 @@ from typing import (
from urllib.error import HTTPError from urllib.error import HTTPError
from urllib.request import urlopen from urllib.request import urlopen
__version__ = "23.5a1-3-g3a85fe4-dev" __version__ = "23.5a1-dev"
@dataclass @dataclass
@ -544,14 +544,15 @@ REL_SYS_PATH_TEMPLATE = (
IMPORT_TEMPLATE = """__import__("viv").use({spec}) # noqa""" IMPORT_TEMPLATE = """__import__("viv").use({spec}) # noqa"""
STANDALONE_TEMPLATE = r""" STANDALONE_TEMPLATE = r"""
# <<<<< auto-generated by daylinmorgan/viv v{version} # <<<<< auto-generated by viv (v{version})
# see `python3 <(curl -fsSL gh.dayl.in/viv/viv.py) --help`
# fmt: off # fmt: off
{use} {func}
# fmt: on # fmt: on
# >>>>> code golfed with <3 # >>>>> code golfed with <3
""" # noqa """ # noqa
STANDALONE_TEMPLATE_USE = r"""def _viv_use(*pkgs: str, track_exe: bool = False, name: str = "") -> None: STANDALONE_TEMPLATE_FUNC = r"""def _viv_use(*pkgs: str, track_exe: bool = False, name: str = "") -> None:
i,s,m,e,spec=__import__,str,map,lambda x: True if x else False,[*pkgs] i,s,m,e,spec=__import__,str,map,lambda x: True if x else False,[*pkgs]
if not {{*m(type,pkgs)}}=={{s}}: raise ValueError(f"spec: {{pkgs}} is invalid") if not {{*m(type,pkgs)}}=={{s}}: raise ValueError(f"spec: {{pkgs}} is invalid")
ge,sys,P,ew=i("os").getenv,i("sys"),i("pathlib").Path,i("sys").stderr.write ge,sys,P,ew=i("os").getenv,i("sys"),i("pathlib").Path,i("sys").stderr.write
@ -569,7 +570,7 @@ STANDALONE_TEMPLATE_USE = r"""def _viv_use(*pkgs: str, track_exe: bool = False,
with (env/"viv-info.json").open("w") as f: with (env/"viv-info.json").open("w") as f:
i("json").dump({{"created":s(i("datetime").datetime.today()),"id":_id,"spec":spec,"exe":exe}},f) i("json").dump({{"created":s(i("datetime").datetime.today()),"id":_id,"spec":spec,"exe":exe}},f)
sys.path = [p for p in (*sys.path,s(*(env/"lib").glob("py*/si*"))) if p!=i("site").USER_SITE] sys.path = [p for p in (*sys.path,s(*(env/"lib").glob("py*/si*"))) if p!=i("site").USER_SITE]
_viv_use({spec}) {use}
""" # noqa """ # noqa
SHOW_TEMPLATE = f""" SHOW_TEMPLATE = f"""
@ -661,9 +662,15 @@ def generate_import(
sys.stdout.write( sys.stdout.write(
STANDALONE_TEMPLATE.format( STANDALONE_TEMPLATE.format(
version=__version__, version=__version__,
use=noqa( func=noqa(
STANDALONE_TEMPLATE_USE.format( STANDALONE_TEMPLATE_FUNC.format(
spec=", ".join(f'"{pkg}"' for pkg in resolved_spec.splitlines()) use="_viv_use("
+ fill(
", ".join(f'"{pkg}"' for pkg in resolved_spec.splitlines()),
width=100,
subsequent_indent=" ",
)
+ ")"
) )
), ),
) )
@ -1113,6 +1120,9 @@ class Viv:
), ),
): ):
self._install_local_src(sha256, args.src, args.cli) self._install_local_src(sha256, args.src, args.cli)
def shim(self, args):
"""generate viv-powered cli apps"""
echo("not implemented.")
def _get_subcmd_parser( def _get_subcmd_parser(
self, self,
@ -1274,6 +1284,11 @@ class Viv:
"-p", "--pythonpath", help="show the path/to/install", action="store_true" "-p", "--pythonpath", help="show the path/to/install", action="store_true"
) )
self._get_subcmd_parser(
subparsers,
"shim",
).set_defaults(func=self.shim, cmd="shim")
args = parser.parse_args() args = parser.parse_args()
args.func(args) args.func(args)