Skip to content

Commit 4895356

Browse files
authored
Maintainance PR (#527)
* feat: fixed the pydata-sphinx-theme version dependency * ix: language render and annotations * feat: added design updates to fix the UI * fix: multi lingual support * maintainance PR * cache builds to reduce build time * cache builds to reduce build time * fix cleanPR
1 parent 7cedeb3 commit 4895356

File tree

4 files changed

+57
-34
lines changed

4 files changed

+57
-34
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
python-version: "3.10"
3131

3232
- name: Setup Fortran compiler
33-
uses: fortran-lang/[email protected].1
33+
uses: fortran-lang/[email protected].3
3434
id: setup-fortran
3535
with:
3636
compiler: gcc

.github/workflows/closePR.yml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,27 @@ jobs:
2222
- name: Iterate and Check PRs
2323
id: pr_check
2424
run: |
25-
pr_folders=($(cd pr && ls -d */))
25+
# Get the list of PR folders inside 'pr/' (e.g., pr/123, pr/456)
26+
pr_folders=($(find pr -mindepth 1 -maxdepth 1 -type d -printf "%f\n"))
2627
closed_pr=()
28+
2729
for pr_folder in "${pr_folders[@]}"; do
28-
pr_status=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
29-
-X GET "https://api.github.com/repos/${{ github.repository }}/pulls/${pr_folder::-1}" \
30-
| jq -r '.state')
31-
echo "PR ${pr_folder::-1} is $pr_status"
32-
if [ "$pr_status" != "open" ]; then
33-
rm -rf "pr/${pr_folder::-1}"
34-
closed_pr+=("${pr_folder::-1}")
35-
echo "Removed folder pr/${pr_folder::-1} for closed PR ${pr_folder::-1}"
36-
fi
30+
# Fetch PR status from GitHub API
31+
pr_status=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
32+
-X GET "https://api.github.com/repos/${{ github.repository }}/pulls/$pr_folder" | jq -r '.state')
33+
34+
echo "PR $pr_folder is $pr_status"
35+
36+
# Remove the folder if PR is closed
37+
if [[ "$pr_status" != "open" ]]; then
38+
rm -rf "pr/$pr_folder"
39+
closed_pr+=("$pr_folder")
40+
echo "Removed folder pr/$pr_folder for closed PR $pr_folder"
41+
fi
3742
done
38-
echo "${closed_pr[*]}" >> $GITHUB_STATE
43+
44+
# Store closed PRs in GITHUB_STATE for later use
45+
echo "${closed_pr[*]}" >> "$GITHUB_STATE"
3946
4047
- name: Commit and push to gh-pages
4148
uses: EndBug/[email protected]

extensions/fortran_playground.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,54 @@
33
from sphinx.util._lines import parse_line_num_spec
44
from docutils import nodes
55
import subprocess
6+
import hashlib
7+
import os
68

79

810
comp_error = ["<ERROR>","Error","app/main.f90","<h1>Bad Request</h1>"]
911

1012

1113
class PlayCodeBlock(CodeBlock):
1214

13-
def compile_and_execute_fortran(self,fortran_code, filename="code.f90"):
15+
def compile_and_execute_fortran(self,fortran_code):
16+
code_hash = hashlib.md5(fortran_code.encode('utf-8')).hexdigest()
17+
cache_filename = f"build/fortran_output_{code_hash}.txt"
18+
filename=f"build/code_{code_hash}.f90"
19+
20+
# Check if the output is already cached
21+
if os.path.exists(cache_filename):
22+
with open(cache_filename, "r") as f:
23+
return f.read()
24+
1425
with open(filename, "w") as f:
1526
f.write(fortran_code)
1627

17-
compile_command = ["gfortran", filename]
28+
compile_command = ["gfortran", filename, "-o", f"./build/{code_hash}.out"]
1829
compile_result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
1930

20-
if compile_result.returncode == 0:
21-
print("Compilation successful!")
31+
with open(cache_filename, "w") as f:
2232

23-
execute_command = ["./a.out"]
24-
execute_result = subprocess.run(execute_command, input="", stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
25-
26-
if execute_result.returncode == 0:
27-
print("Execution successful!")
28-
print(execute_result.stdout)
29-
return execute_result.stdout
33+
if compile_result.returncode == 0:
34+
print("Compilation successful!")
35+
36+
execute_command = [f"./build/{code_hash}.out"]
37+
execute_result = subprocess.run(execute_command, input="", stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
38+
39+
if execute_result.returncode == 0:
40+
print("Execution successful!")
41+
print(execute_result.stdout)
42+
f.write(str(execute_result.stdout))
43+
return execute_result.stdout
44+
else:
45+
print("Execution failed.")
46+
print(execute_result.stderr)
47+
f.write(str(execute_result.stderr))
48+
return execute_result.stderr
3049
else:
31-
print("Execution failed.")
32-
print(execute_result.stderr)
33-
return execute_result.stderr
34-
else:
35-
print("Compilation failed.")
36-
print(compile_result.stderr)
37-
return compile_result.stderr
50+
print("Compilation failed.")
51+
print(compile_result.stderr)
52+
f.write(str(compile_result.stderr))
53+
return compile_result.stderr
3854

3955
def run(self):
4056
document = self.state.document

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Sphinx==8.1.3
2-
ablog==0.11.11
2+
ablog==0.11.12
33
pydata-sphinx-theme==0.16.1
44
myst-parser==4.0.0
55
sphinx_design==0.6.1
66
sphinx_copybutton==0.5.2
77
sphinx-jinja==2.0.2
8-
jinja2==3.1.4
8+
jinja2==3.1.5
99
requests==2.32.3
10-
black==24.10.0
10+
black==25.1.0
1111
pylint==3.3.4
12-
pre-commit==4.0.1
12+
pre-commit==4.1.0
1313
sphinx-sitemap==2.6.0
1414
sphinx-favicon==1.0.1

0 commit comments

Comments
 (0)