Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide ability to parse Python parameters included '=' character in value or comment #813

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions papermill/tests/notebooks/complex_parameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
"# Interesting c variable\n",
"c: \"NoneType\" = None\n",
"# Not introspectable line\n",
"d = a == 3\n",
"# Broken name definition\n",
"= 2"
"d = \"a = 3\"\n",
"# str value with equal character\n",
"e = 1 # comment with '=' character\n",
"f = (a != 3 and 2 <= a <= 3) or a == 1\n",
"# bool value with logical operators\n",
"= 2\n",
"# Broken name definition\n"
]
}
],
Expand Down
16 changes: 16 additions & 0 deletions papermill/tests/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ def click_context():
"help": "Nice list",
},
"c": {"name": "c", "inferred_type_name": "NoneType", "default": "None", "help": ""},
"d": {"name": "d", "inferred_type_name": "None", "default": "\"a = 3\"", "help": ""},
"e": {
"name": "e",
"inferred_type_name": "None",
"default": "1",
"help": "comment with '=' character",
},
"f": {
"name": "f",
"inferred_type_name": "None",
"default": "(a != 3 and 2 <= a <= 3) or a == 1",
"help": "",
},
},
),
(_get_fullpath("notimplemented_translator.ipynb"), {}),
Expand Down Expand Up @@ -87,6 +100,9 @@ def test_str_path():
" a: float (default 2.25) Variable a",
" b: List[str] (default ['Hello','World'])\n Nice list",
" c: NoneType (default None) ",
" d: Unknown type (default \"a = 3\")",
" e: Unknown type (default 1) comment with '=' character",
" f: Unknown type (default (a != 3 and 2 <= a <= 3) or a == 1)",
],
),
(
Expand Down
3 changes: 0 additions & 3 deletions papermill/translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@ def flatten_accumulator(accumulator):
if nequal > 0:
grouped_variable.append(flatten_accumulator(accumulator))
accumulator = []
if nequal > 1:
logger.warning(f"Unable to parse line {iline + 1} '{line}'.")
continue

accumulator.append(line)
grouped_variable.append(flatten_accumulator(accumulator))
Expand Down