Skip to content

Commit

Permalink
dumping model on request
Browse files Browse the repository at this point in the history
  • Loading branch information
mesemus committed Sep 2, 2022
1 parent a61c0df commit 1e8e731
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions oarepo_model_builder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path

import click
import yaml

from oarepo_model_builder.conflict_resolvers import AutomaticResolver, InteractiveResolver
from oarepo_model_builder.entrypoints import create_builder_from_entrypoints, load_model
Expand Down Expand Up @@ -35,6 +36,11 @@
help="Increase the verbosity. This option can be used multiple times.",
count=True,
)
@click.option(
"--save-model",
"save_model",
help="Save resolved model into this file.",
)
@click.option(
"--config",
"configs",
Expand All @@ -49,13 +55,15 @@
@click.option("--black/--skip-black", default=True, help="Call black on generated sources")
@click.option("--resolve-conflicts", type=click.Choice(["replace", "keep", "comment", "debug"]))
@click.argument("model_filename")
def run(output_directory, package, sets, configs, model_filename, verbosity, isort, black, resolve_conflicts):
def run(output_directory, package, sets, configs, model_filename,
verbosity, isort, black, resolve_conflicts, save_model):
"""
Compiles an oarepo model file given in MODEL_FILENAME into an Invenio repository model.
"""
try:
run_internal(
output_directory, model_filename, package, configs, resolve_conflicts, sets, black, isort, verbosity
output_directory, model_filename, package, configs, resolve_conflicts,
sets, black, isort, verbosity, save_model
)
except Exception as e:
if verbosity >= 2:
Expand All @@ -69,7 +77,8 @@ def run(output_directory, package, sets, configs, model_filename, verbosity, iso
sys.exit(1)


def run_internal(output_directory, model_filename, package, configs, resolve_conflicts, sets, black, isort, verbosity):
def run_internal(output_directory, model_filename, package, configs,
resolve_conflicts, sets, black, isort, verbosity, save_model):
# extend system's search path to add script's path in front (so that scripts called from the compiler are taken
# from the correct virtual environ)
os.environ["PATH"] = str(Path(sys.argv[0]).parent.absolute()) + os.pathsep + os.environ.get("PATH", "")
Expand All @@ -91,6 +100,9 @@ def run_internal(output_directory, model_filename, package, configs, resolve_con
output_directory,
)
model = load_model(model_filename, package, configs, black, isort, sets)
if save_model:
with open(save_model, 'w') as f:
yaml.dump(model.schema, f)
model.schema["output-directory"] = output_directory
if not resolve_conflicts or resolve_conflicts == "debug":
resolver = InteractiveResolver(resolve_conflicts == "debug")
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-model-builder
version = 1.0.0.dev15
version = 1.0.0.dev16
description = An utility library that generates OARepo required data model files from a JSON specification file
authors = Miroslav Bauer <[email protected]>, Miroslav Simek <[email protected]>
readme = README.md
Expand Down

0 comments on commit 1e8e731

Please sign in to comment.