Skip to content

Commit

Permalink
cleanup + renaming files
Browse files Browse the repository at this point in the history
  • Loading branch information
milachae committed Aug 31, 2023
1 parent 15289a1 commit 9bbdb25
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 161 deletions.
2 changes: 1 addition & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Scripts that can be used to automatically generate markdown files, can be found here.

* [`module_overview`](module_overview): script to generate overview of available environment modules;
* [`available_software`](available_software): script to generate overview of available environment modules;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
@author: Michiel Lachaert (Ghent University)
"""

import time
import json
from pathlib import Path
import numpy as np
import re
import os
import re
import subprocess
from mdutils.mdutils import MdUtils
import time
from pathlib import Path
from typing import Union, Tuple
from module_detail import generate_detail_pages
import numpy as np
from mdutils.mdutils import MdUtils
from natsort import natsorted


# --------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -220,8 +220,93 @@ def get_unique_software_names(data: Union[dict, list, np.ndarray]) -> Union[dict
return simplified_data


def dict_sort(dictionary: dict) -> dict:
"""
Sort a dictionary by key.
@param dictionary: A dictionary
@return: Sorted dictionary
"""
return dict(natsorted(dictionary.items()))


# --------------------------------------------------------------------------------------------------------
# Generate detailed markdown
# --------------------------------------------------------------------------------------------------------

def generate_software_table_data(software_data: dict, clusters: list) -> list:
"""
Construct the data for the detailed software table.
@param software_data: Software specific data.
@param clusters: List with all the cluster names
@return: 1D list with all the data for the table
"""
table_data = [" "] + clusters

for k, v in list(software_data.items())[::-1]:
row = [k]

for cluster in clusters:
row += ("x" if cluster in v else "-")
table_data += row

return table_data


def generate_software_detail_page(
software_name: str,
software_data: dict,
generated_time: str,
clusters: list,
path: str
) -> None:
"""
Generate one software specific detail page.
@param software_name: Name of the software
@param software_data: Additional information about the software (version, etc...)
@param generated_time: Timestamp when the data was generated
@param clusters: List with all the cluster names
@param path: Path of the directory where the detailed page will be created.
"""
filename = f"{path}/{software_name}.md"
md_file = MdUtils(file_name=filename, title=f"detailed overview of {software_name}")

md_file.new_paragraph(f"This data was automatically generated on {generated_time}")
md_file.new_line()

sorted_versions = dict_sort(software_data["versions"])
md_file.new_table(
columns=len(clusters) + 1,
rows=len(sorted_versions) + 1,
text=generate_software_table_data(sorted_versions, clusters)
)

md_file.create_md_file()

# Remove the TOC
with open(filename) as f:
read_data = f.read()
with open(filename, 'w') as f:
f.write("---\nhide:\n - toc\n---\n" + read_data)


def generate_detail_pages(json_path, dest_path) -> None:
"""
Generate all the detailed pages for all the software that is available.
"""

with open(json_path) as json_data:
data = json.load(json_data)

all_clusters = data["clusters"]
for software, content in data["software"].items():
generate_software_detail_page(software, content, data["time_generated"], all_clusters, dest_path)


# --------------------------------------------------------------------------------------------------------
# Generate markdown
# Generate overview markdown
# --------------------------------------------------------------------------------------------------------

def generate_table_data(avail_mods: dict) -> Tuple[np.ndarray, int, int]:
Expand Down Expand Up @@ -376,9 +461,9 @@ def generate_json_detailed_data(modules: dict) -> dict:
# If the software is not yet present, add it.
if software not in json_data["software"]:
json_data["software"][software] = {
"clusters": [],
"versions": {}
}
"clusters": [],
"versions": {}
}

# If the version is not yet present, add it.
if mod not in json_data["software"][software]["versions"]:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from module_overview import modules_ugent, get_unique_software_names
from available_software import modules_ugent, get_unique_software_names


class TestData:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from module_overview import generate_json_overview_data, generate_json_overview, modules_ugent, generate_json_detailed
from available_software import (generate_json_overview_data,
generate_json_overview,
modules_ugent,
generate_json_detailed)
import os
import json

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from mdutils.mdutils import MdUtils
from module_overview import get_unique_software_names, modules_ugent, generate_table_data, generate_module_table
from available_software import get_unique_software_names, modules_ugent, generate_table_data, generate_module_table
import os
import filecmp

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from module_overview import module_avail, filter_fn_gent_modules, filter_fn_gent_cluster, module_swap, module_whatis
from available_software import module_avail, filter_fn_gent_modules, filter_fn_gent_cluster, module_swap, module_whatis


class TestModule:
Expand Down
146 changes: 0 additions & 146 deletions scripts/module_overview/module_detail.py

This file was deleted.

0 comments on commit 9bbdb25

Please sign in to comment.