Compare commits
5 Commits
69f6a11874
...
9040b26279
Author | SHA1 | Date | |
---|---|---|---|
|
9040b26279 | ||
|
98d656b2fe | ||
|
abadff31d8 | ||
|
ba36851336 | ||
|
d9e6bac410 |
@ -94,12 +94,12 @@ def assert_venv(only_warn: bool = False):
|
||||
exit(1)
|
||||
|
||||
|
||||
def write_compile_config(local: bool):
|
||||
def write_compile_config(local: bool, disable_requests: bool = False):
|
||||
assert_venv(only_warn=not local)
|
||||
|
||||
compiled_base_dir = VENV_DIRECTORY if local else CONFIG_DIRECTORY
|
||||
compiled_config_file = compiled_base_dir / COMPILED_CONFIG_FILE_NAME
|
||||
compiled = compile_config()
|
||||
compiled = compile_config(disable_requests=disable_requests)
|
||||
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)
|
||||
@ -169,9 +169,16 @@ def cli_compile_config():
|
||||
help="compile the config only for the current virtual environment"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-r", "--no-requests",
|
||||
action="store_true",
|
||||
help="by default if makes one request to GitHub to fetch the newest responses, this disables that"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
write_compile_config(args.local)
|
||||
config_logging(args.verbose)
|
||||
write_compile_config(args.local, disable_requests=args.no_requests)
|
||||
|
||||
|
||||
def mommify_venv():
|
||||
@ -189,6 +196,12 @@ def mommify_venv():
|
||||
help="compile the config only for the current virtual environment"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-r", "--no-requests",
|
||||
action="store_true",
|
||||
help="by default if makes one request to GitHub to fetch the newest responses, this disables that"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
config_logging(args.verbose)
|
||||
@ -204,10 +217,17 @@ def mommify_venv():
|
||||
mommy_logger.info("mommy looks in %s to mess your system up~ <33", str(bin_path))
|
||||
serious_logger.info("scanning binary directory of venv at %s", str(bin_path))
|
||||
|
||||
resolved_symlinks = {}
|
||||
for path in list(bin_path.iterdir()):
|
||||
if path.is_symlink():
|
||||
resolved_symlinks[path.name] = path.resolve()
|
||||
# resolving the symlinks before making edits to anything because else it will mess up the resolving
|
||||
# and link to the wrapper instead of the original script
|
||||
resolved_symlinks = {
|
||||
path.name: path.resolve()
|
||||
for path in bin_path.iterdir()
|
||||
if path.is_symlink()
|
||||
}
|
||||
serious_logger.debug("resolved symlinks:\n%s", "\n".join(
|
||||
f"\t{name} => {str(target)}"
|
||||
for name, target in resolved_symlinks.items()
|
||||
))
|
||||
|
||||
for path in list(bin_path.iterdir()):
|
||||
name = path.name
|
||||
@ -217,8 +237,9 @@ def mommify_venv():
|
||||
# check for both just to be more expressive
|
||||
if name.startswith("inner_"):
|
||||
continue
|
||||
|
||||
if subprocess.run([str(path), '-c', '"exit(0)"']).returncode != 0:
|
||||
|
||||
RANDOM_RETURNCODE = 161
|
||||
if subprocess.run([str(path), '-c', f'exit({RANDOM_RETURNCODE})']).returncode != RANDOM_RETURNCODE:
|
||||
continue
|
||||
|
||||
wrap_interpreter(path, resolved_symlinks[path.name])
|
||||
|
@ -25,7 +25,7 @@ ADDITIONAL_ENV_VARS = {
|
||||
|
||||
|
||||
|
||||
def _load_config_file(config_file: Path) -> Dict[str, List[str]]:
|
||||
def _load_config_file(config_file: Path) -> dict:
|
||||
with config_file.open("r") as f:
|
||||
data = toml.load(f)
|
||||
|
||||
@ -95,7 +95,22 @@ def compile_config(disable_requests: bool = False) -> dict:
|
||||
# load config file
|
||||
config_file = get_config_file()
|
||||
if config_file is not None:
|
||||
config.update(_load_config_file(config_file))
|
||||
c = _load_config_file(config_file)
|
||||
serious_logger.debug(
|
||||
"config at %s:\n%s\n",
|
||||
config_file,
|
||||
json.dumps(c, indent=4)
|
||||
)
|
||||
|
||||
config["mood"] = c.get("moods", config["mood"])
|
||||
c_vars: dict = c.get("vars", {})
|
||||
# validate the config var values
|
||||
for key, val in c_vars.items():
|
||||
if not isinstance(val, list):
|
||||
mommy_logger.error("mommy needs the value of %s to be a list~", key)
|
||||
serious_logger.error("the value of %s is not a list", key)
|
||||
exit(1)
|
||||
config.update(c_vars)
|
||||
|
||||
# fill config with env
|
||||
for key, conf in config_definition.items():
|
||||
|
Loading…
x
Reference in New Issue
Block a user