|
|
|
|
@@ -33,14 +33,6 @@ def config_logging(verbose: bool):
|
|
|
|
|
serious_logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def development():
|
|
|
|
|
s = "positive"
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
s = sys.argv[1]
|
|
|
|
|
|
|
|
|
|
compile_config()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WRAPPER_TEMPLATE = """#!{inner_bin}
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
@@ -93,13 +85,29 @@ PIP_HOOK = """# GENERATED BY MOMMY
|
|
|
|
|
sys.exit(code)"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def assert_venv():
|
|
|
|
|
def assert_venv(only_warn: bool = False):
|
|
|
|
|
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")
|
|
|
|
|
serious_logger.error("this should run in a virtual environment")
|
|
|
|
|
if not only_warn:
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_compile_config(local: bool):
|
|
|
|
|
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()
|
|
|
|
|
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)
|
|
|
|
|
if not local:
|
|
|
|
|
(VENV_DIRECTORY / COMPILED_CONFIG_FILE_NAME).unlink(missing_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
@@ -146,6 +154,26 @@ def install_pip_hook(path: Path):
|
|
|
|
|
f.write(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cli_compile_config():
|
|
|
|
|
parser = argparse.ArgumentParser(description="only recompile the config")
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"-v", "--verbose",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="enable verbose and serious output"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"-l", "--local",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="compile the config only for the current virtual environment"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
write_compile_config(args.local)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def mommify_venv():
|
|
|
|
|
parser = argparse.ArgumentParser(description="patch the virtual environment to use mommy")
|
|
|
|
|
|
|
|
|
|
@@ -166,16 +194,7 @@ def mommify_venv():
|
|
|
|
|
config_logging(args.verbose)
|
|
|
|
|
assert_venv()
|
|
|
|
|
|
|
|
|
|
compiled_base_dir = VENV_DIRECTORY if args.local else CONFIG_DIRECTORY
|
|
|
|
|
compiled_config_file = compiled_base_dir / COMPILED_CONFIG_FILE_NAME
|
|
|
|
|
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)
|
|
|
|
|
if not args.local:
|
|
|
|
|
(VENV_DIRECTORY / COMPILED_CONFIG_FILE_NAME).unlink(missing_ok=True)
|
|
|
|
|
write_compile_config(args.local)
|
|
|
|
|
|
|
|
|
|
mommy_logger.info("")
|
|
|
|
|
|
|
|
|
|
|