Compare commits

...

6 commits

6 changed files with 67 additions and 52 deletions

View file

@ -1,13 +1,9 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
language_version: python
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.270'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.10
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
args: [ --fix ]
- id: ruff-format

View file

@ -1,6 +0,0 @@
USAGE={a.bold}{a.cyan} viv tasks{a.end}:\n
PHONIFY=1
HELP_SEP={a.b_blue}>>>{a.end}
-include .task.mk
$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v23.1.2/task.mk -o .task.mk)

View file

@ -1,28 +0,0 @@
VERSION ?= $(shell git describe --tags --always --dirty=-dev | sed 's/^v//g')
venv: ## generate environment
pdm install
assets/viv-help.svg:
FORCE_COLOR=1 viv --help | yartsu -t 'viv --help' -w 70 -o $@
.PHONY: dev-install
dev-install:
ln -sf $(PWD)/src/viv/viv.py ~/.local/share/viv/viv.py
examples/black: .FORCE
rm -f $@
viv shim black -y -s -f -o $@
clean: ## remove build artifacts
rm -rf build dist
EXAMPLES = cli.py sys_path.py exe_specific.py frozen_import.py named_env.py scrape.py
generate-example-vivens: ##
for f in $(EXAMPLES); \
do python examples/$$f; done
.FORCE:
.PHONY: .FORCE
-include .task.cfg.mk

View file

@ -7,9 +7,7 @@ import sys
old_sys_path = sys.path.copy() # noqa
__import__("sys").path.append(
__import__("os").path.expanduser("~/.local/share/viv")
) # noqa # isort: off
__import__("sys").path.append(__import__("os").path.expanduser("~/.local/share/viv")) # noqa # isort: off
__import__("viv").use("rich") # noqa # isort: off
from difflib import unified_diff

View file

@ -1033,7 +1033,6 @@ class ViVenv:
self.ensure()
self.touch()
# TODO: get username for directories below
try:
if self.loaded or keep or run_mode == "persist":
common()
@ -1514,9 +1513,7 @@ class Viv:
vivenv = self._match_vivenv(vivenv_id)
bin = vivenv.path / "bin" / cmd
vivenv.bin_exists(bin.name)
full_cmd = [str(bin), *rest]
# TODO: use subprocess_run_quit
@ -1727,9 +1724,9 @@ class Viv:
f"Write shim for {a.bold}{bin}{a.end} to {a.green}{output}{a.end}?",
yes=yes,
):
output.parent.mkdir(exist_ok=True, parents=True)
with output.open("w") as f:
f.write(self.t.shim(path, self.local_source, standalone, spec, bin))
make_executable(output)
@staticmethod
@ -1988,7 +1985,6 @@ class Cli:
"list",
"shim",
"run",
# "exe",
"env",
"freeze",
"manage",
@ -2177,9 +2173,20 @@ class Cli:
)
def _no_traceback_excepthook(exc_type, exc_val, traceback):
# https://stackoverflow.com/questions/7073268/remove-traceback-in-python-on-ctrl-c
pass
def main() -> None:
try:
viv = Viv()
Cli(viv).run()
except KeyboardInterrupt:
echo(f"caught {a.bold}SIGINT")
if sys.excepthook is sys.__excepthook__:
sys.excepthook = _no_traceback_excepthook
raise
if __name__ == "__main__":

48
task Executable file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env bash
# VERSION = $(git describe --tags --always --dirty=-dev | sed 's/^v//g')
function task:venv {
: "setup up pdm venv"
pdm install
}
function task:dev-install {
: "symlink development version"
mkdir -p ~/.local/share/viv
mkdir -p ~/.local/bin
ln -sf "$(pwd)/src/viv/viv.py" ~/.local/share/viv/viv.py
ln -sf ~/.local/share/viv/viv.py ~/.local/bin/viv
}
function task:_black {
: "generate black example shim"
rm -f examples/black
viv shim black -y -s -f -o examples/black
}
function task:clean {
: "clean build artifacts"
rm -rf build dist
}
function task:examples {
: "run examples to generate vivenvs"
examples="cli sys_path exe_specific frozen_import named_env scrape"
for f in $examples; do
python "examples/$f.py"
done
}
function task:_help-logo {
FORCE_COLOR=1 viv --help | yartsu -t 'viv --help' -w 70 -o assets/viv-help.svg
}
# ---- do-task boilerplate ----
function task:help {
: "Show this help"
echo "do:";w=$(("$(compgen -A function | wc -L)" - 3));while read -r name; do [[ ! $name =~ ^task:_ ]] && [[ $name =~ ^task: ]] && paste <(printf '\033[1;32m%*s\033[0m\n' "$w" "${name#task:}") <(type "$name" | sed -nEe 's/^[[:space:]]*: ?"(.*)";/\1/p'); done < <(compgen -A function)
}
while read -r name; do [[ $name == "task:$1" ]] && { shift; task="$name"; }; done < <(compgen -A function)
[[ -n "$1" && -z "$task" ]] && printf "\033[1;31m%s\033\0[m is not a task\n" "$1"
"${task:-task:help}" "$@" && exit "$?"