Compare commits

..

4 commits

4 changed files with 39 additions and 23 deletions

View file

@ -8,8 +8,9 @@ A possible cli signature
viv shim black -o ~/bin/black
"""
import sys
import subprocess
import sys
import viv
if __name__ == "__main__":

View file

@ -17,7 +17,7 @@ homepage = "https://github.com/daylinmorgan/viv"
repository = "https://github.com/daylinmorgan/viv"
[project.scripts]
viv = "viv.viv:main"
viv = "viv:main"
[tool.pdm]
version = { source = "scm" }
@ -29,6 +29,7 @@ dev = [
]
[tool.ruff]
select = ["E","F","I"]
ignore = ["E402"]
[tool.mypy]

View file

@ -1 +1 @@
from .viv import use, __version__ # noqa
from .viv import __version__, use, main # noqa

View file

@ -21,17 +21,16 @@ import sys
import tempfile
import threading
import time
from urllib.request import urlopen
from urllib.error import HTTPError
import venv
from argparse import SUPPRESS, Action
from argparse import ArgumentParser as StdArgParser
from argparse import (
SUPPRESS,
Action,
HelpFormatter,
Namespace,
RawDescriptionHelpFormatter,
_SubParsersAction,
)
from argparse import ArgumentParser as StdArgParser
from dataclasses import dataclass
from datetime import datetime
from itertools import zip_longest
@ -50,8 +49,10 @@ from typing import (
Tuple,
Type,
)
from urllib.error import HTTPError
from urllib.request import urlopen
__version__ = "23.5a1"
__version__ = "23.5a1-3-g3a85fe4-dev"
@dataclass
@ -64,10 +65,8 @@ class Config:
srccache: Path = (
Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache")) / "viv" / "src"
)
srcdefault: Path = (
Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local" / "share"))
/ "viv"
/ "viv.py"
share: Path = (
Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local" / "share")) / "viv"
)
def __post_init__(self) -> None:
@ -76,7 +75,8 @@ class Config:
parents=True,
exist_ok=True,
)
self.srcdefault.parent.mkdir(parents=True, exist_ok=True)
self.share.mkdir(parents=True, exist_ok=True)
self.srcdefault = self.share / "viv.py"
c = Config()
@ -466,12 +466,14 @@ class ViVenv:
def dump_info(self, write: bool = False) -> None:
# TODO: include associated files in 'info'
# means it needs to be loaded first
# or keep a seperate file hash in c.share?
info = {
"created": str(datetime.today()),
"id": self.id,
"spec": self.spec,
"exe": self.exe,
}
# save metadata to json file
if write:
with (self.path / "viv-info.json").open("w") as f:
@ -1027,8 +1029,14 @@ class Viv:
"""manage viv itself"""
if args.cmd == "show":
if args.pythonpath:
if not self.local:
error("expected to find a local installation", exit=1)
else:
sys.stdout.write(str(self.local_source.parent) + "\n")
else:
echo("Current:")
sys.stdout.write(
sys.stderr.write(
SHOW_TEMPLATE.format(
version=__version__,
cli=shutil.which("viv"),
@ -1256,10 +1264,16 @@ class Viv:
parents=[p_manage_shared],
).set_defaults(func=self.manage, cmd="update")
p_manage_sub.add_parser(
(
p_manage_show := p_manage_sub.add_parser(
"show", help="show current installation info", aliases="s"
)
).set_defaults(func=self.manage, cmd="show")
p_manage_show.add_argument(
"-p", "--pythonpath", help="show the path/to/install", action="store_true"
)
args = parser.parse_args()
args.func(args)