From e623b960a68c69978d7cb8e9e6759a239dc0f4f0 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Wed, 23 Nov 2022 13:07:21 +0100 Subject: [PATCH] Embedded python model --- createreadmes.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/createreadmes.py b/createreadmes.py index 04fddb2..05fcf55 100644 --- a/createreadmes.py +++ b/createreadmes.py @@ -370,9 +370,13 @@ def write_model_readmes(dataset: Dataset): info['forks'] = forks info['owner_name'] = owner_name info['owner_slug'] = owner_slug - security_rules_file = dataset_path / model_id / 'security_rules.yaml' + model_path = dataset_path / model_id + security_rules_file = model_path / 'security_rules.yaml' + model_file = model_path / f"{model_id}.py" + with model_file.open("r") as f: + model = f.read() try: - with open(security_rules_file, 'r') as f: + with security_rules_file.open('r') as f: security_rules = yaml.safe_load(f) security_rules = check_security_rules(security_rules) except FileNotFoundError: @@ -383,7 +387,7 @@ def write_model_readmes(dataset: Dataset): security_rules = {} print(f"Writing readme file {readme}") dir.mkdir(exist_ok=True) - with open(readme, 'w', encoding="utf-8") as f: + with readme.open('w', encoding="utf-8") as f: f.write(f"""--- title: {slug} keywords: model TODO @@ -411,6 +415,10 @@ The repository has {plural(stars, 'star')} and was forked {plural(forks, 'time') The images below were generated by executing the model file. The DFD is represented as a CodeableModels file. +```python +{model} +``` + ### Statistics The Application consists of a total of {plural(info['t'], 'element')}: