From 9a76c5e672ecef03d3e799cadb30e3053b748583 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Sat, 27 May 2023 17:33:35 -0500 Subject: [PATCH] WIP --- src/viv/viv.py | 64 +++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/src/viv/viv.py b/src/viv/viv.py index 730b980..50fb70b 100755 --- a/src/viv/viv.py +++ b/src/viv/viv.py @@ -52,32 +52,46 @@ from typing import ( from urllib.error import HTTPError from urllib.request import urlopen -__version__ = "23.5a1-12-g298e8b2" +__version__ = "23.5a1-13-gbaad178" @dataclass class Config: """viv config manager""" - - venvcache: Path = ( + _venvcache: Path = ( Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache")) / "viv" / "venvs" ) - srccache: Path = ( + _srccache: Path = ( Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache")) / "viv" / "src" ) - share: Path = ( + _share: Path = ( Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local" / "share")) / "viv" ) + _binparent: Path = Path(os.getenv("VIV_BIN_DIR", Path.home() / ".local" / "bin")) - def __post_init__(self) -> None: - self.venvcache.mkdir(parents=True, exist_ok=True) - self.srccache.mkdir( - parents=True, - exist_ok=True, - ) - self.share.mkdir(parents=True, exist_ok=True) - self.srcdefault = self.share / "viv.py" + @property + def venvcache(self): + self._venvcache.mkdir(parents=True, exist_ok=True) + return self._venvcache + @property + def srccache(self): + self._srccache.mkdir(parents=True, exist_ok=True) + return self._srccache + + @property + def share(self): + self._share.mkdir(parents=True, exist_ok=True) + return self._share + + @property + def binparent(self): + self._binparent.mkdir(parents=True, exist_ok=True) + return self._binparent + + @property + def srcdefault(self) -> None: + return self.share / "viv.py" c = Config() @@ -1136,24 +1150,23 @@ class Viv: def shim(self, args): """generate viv-powered cli apps""" - if args.output.is_file(): - error(f"{args.output} already exists...exiting", code=1) - - # TODO: robustness.... + # TODO: robustness.... spec = ", ".join(f'"{req}"' for req in args.reqs) - if args.bin: - bin = args.bin - elif len(args.reqs) == 1: + if len(args.reqs) == 1: bin = args.reqs[0] + output = Path.cwd() / args.reqs[0] else: - error("please specify an explicit -b/--bin") + error("please specify an explicit -b/--bin and -o/--output") - with args.output.open("w") as f: + if output.is_file(): + error(f"{output} already exists...exiting", code=1) + + with output.open("w") as f: f.write(SHIM_TEMPLATE.format(use=f'__import__("viv").use({spec})', bin=bin)) - make_executable(args.output) + make_executable(output) def _get_subcmd_parser( self, @@ -1322,17 +1335,20 @@ class Viv: subparsers, "shim", parents=[p_freeze_shim_shared] ) ).set_defaults(func=self.shim, cmd="shim") + p_manage_shim.add_argument( + '-f',"--freeze", help="freeze/resolve all dependencies", action="store_true" + ) p_manage_shim.add_argument( "-o", "--output", help="path/to/output file", - required=True, type=Path, metavar="", ) p_manage_shim.add_argument( "-b", "--bin", help="console_script/script to invoke" ) + args = parser.parse_args() args.func(args)