Skip to content

Commit

Permalink
Merge pull request #129 from ara-25/main
Browse files Browse the repository at this point in the history
Use rich for displaying error traceback in mlinfra cli
  • Loading branch information
aliabbasjaffri authored Oct 28, 2024
2 parents 39b8d01 + 70fb171 commit 25f3e98
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ dependencies = [
"GitPython",
"mypy",
"getmac",
"requests"
"requests",
"rich"
]

[tool.setuptools]
Expand Down
8 changes: 8 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jmespath==1.0.1
# via
# boto3
# botocore
markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
mypy==1.12.0
# via mlinfra (pyproject.toml)
mypy-extensions==1.0.0
Expand All @@ -48,6 +52,8 @@ pluggy==1.5.0
# via pytest
pre-commit==3.7.1
# via mlinfra (pyproject.toml)
pygments==2.18.0
# via rich
pytest==8.2.2
# via
# mlinfra (pyproject.toml)
Expand All @@ -62,6 +68,8 @@ pyyaml==6.0.2
# pre-commit
requests==2.32.3
# via mlinfra (pyproject.toml)
rich==13.9.3
# via mlinfra (pyproject.toml)
s3transfer==0.10.3
# via boto3
six==1.16.0
Expand Down
10 changes: 9 additions & 1 deletion requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ markdown==3.6
# mkdocs
# mkdocs-material
# pymdown-extensions
markdown-it-py==3.0.0
# via rich
markupsafe==2.1.5
# via
# jinja2
# mkdocs
mdurl==0.1.2
# via markdown-it-py
mergedeep==1.3.4
# via
# mkdocs
Expand Down Expand Up @@ -89,7 +93,9 @@ pathspec==0.12.1
platformdirs==4.3.6
# via mkdocs-get-deps
pygments==2.18.0
# via mkdocs-material
# via
# mkdocs-material
# rich
pymdown-extensions==10.8.1
# via mkdocs-material
pyparsing==3.2.0
Expand Down Expand Up @@ -118,6 +124,8 @@ requests==2.32.3
# via
# mlinfra (pyproject.toml)
# mkdocs-material
rich==13.9.3
# via mlinfra (pyproject.toml)
s3transfer==0.10.3
# via boto3
six==1.16.0
Expand Down
6 changes: 6 additions & 0 deletions src/mlinfra/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing
# permissions and limitations under the License.

from mlinfra.utils.constants import ENABLE_RICH_TRACEBACK
from mlinfra.utils.utils import setup_rich_traceback

if ENABLE_RICH_TRACEBACK:
setup_rich_traceback()
2 changes: 2 additions & 0 deletions src/mlinfra/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@
VERSION: Final = version("mlinfra")

EXECUTABLE_PATH = "/usr/local/bin"

ENABLE_RICH_TRACEBACK = True
10 changes: 10 additions & 0 deletions src/mlinfra/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import sys
from typing import List

import invoke
from rich.traceback import install as rich_tr_install

from .constants import TF_PATH


Expand Down Expand Up @@ -186,3 +189,10 @@ def func_wrapper(*args, **kwargs): # type: ignore
return None

return func_wrapper


def setup_rich_traceback(debug_mode: bool = False):
if debug_mode:
rich_tr_install(show_locals=True)
else:
rich_tr_install(show_locals=False, suppress=[invoke, subprocess])

0 comments on commit 25f3e98

Please sign in to comment.