mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-11-10 03:13:14 -06:00
WIP
This commit is contained in:
parent
baad1783a2
commit
9a76c5e672
1 changed files with 40 additions and 24 deletions
|
@ -52,32 +52,46 @@ 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-12-g298e8b2"
|
__version__ = "23.5a1-13-gbaad178"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Config:
|
class Config:
|
||||||
"""viv config manager"""
|
"""viv config manager"""
|
||||||
|
_venvcache: Path = (
|
||||||
venvcache: Path = (
|
|
||||||
Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache")) / "viv" / "venvs"
|
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"
|
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"
|
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:
|
@property
|
||||||
self.venvcache.mkdir(parents=True, exist_ok=True)
|
def venvcache(self):
|
||||||
self.srccache.mkdir(
|
self._venvcache.mkdir(parents=True, exist_ok=True)
|
||||||
parents=True,
|
return self._venvcache
|
||||||
exist_ok=True,
|
|
||||||
)
|
|
||||||
self.share.mkdir(parents=True, exist_ok=True)
|
|
||||||
self.srcdefault = self.share / "viv.py"
|
|
||||||
|
|
||||||
|
@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()
|
c = Config()
|
||||||
|
|
||||||
|
@ -1136,24 +1150,23 @@ class Viv:
|
||||||
|
|
||||||
def shim(self, args):
|
def shim(self, args):
|
||||||
"""generate viv-powered cli apps"""
|
"""generate viv-powered cli apps"""
|
||||||
if args.output.is_file():
|
# TODO: robustness....
|
||||||
error(f"{args.output} already exists...exiting", code=1)
|
|
||||||
|
|
||||||
# TODO: robustness....
|
|
||||||
|
|
||||||
spec = ", ".join(f'"{req}"' for req in args.reqs)
|
spec = ", ".join(f'"{req}"' for req in args.reqs)
|
||||||
|
|
||||||
if args.bin:
|
if len(args.reqs) == 1:
|
||||||
bin = args.bin
|
|
||||||
elif len(args.reqs) == 1:
|
|
||||||
bin = args.reqs[0]
|
bin = args.reqs[0]
|
||||||
|
output = Path.cwd() / args.reqs[0]
|
||||||
else:
|
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))
|
f.write(SHIM_TEMPLATE.format(use=f'__import__("viv").use({spec})', bin=bin))
|
||||||
|
|
||||||
make_executable(args.output)
|
make_executable(output)
|
||||||
|
|
||||||
def _get_subcmd_parser(
|
def _get_subcmd_parser(
|
||||||
self,
|
self,
|
||||||
|
@ -1322,17 +1335,20 @@ class Viv:
|
||||||
subparsers, "shim", parents=[p_freeze_shim_shared]
|
subparsers, "shim", parents=[p_freeze_shim_shared]
|
||||||
)
|
)
|
||||||
).set_defaults(func=self.shim, cmd="shim")
|
).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(
|
p_manage_shim.add_argument(
|
||||||
"-o",
|
"-o",
|
||||||
"--output",
|
"--output",
|
||||||
help="path/to/output file",
|
help="path/to/output file",
|
||||||
required=True,
|
|
||||||
type=Path,
|
type=Path,
|
||||||
metavar="<path>",
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
p_manage_shim.add_argument(
|
p_manage_shim.add_argument(
|
||||||
"-b", "--bin", help="console_script/script to invoke"
|
"-b", "--bin", help="console_script/script to invoke"
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
args.func(args)
|
args.func(args)
|
||||||
|
|
Loading…
Reference in a new issue