feat: move project from poetry to pdm, rewrite from scratch and add

basic `notebooks`, `edit` and `show` commands
This commit is contained in:
cătălin 2023-04-01 12:37:10 +02:00
commit d3ad87211e
Signed by: catalin
GPG key ID: 686088EF78EE4083
35 changed files with 1309 additions and 1434 deletions

View file

@ -1,48 +0,0 @@
import os
import subprocess
from pathlib import Path
from halig import logger
from halig.exceptions import CouldNotEditTempfile
def resolve_path(path: Path) -> Path:
"""Resolve a path's relative attributes, like envvars, relative notations, etc
Args:
path(Path): The path to resolve
Returns:
Path: The resolved path
"""
return Path(os.path.expandvars(path)).expanduser().resolve()
def get_template_data(path: Path) -> str | None:
"""Read template data from path/template.halig
Args:
path(Path): The path to read template data from, usually a notebook
Returns:
maybe returns a string containing the template data
"""
template_path = path / "template.halig"
if not (template_path.exists() and template_path.is_file()):
return None
with open(template_path) as f:
return f.read()
def wait_for_editor(filepath: str):
"""Wait for $EDITOR to be opened and then manually closed by the user
Args:
filepath(Path): The filepath which $EDITOR should modify
Raises:
CouldNotEditTempfile if the subprocess call errors out
"""
try:
subprocess.call([os.environ.get("EDITOR", "vim"), filepath])
except subprocess.CalledProcessError as e:
logger.error(e.output)
raise CouldNotEditTempfile