Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
run: |
brew install llvm libomp
echo "export CC=/usr/local/opt/llvm/bin/clang" >> ~/.bashrc
echo "export CXX=/usr/local/opt/llvm/bin/clang++" >> ~/.bashrc
echo "export CFLAGS=\"$CFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
echo "export CXXFLAGS=\"$CXXFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp\"" >> ~/.bashrc
Expand All @@ -45,6 +46,7 @@ jobs:
run: |
brew install llvm libomp
echo "export CC=/opt/homebrew/opt/llvm/bin/clang" >> ~/.bashrc
echo "export CXX=/opt/homebrew/opt/llvm/bin/clang++" >> ~/.bashrc
echo "export CFLAGS=\"$CFLAGS -I/opt/homebrew/opt/libomp/include\"" >> ~/.bashrc
echo "export CXXFLAGS=\"$CXXFLAGS -I/opt/homebrew/opt/libomp/include\"" >> ~/.bashrc
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/opt/homebrew/opt/libomp/lib -L/opt/homebrew/opt/libomp/lib -lomp\"" >> ~/.bashrc
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
run: |
brew install llvm libomp
echo "export CC=/usr/local/opt/llvm/bin/clang" >> ~/.bashrc
echo "export CXX=/usr/local/opt/llvm/bin/clang++" >> ~/.bashrc
echo "export CFLAGS=\"$CFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
echo "export CXXFLAGS=\"$CXXFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp\"" >> ~/.bashrc
Expand Down
23 changes: 16 additions & 7 deletions RATapi/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time

from tqdm import tqdm
from tqdm.auto import tqdm

import RATapi.rat_core
from RATapi.inputs import make_input
Expand All @@ -16,18 +16,23 @@ class ProgressBar:
----------
display : bool, default: True
Indicates if displaying is allowed

"""

def __init__(self, display=True):
self.pbar = None
self.display = display
self.tqdm_kwargs = {"total": 100, "desc": "", "bar_format": "{l_bar}{bar}", "disable": not self.display}
# Determine if the auto tqdm is standard or notebook
from tqdm.asyncio import tqdm as asyncio_tqdm

if tqdm == asyncio_tqdm:
self.tqdm_kwargs.update({"ncols": 90})

def __enter__(self):
if self.display:
RATapi.events.register(RATapi.events.EventTypes.Progress, self.updateProgress)
self.pbar = tqdm(total=100, desc="", delay=1, bar_format="{l_bar}{bar}", ncols=90, disable=not self.display)
self.pbar.delay = 0
return self.pbar

return self

def updateProgress(self, event):
"""Callback for the progress event.
Expand All @@ -37,13 +42,17 @@ def updateProgress(self, event):
event: ProgressEventData
The progress event data.
"""

if self.pbar is None:
self.pbar = tqdm(**self.tqdm_kwargs)
value = event.percent * 100
self.pbar.desc = event.message
self.pbar.update(value - self.pbar.n)

def __exit__(self, _exc_type, _exc_val, _traceback):
self.pbar.leave = False
if self.pbar is not None:
self.pbar.close()
print("") # Print new line after bar

if self.display:
RATapi.events.clear(RATapi.events.EventTypes.Progress, self.updateProgress)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def build_libraries(self, libraries):
':python_version < "3.11"': ["StrEnum >= 0.4.15"],
"Dev": ["pytest>=7.4.0", "pytest-cov>=4.1.0", "ruff>=0.4.10"],
"Matlab_latest": ["matlabengine"],
"Matlab_2023b": ["matlabengine == 23.2.1"],
"Matlab_2023b": ["matlabengine == 23.2.3"],
"Matlab_2023a": ["matlabengine == 9.14.3"],
"Matlab_2022b": ["matlabengine == 9.13.9"],
"Matlab_2022a": ["matlabengine == 9.12.19"],
Expand Down
10 changes: 5 additions & 5 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ def test_progress_bar() -> None:
event.message = "TESTING"
event.percent = 0.2
with ProgressBar() as bar:
assert bar.n == 0
assert bar.pbar is None
notify(EventTypes.Progress, event)
assert bar.desc == "TESTING"
assert bar.n == 20
assert bar.pbar.desc == "TESTING"
assert bar.pbar.n == 20

event.message = "AGAIN"
event.percent = 0.6
notify(EventTypes.Progress, event)
assert bar.desc == "AGAIN"
assert bar.n == 60
assert bar.pbar.desc == "AGAIN"
assert bar.pbar.n == 60