Skip to content

Commit

Permalink
Reset
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKora committed Dec 5, 2023
1 parent c2580f7 commit 16f81be
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
16 changes: 11 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
default_language_version:
python: python3.
# default_stages: [pre-commit, manual]
python: 3.11.4
default_stages: [pre-commit, manual]
# default_stages: [commit, manual]
# default_stages: [commit]

repos:
- repo: local
Expand All @@ -10,6 +12,7 @@ repos:
name: Generate doc
entry: python3 generate-doc.py
always_run: true
require_serial: true

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
Expand All @@ -18,17 +21,20 @@ repos:
additional_dependencies:
- mdformat-gfm
- mdformat-black
files: 'docs.*\.md$'
# files: '^(?!README\.md$)docs.*\.md$'
# exclude: '.*README\.md$'
exclude: '.*README\.md$'
always_run: true
require_serial: true
files: '.*\.md$'

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-yaml
always_run: true
require_serial: true
files: 'docs.*\.md$'
- id: trailing-whitespace
files: 'docs.*\.md$'
always_run: true
require_serial: true
files: 'docs.*\.md$'
43 changes: 33 additions & 10 deletions generate-doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ def print_colored(text, color):
print(f"{color}{text}{Colors.RESET}")


def safe_make_dir(directory_path):
if not os.path.isdir(directory_path):
try:
os.makedirs(directory_path)
except FileExistsError:
shutil.rmtree(directory_path)
safe_make_dir(directory_path)
except Exception as e:
print_colored(
f"Error while removing directory '{directory_path}': {e}", Colors.BLUE)


def safe_remove_directory(directory_path):
if os.path.exists(directory_path):
try:
shutil.rmtree(directory_path)
print(f"Directory '{directory_path}' successfully removed.")
except Exception as e:
print(f"Error while removing directory '{directory_path}': {e}")
else:
print(f"Directory '{directory_path}' does not exist.")


def copy_file(source_path, destination_path):
try:
# Copy the file from source_path to destination_path
Expand Down Expand Up @@ -42,9 +65,9 @@ def files_equal(file1_path, file2_path):

def run():
# go through actions
safe_make_dir("tmps")
tmp_action = "tmps/actions"
if not os.path.exists(tmp_action):
os.makedirs(tmp_action)
safe_make_dir(tmp_action)
action_dir = "actions"
changes = []
for action_name in os.listdir(action_dir):
Expand All @@ -61,8 +84,7 @@ def run():
# create docu in tmp dir
tmp_docu_output_dir = os.path.join(
tmp_action, action_name)
if not os.path.exists(tmp_docu_output_dir):
os.makedirs(tmp_docu_output_dir)
safe_make_dir(tmp_docu_output_dir)

tmp_docu_output_action = os.path.join(
tmp_action, action_name, "Variables.md")
Expand All @@ -83,8 +105,7 @@ def run():

# go through workflows
tmp_workflow = "tmps/workflows"
if not os.path.exists(tmp_workflow):
os.makedirs(tmp_workflow)
safe_make_dir(tmp_workflow)

workflow_dir = ".github/workflows"
for workflow in os.listdir(workflow_dir):
Expand All @@ -96,8 +117,7 @@ def run():
# create docu in tmp dir
tmp_workflow_output_dir = os.path.join(
tmp_workflow, workflow_name)
if not os.path.exists(tmp_workflow_output_dir):
os.makedirs(tmp_workflow_output_dir)
safe_make_dir(tmp_workflow_output_dir)

tmp_docu_output_workflow = os.path.join(
tmp_workflow_output_dir, "Variables.md")
Expand Down Expand Up @@ -132,8 +152,7 @@ def run():
outdated_file = entry["existing"]
path_to_doc = outdated_file.split("/Variables.md")[0]
print_colored(path_to_doc, Colors.YELLOW)
if not os.path.exists(path_to_doc):
os.makedirs(path_to_doc)
safe_make_dir(path_to_doc)
new_file = entry["tmp_output"]
copy_file(new_file, outdated_file)

Expand All @@ -144,6 +163,10 @@ def run():
"\nError: The documentation is not up to date. Re running pre-commit may help.", Colors.RED)
os._exit(1)

# remove tmp dir
# if os.path.isdir("tmps"):
# shutil.rmtree("tmps")


if __name__ == "__main__":
run()

0 comments on commit 16f81be

Please sign in to comment.