-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new dev and rm-all command * add response tests * update readme
- Loading branch information
Showing
18 changed files
with
531 additions
and
338 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
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
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,64 @@ | ||
from .transformer import Transformer | ||
from .loader import Loader | ||
from .homer import save_metadata | ||
from .helper import out | ||
from .builder import run_cli as cli_runner | ||
|
||
import time | ||
from datetime import datetime, timedelta | ||
from watchdog.observers import Observer | ||
from watchdog.events import FileSystemEventHandler, FileModifiedEvent | ||
from pathlib import Path | ||
import threading | ||
|
||
|
||
class CLIManifestReloader(FileSystemEventHandler): | ||
def __init__(self, manifest_path: str, run_cli: bool, run_cli_args: tuple[str]) -> None: | ||
self.manifest_path = manifest_path | ||
self.run_cli = run_cli | ||
self.run_cli_args = run_cli_args | ||
self.last_modified = datetime.now() | ||
|
||
super().__init__() | ||
|
||
def on_modified(self, event): | ||
if event.is_directory or not event.src_path.endswith(self.manifest_path): | ||
return | ||
|
||
if not isinstance(event, FileModifiedEvent): | ||
return | ||
|
||
if datetime.now() - self.last_modified < timedelta(seconds=1): | ||
return | ||
|
||
self.last_modified = datetime.now() | ||
|
||
t = threading.Thread(target=self.reload, args=(self.manifest_path, self.run_cli, self.run_cli_args)) | ||
t.daemon = True | ||
t.start() | ||
|
||
@classmethod | ||
def watch(cls, manifest_path: str, run_cli: bool, run_cli_args: tuple[str]): | ||
event_handler = cls(manifest_path, run_cli, run_cli_args) | ||
observer = Observer() | ||
observer.schedule(event_handler, path=Path(manifest_path).parent, recursive=False) | ||
observer.start() | ||
|
||
try: | ||
while True: | ||
time.sleep(1) | ||
except KeyboardInterrupt: | ||
observer.stop() | ||
observer.join() | ||
|
||
@staticmethod | ||
def reload(manifest_path: str, run_cli: bool, run_cli_args: tuple[str]): | ||
manifest_io = open(manifest_path, "r") | ||
|
||
T = Transformer(manifest_io) | ||
Loader.load_from_cli(T.cli) | ||
save_metadata(manifest_io.name, T.cli) | ||
out(f"✨ Reloaded {T.cli.name} CLI v{T.cli.version} ✨", fg="green") | ||
|
||
if run_cli: | ||
cli_runner(T.cli.name, T.cli.code, run_cli_args) |
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
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,71 @@ | ||
## Generated penv on 2024-08-02 14:08:54.032251 | ||
import typer | ||
import subprocess | ||
from typing import Optional | ||
import os | ||
from pathlib import Path | ||
from shutil import rmtree | ||
|
||
|
||
HOME_PATH = str(Path.home()) | ||
DEFAULT_VENV_STORE = f"{HOME_PATH}/venv-store/" | ||
|
||
|
||
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) | ||
cli = typer.Typer(context_settings=CONTEXT_SETTINGS, help="""~ Virtualenv store ~ | ||
Simplify virtualenvs | ||
""") | ||
__version__ = '0.1.0' | ||
__cli_name__ = 'penv' | ||
|
||
|
||
def version_callback(value: bool): | ||
if value: | ||
print(f"{__cli_name__}, {__version__}") | ||
raise typer.Exit() | ||
|
||
|
||
@cli.callback() | ||
def main(version: Optional[bool] = typer.Option(None, '--version', callback=version_callback, is_eager=True)): | ||
pass | ||
|
||
def get_venv_path(name: str) -> str: | ||
return f"{DEFAULT_VENV_STORE}{name}" | ||
|
||
def venv_exists(name: str) -> bool: | ||
return os.path.exists(get_venv_path(name)) | ||
|
||
|
||
|
||
@cli.command("ls") | ||
def ls(): | ||
""" | ||
List venvs in the store | ||
""" | ||
subprocess.run(["ls",f"""{DEFAULT_VENV_STORE}"""]) | ||
|
||
|
||
@cli.command("rm") | ||
def rm(name: str = typer.Argument(...)): | ||
""" | ||
Remove a venv | ||
""" | ||
rmtree(get_venv_path(name)) | ||
|
||
|
||
@cli.command("go") | ||
def go(name: str = typer.Argument(...), interpreter: str = typer.Option("python", "--interpreter", "-i")): | ||
""" | ||
Activate a venv | ||
""" | ||
if venv_exists(name): | ||
print(f"~ sourcing {name}") | ||
else: | ||
print(f"~ creating {name}") | ||
subprocess.run([f"""{interpreter}""","-m","venv",f"""{os.path.join(DEFAULT_VENV_STORE, name)}"""]) | ||
|
||
os.system(f"""bash -c ". {get_venv_path(name)}/bin/activate; env PS1='\[\e[38;5;211m\]({name})\[\e[\033[00m\] \w $ ' bash --norc\"""") | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
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
Oops, something went wrong.