Skip to content

Commit

Permalink
feat(convert): try-except conversion (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Caceresenzo authored Nov 28, 2024
1 parent 532b640 commit fe104fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
22 changes: 13 additions & 9 deletions crunch/command/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import click

from .. import constants
from ..convert import extract_cells
from ..convert import ConverterError, extract_cells


def convert_cells_to_file(
Expand Down Expand Up @@ -40,11 +40,15 @@ def convert(
python_file_path: str,
override: bool = False,
):
with open(notebook_file_path) as fd:
notebook = json.load(fd)

convert_cells_to_file(
notebook.get("cells", []),
python_file_path,
override
)
try:
with open(notebook_file_path) as fd:
notebook = json.load(fd)

convert_cells_to_file(
notebook.get("cells", []),
python_file_path,
override
)
except ConverterError as error:
print(f"convert failed: {error}")
raise click.Abort()
10 changes: 7 additions & 3 deletions crunch/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def strip_packages(name: str):
return name[:index]


class NotebookCellParseError(ValueError):
class ConverterError(ValueError):
pass


class NotebookCellParseError(ConverterError):

def __init__(
self,
Expand All @@ -59,13 +63,13 @@ def __init__(
self.cell_source = cell_source


class RequirementVersionParseError(ValueError):
class RequirementVersionParseError(ConverterError):

def __init__(self, message) -> None:
super().__init__(message)


class InconsistantLibraryVersionError(ValueError):
class InconsistantLibraryVersionError(ConverterError):

def __init__(
self,
Expand Down

0 comments on commit fe104fc

Please sign in to comment.