added option for local compile

This commit is contained in:
Hazel Noack 2025-07-29 12:22:41 +02:00
parent 94c585fa7a
commit 3213e8a21f

View File

@ -152,25 +152,30 @@ def mommify_venv():
parser.add_argument( parser.add_argument(
"-v", "--verbose", "-v", "--verbose",
action="store_true", action="store_true",
help="enable verbose output" 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() args = parser.parse_args()
config_logging(args.verbose) config_logging(args.verbose)
assert_venv() assert_venv()
compile_local = False compiled_base_dir = VENV_DIRECTORY if args.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
compiled = compile_config() compiled = compile_config()
mommy_logger.info("mommy writes its moods in %s", compiled_config_file) mommy_logger.info("mommy writes its moods in %s", compiled_config_file)
serious_logger.info("writing compiled config file to %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) compiled_base_dir.mkdir(parents=True, exist_ok=True)
with compiled_config_file.open("w") as f: with compiled_config_file.open("w") as f:
json.dump(compiled, f, indent=4) json.dump(compiled, f, indent=4)
if not args.local:
(VENV_DIRECTORY / COMPILED_CONFIG_FILE_NAME).unlink(missing_ok=True)
mommy_logger.info("") mommy_logger.info("")