Compare commits

..

No commits in common. "a8a1f425ccc0e9def00b98089373ff90a86deb79" and "d1fe9d55d5096b99d05c01813587ae9d40910844" have entirely different histories.

4 changed files with 23 additions and 72 deletions

View File

@ -3,7 +3,8 @@ import sys
from typing import Optional
import json
from .static import colors, get_compiled_config_file
from .responses import COMPILED_CONFIG_FILE
from .static import colors
def get_response_from_situation(situation: str, colorize: Optional[bool] = None):
@ -11,7 +12,7 @@ def get_response_from_situation(situation: str, colorize: Optional[bool] = None)
colorize = sys.stdout.isatty()
# get message
config = json.loads(get_compiled_config_file().read_text())
config = json.loads(COMPILED_CONFIG_FILE.read_text())
existing_moods = list(config["moods"].keys())
template_options = config["moods"][random.choice(existing_moods)][situation]
template: str = random.choice(template_options)

View File

@ -3,11 +3,11 @@ from pathlib import Path
import stat
import subprocess
import logging
import json
import toml
from . import get_response
from .responses import compile_config
from .static import IS_VENV, VENV_DIRECTORY, CONFIG_DIRECTORY, COMPILED_CONFIG_FILE_NAME
logging.basicConfig(
format=' %(message)s',
@ -82,13 +82,6 @@ PIP_HOOK = """# GENERATED BY MOMMY
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):
mommy_logger.info("mommy found a symlink to an interpreter~ %s", str(path))
serious_logger.info("interpreter symlink found at %s", str(path))
@ -137,23 +130,13 @@ def install_pip_hook(path: Path):
def mommify_venv():
assert_venv()
compile_config()
compile_local = False
compiled_base_dir = VENV_DIRECTORY if compile_local else CONFIG_DIRECTORY
compiled_config_file = compiled_base_dir / COMPILED_CONFIG_FILE_NAME
v = ".venv"
if len(sys.argv) > 1:
v = sys.argv[1]
compiled = compile_config()
mommy_logger.info("mommy writes its moods in %s", compiled_config_file)
serious_logger.info("writing compiled config file to %s", compiled_config_file)
compiled_base_dir.mkdir(parents=True, exist_ok=True)
with compiled_config_file.open("w") as f:
json.dump(compiled, f, indent=4)
serious_logger.info("")
mommy_logger.info("")
bin_path = VENV_DIRECTORY / "bin"
bin_path = Path(v, "bin")
bin_path = bin_path.resolve()
mommy_logger.info("mommy looks in %s to mess your system up~ <33", str(bin_path))
@ -165,10 +148,10 @@ def mommify_venv():
if path.is_symlink():
# could be python interpreter
# check for both just to be more expressive
if name.startswith("inner_"):
if name.startswith("inner_") or not name.startswith("python"):
continue
if subprocess.run([str(path), '-c', '"exit(0)"']).returncode != 0:
if subprocess.run([str(path), '-c', '"exit()"']) != 0:
continue
wrap_interpreter(path)
@ -179,3 +162,6 @@ def mommify_venv():
continue
install_pip_hook(path)
serious_logger.info("")
mommy_logger.info("")

View File

@ -9,9 +9,8 @@ import requests
from .static import get_config_file
mommy_logger = logging.getLogger("mommy")
serious_logger = logging.getLogger("serious")
logger = logging.Logger(__name__)
PREFIX = "MOMMY"
RESPONSES_URL = "https://raw.githubusercontent.com/diamondburned/go-mommy/refs/heads/main/responses.json"
@ -69,8 +68,9 @@ def compile_config(disable_requests: bool = False) -> dict:
data = json.loads(RESPONSES_FILE.read_text())
if not disable_requests:
mommy_logger.info("mommy downloads newest responses for her girl~ %s", RESPONSES_URL)
serious_logger.info("downloading cargo mommy responses: %s", RESPONSES_URL)
print("mommy downloads newest responses for her girl~")
print(RESPONSES_URL)
print()
r = requests.get(RESPONSES_URL)
data = r.json()
@ -103,18 +103,7 @@ def compile_config(disable_requests: bool = False) -> dict:
for mood in config["mood"]:
if mood not in mood_definitions:
supported_moods_str = ", ".join(mood_definitions.keys())
mommy_logger.error(
"%s doesn't know how to feel %s... %s moods are %s",
random.choice(config['role']),
mood,
random.choice(config['pronoun']),
supported_moods_str,
)
serious_logger.error(
"mood '%s' doesn't exist. moods are %s",
mood,
supported_moods_str,
)
print(f"{random.choice(config['role'])} doesn't know how to feel {mood}... {random.choice(config['pronoun'])} moods are {supported_moods_str}")
exit(1)
# compile

View File

@ -4,7 +4,6 @@ from pathlib import Path
import os
import logging
from typing import Optional
import sys
logger = logging.Logger(__name__)
@ -73,36 +72,12 @@ def _get_xdg_config_dir() -> Path:
CONFIG_DIRECTORY = _get_xdg_config_dir() / "mommy"
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]:
config_files = []
if IS_VENV:
config_files.extend([
VENV_DIRECTORY / "python-mommy.toml",
VENV_DIRECTORY / "mommy.toml",
])
config_files.extend([
config_files = [
CONFIG_DIRECTORY / "python-mommy.toml",
CONFIG_DIRECTORY / "mommy.toml",
])
]
for f in config_files:
if f.exists():
return f
def get_compiled_config_file() -> Path:
compiled_config_files = [
VENV_DIRECTORY / "compiled-mommy.json",
CONFIG_DIRECTORY / "compiled-mommy.json",
]
for f in compiled_config_files:
if f.exists():
return f
raise Exception("couldn't find compiled config file")