mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-09-20 12:07:18 -05:00
Compare commits
3 commits
a350fa30b7
...
954a7b556e
Author | SHA1 | Date | |
---|---|---|---|
954a7b556e | |||
9a76c5e672 | |||
baad1783a2 |
1 changed files with 61 additions and 14 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-dev"
|
__version__ = "23.5a1-14-g9a76c5e"
|
||||||
|
|
||||||
|
|
||||||
@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()
|
||||||
|
|
||||||
|
@ -593,6 +607,16 @@ UPDATE_TEMPLATE = f"""
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
SHIM_TEMPLATE = """\
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
vivenv = {use}
|
||||||
|
sys.exit(subprocess.run([vivenv.path / "bin" / "{bin}", *sys.argv[1:]]).returncode)
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def noqa(txt: str) -> str:
|
def noqa(txt: str) -> str:
|
||||||
max_length = max(map(len, txt.splitlines()))
|
max_length = max(map(len, txt.splitlines()))
|
||||||
|
@ -950,6 +974,8 @@ class Viv:
|
||||||
"""create import statement from package spec"""
|
"""create import statement from package spec"""
|
||||||
# TODO: warn user about using anything but standalone when
|
# TODO: warn user about using anything but standalone when
|
||||||
# self.local_source is 'Not Found'
|
# self.local_source is 'Not Found'
|
||||||
|
if self.local_source == "Not Found" and not (args.standalone or args.path):
|
||||||
|
warn("failed to find local copy of `viv` make sure to add it to your PYTHONPATH")
|
||||||
|
|
||||||
if not args.reqs:
|
if not args.reqs:
|
||||||
error("must specify a requirement", code=1)
|
error("must specify a requirement", code=1)
|
||||||
|
@ -1126,7 +1152,23 @@ class Viv:
|
||||||
|
|
||||||
def shim(self, args):
|
def shim(self, args):
|
||||||
"""generate viv-powered cli apps"""
|
"""generate viv-powered cli apps"""
|
||||||
echo("not implemented.")
|
# TODO: robustness....
|
||||||
|
|
||||||
|
spec = ", ".join(f'"{req}"' for req in args.reqs)
|
||||||
|
|
||||||
|
if len(args.reqs) == 1:
|
||||||
|
bin = args.reqs[0]
|
||||||
|
output = Path.cwd() / args.reqs[0]
|
||||||
|
else:
|
||||||
|
error("please specify an explicit -b/--bin and -o/--output")
|
||||||
|
|
||||||
|
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(output)
|
||||||
|
|
||||||
def _get_subcmd_parser(
|
def _get_subcmd_parser(
|
||||||
self,
|
self,
|
||||||
|
@ -1295,15 +1337,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",
|
||||||
|
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