ensure running in venv
This commit is contained in:
parent
be95c352d6
commit
a8a1f425cc
@ -82,6 +82,13 @@ PIP_HOOK = """# GENERATED BY MOMMY
|
|||||||
sys.exit(code)"""
|
sys.exit(code)"""
|
||||||
|
|
||||||
|
|
||||||
|
def assert_venv():
|
||||||
|
if not IS_VENV:
|
||||||
|
mommy_logger.error("mommy doesn't run in a virtual environment~")
|
||||||
|
serious_logger.error("this has to run in a virtual environment")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def wrap_interpreter(path: Path):
|
def wrap_interpreter(path: Path):
|
||||||
mommy_logger.info("mommy found a symlink to an interpreter~ %s", str(path))
|
mommy_logger.info("mommy found a symlink to an interpreter~ %s", str(path))
|
||||||
serious_logger.info("interpreter symlink found at %s", str(path))
|
serious_logger.info("interpreter symlink found at %s", str(path))
|
||||||
@ -130,6 +137,8 @@ def install_pip_hook(path: Path):
|
|||||||
|
|
||||||
|
|
||||||
def mommify_venv():
|
def mommify_venv():
|
||||||
|
assert_venv()
|
||||||
|
|
||||||
compile_local = False
|
compile_local = False
|
||||||
compiled_base_dir = VENV_DIRECTORY if compile_local else CONFIG_DIRECTORY
|
compiled_base_dir = VENV_DIRECTORY if compile_local else CONFIG_DIRECTORY
|
||||||
compiled_config_file = compiled_base_dir / COMPILED_CONFIG_FILE_NAME
|
compiled_config_file = compiled_base_dir / COMPILED_CONFIG_FILE_NAME
|
||||||
|
@ -73,19 +73,27 @@ def _get_xdg_config_dir() -> Path:
|
|||||||
CONFIG_DIRECTORY = _get_xdg_config_dir() / "mommy"
|
CONFIG_DIRECTORY = _get_xdg_config_dir() / "mommy"
|
||||||
COMPILED_CONFIG_FILE_NAME = "compiled-mommy.json"
|
COMPILED_CONFIG_FILE_NAME = "compiled-mommy.json"
|
||||||
|
|
||||||
|
IS_VENV = sys.prefix != sys.base_prefix
|
||||||
|
VENV_DIRECTORY = Path(sys.prefix)
|
||||||
|
|
||||||
def get_config_file() -> Optional[Path]:
|
def get_config_file() -> Optional[Path]:
|
||||||
config_files = [
|
config_files = []
|
||||||
|
if IS_VENV:
|
||||||
|
config_files.extend([
|
||||||
|
VENV_DIRECTORY / "python-mommy.toml",
|
||||||
|
VENV_DIRECTORY / "mommy.toml",
|
||||||
|
])
|
||||||
|
config_files.extend([
|
||||||
CONFIG_DIRECTORY / "python-mommy.toml",
|
CONFIG_DIRECTORY / "python-mommy.toml",
|
||||||
CONFIG_DIRECTORY / "mommy.toml",
|
CONFIG_DIRECTORY / "mommy.toml",
|
||||||
]
|
])
|
||||||
|
|
||||||
for f in config_files:
|
for f in config_files:
|
||||||
if f.exists():
|
if f.exists():
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
IS_VENV = sys.prefix != sys.base_prefix
|
|
||||||
VENV_DIRECTORY = Path(sys.prefix)
|
|
||||||
|
|
||||||
def get_compiled_config_file() -> Path:
|
def get_compiled_config_file() -> Path:
|
||||||
compiled_config_files = [
|
compiled_config_files = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user