Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doctor: fix error when config is on read only partition #417

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/promnesia/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import ast
import importlib
import inspect
import os
from pathlib import Path
import shutil
from subprocess import run, check_call, Popen
import sys
from tempfile import TemporaryDirectory
from tempfile import TemporaryDirectory, gettempdir
from typing import Callable, Sequence, Iterable, Iterator, Union


Expand Down Expand Up @@ -216,15 +217,23 @@ def config_check(args: argparse.Namespace) -> None:
def _config_check(cfg: Path) -> Iterable[Exception]:
logger.info('config: %s', cfg)

def check(cmd: list[str | Path]) -> Iterable[Exception]:
def check(cmd: list[str | Path], **kwargs) -> Iterable[Exception]:
logger.debug(' '.join(map(str, cmd)))
res = run(cmd)
res = run(cmd, **kwargs)
if res.returncode > 0:
yield Exception()

logger.info('Checking syntax...')
cmd: list[str | Path] = [sys.executable, '-m', 'compileall', cfg]
yield from check(cmd)
yield from check(
cmd,
env={
**os.environ,
# if config is on read only partition, the command would fail due to generated bytecode
# so put it in the temporary directory instead
'PYTHONPYCACHEPREFIX': gettempdir()
},
)

# todo not sure if should be more defensive than check_call here
logger.info('Checking type safety...')
Expand Down