feat: add experimental support for windows

This commit is contained in:
Daylin Morgan 2023-09-27 15:53:27 -05:00
parent 24787a746c
commit 7286e90a36
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
2 changed files with 33 additions and 15 deletions

View file

@ -9,11 +9,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python-version: python-version: ['3.8','3.9','3.10','3.11']
- '3.8' os:
- '3.9' - ubuntu-latest
- '3.10' - windows-latest
- '3.11' # - macos-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4

View file

@ -1,4 +1,4 @@
#!/usr/bin/env -S python3 -S #!/usr/bin/env python3
"""viv isn't venv! """viv isn't venv!
viv -h viv -h
@ -13,6 +13,7 @@ import itertools
import json import json
import logging import logging
import os import os
import platform
import re import re
import shutil import shutil
import site import site
@ -158,7 +159,22 @@ class Env:
return run_mode return run_mode
class System:
def __init__(self) -> None:
self._windows = platform.system() == "Windows"
(self.bin_dir, *_) = ("Scripts",) if self._windows else ("bin",)
def bin(self, exe: str) -> str:
return f"{exe}.exe" if self._windows else exe
system = System()
class Cfg: class Cfg:
def __init__(self) -> None:
self.windows = platform.system() == "Windows"
@property @property
def src(self) -> Path: def src(self) -> Path:
p = Path(Env().xdg_data_home) / "viv" / "viv.py" p = Path(Env().xdg_data_home) / "viv" / "viv.py"
@ -889,8 +905,10 @@ class ViVenv:
def set_path(self, path: Path | None = None) -> None: def set_path(self, path: Path | None = None) -> None:
self.path = path if path else Cfg().cache_venv / self.name self.path = path if path else Cfg().cache_venv / self.name
self.python = str((self.path / "bin" / "python").absolute()) self.python = str(
self.pip = ("pip", "--python", self.python) (self.path / system.bin_dir / system.bin("python")).absolute()
)
self.pip = (system.bin("pip"), "--python", self.python)
def _validate_spec(self, spec: List[str]) -> List[str]: def _validate_spec(self, spec: List[str]) -> List[str]:
"""ensure spec is at least of sequence of strings """ensure spec is at least of sequence of strings
@ -907,13 +925,13 @@ class ViVenv:
return sorted(spec) return sorted(spec)
def bin_exists(self, bin: str) -> None: def bin_exists(self, bin: str) -> None:
if not (self.path / "bin" / bin).is_file(): if not (self.path / system.bin_dir / bin).is_file():
message = f"{a.bold}{bin}{a.end} does not exist " "\nOptions:\n" message = f"{a.bold}{bin}{a.end} does not exist " "\nOptions:\n"
message += " " + " ".join( message += " " + " ".join(
( (
a.style(p.name, "bold") a.style(p.name, "bold")
for p in (self.path / "bin").iterdir() for p in (self.path / system.bin_dir).iterdir()
if not p.name.lower().startswith("activate") if not p.name.lower().startswith("activate")
) )
) )
@ -927,7 +945,7 @@ class ViVenv:
self.path, self.path,
prompt=f"viv-{self.name}", prompt=f"viv-{self.name}",
clear=True, clear=True,
symlinks=True, symlinks=platform.system() != "Windows",
) )
self.meta.created = str(datetime.today()) self.meta.created = str(datetime.today())
@ -1114,7 +1132,7 @@ def resolve_deps(reqs: List[str], requirements: Path) -> List[str]:
spec = combined_spec(reqs, requirements) spec = combined_spec(reqs, requirements)
cmd = [ cmd = [
"pip", system.bin("pip"),
"install", "install",
"--dry-run", "--dry-run",
"--quiet", "--quiet",
@ -1658,7 +1676,7 @@ class Viv:
) )
def _pick_bin(self, reqs: List[str], bin: str) -> Tuple[str, str]: def _pick_bin(self, reqs: List[str], bin: str) -> Tuple[str, str]:
default = re.split(r"[=><~!*]+", reqs[0])[0] default = system.bin(re.split(r"[=><~!*]+", reqs[0])[0])
return default, (default if not bin else bin) return default, (default if not bin else bin)
def cmd_shim( def cmd_shim(
@ -1810,7 +1828,7 @@ class Viv:
vivenv.meta.write(vivenv.path / "vivmeta.json") vivenv.meta.write(vivenv.path / "vivmeta.json")
vivenv.bin_exists(bin) vivenv.bin_exists(bin)
subprocess_run_quit([vivenv.path / "bin" / bin, *rest]) subprocess_run_quit([vivenv.path / system.bin_dir / bin, *rest])
class Arg: class Arg: