-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an auto-updating wrapper script.
- Install and run the package in a venv.
- Loading branch information
Showing
7 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ __pycache__ | |
|
||
/LICENSES.deps.txt | ||
/_build/ | ||
/_venv*/ | ||
/dist/ | ||
/node_modules/ | ||
/tdoc/common/static.gen/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
@echo off | ||
tdoc serve | ||
tdocv.py serve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
#!/usr/bin/env xdg-open | ||
[Desktop Entry] | ||
Name=Serve | ||
Name=tdoc serve | ||
Type=Application | ||
GenericName=Start a local server | ||
GenericName=Start a local t-doc server | ||
Comment= | ||
Icon=document-preview | ||
Exec=cd "$(dirname "%k")" && "${HOME}/.local/bin/tdoc" serve | ||
Exec=cd "$(dirname "%k")" && ./tdocv.py serve | ||
Path= | ||
Terminal=true | ||
StartupNotify=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
# Copyright 2025 Remy Blank <[email protected]> | ||
# SPDX-License-Identifier: MIT | ||
|
||
import contextlib | ||
import pathlib | ||
import subprocess | ||
import sys | ||
import venv | ||
|
||
# TODO: Support running a specific version | ||
|
||
|
||
class EnvBuilder(venv.EnvBuilder): | ||
def __init__(self, stderr): | ||
super().__init__(with_pip=True) | ||
self.stderr = stderr | ||
|
||
def post_setup(self, ctx): | ||
super().post_setup(ctx) | ||
self.pip(ctx, 'install', 't-doc-common') | ||
|
||
def pip(self, ctx, *args, json_output=False): | ||
subprocess.run((ctx.env_exec_cmd, '-m', 'pip') + args, check=True, | ||
stdin=subprocess.DEVNULL, stdout=self.stderr, | ||
stderr=self.stderr) | ||
|
||
|
||
def main(argv, stdin, stdout, stderr): | ||
base = pathlib.Path(argv[0]).parent.resolve() | ||
vdir = base / '_venv' | ||
|
||
# Create the venv if it doesn't exist. | ||
builder = EnvBuilder(stderr) | ||
if not vdir.exists(): | ||
stderr.write("Creating venv...\n") | ||
builder.create(vdir) | ||
stderr.write("\n") | ||
|
||
# Import from modules installed in the venv. | ||
for lib in (vdir / 'lib').glob('python*.*'): | ||
sys.path.append(lib / 'site-packages') | ||
with contextlib.suppress(ImportError): | ||
from tdoc.common import util | ||
break | ||
else: | ||
raise Exception("Failed to import tdoc.common.util") | ||
|
||
# Upgrade if available and requested by the user. | ||
util.check_upgrade(base, vdir, builder) | ||
|
||
# Run the command. | ||
subprocess.run([vdir / 'bin' / 'tdoc'] + argv[1:], check=True, cwd=base) | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
sys.exit(main(sys.argv, sys.stdin, sys.stdout, sys.stderr)) | ||
except SystemExit: | ||
raise | ||
except BaseException as e: | ||
if '--debug' in sys.argv: | ||
raise | ||
if not isinstance(e, KeyboardInterrupt): | ||
sys.stderr.write(f'\n{e}\n') | ||
sys.exit(1) |