Skip to content

Commit

Permalink
Remove type annotations and add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusreaiche committed Oct 3, 2024
1 parent 1745658 commit 29ab059
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions pulp/tests/utilities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re


def read_command_line_from_log_file(logPath: str) -> str:
def read_command_line_from_log_file(logPath):
"""
Read from log file the command line executed.
"""
Expand All @@ -13,8 +13,28 @@ def read_command_line_from_log_file(logPath: str) -> str:


def extract_option_from_command_line(
command_line: str, option: str, prefix: str = "-", grp_pattern: str = "[a-zA-Z]+"
) -> str:
command_line, option, prefix="-", grp_pattern="[a-zA-Z]+"
):
"""
Extract option value from command line string.
:param command_line: str that we extract the option value from
:param option: str representing the option name (e.g., presolve, sec, etc)
:param prefix: str (default: '-')
:param grp_pattern: str (default: '[a-zA-Z]+') - regex to capture option value
:return: option value captured (str); otherwise, None
example:
>>> cmd = "cbc model.mps -presolve off -timeMode elapsed -branch"
>>> extract_option_from_command_line(cmd, "presolve")
'off'
>>> cmd = "cbc model.mps -strong 101 -timeMode elapsed -branch"
>>> extract_option_from_command_line(cmd, "strong", grp_pattern="\d+")
'101'
"""
pattern = re.compile(rf"{prefix}{option}\s+({grp_pattern})\s*")
m = pattern.search(command_line)
if not m:
Expand Down

0 comments on commit 29ab059

Please sign in to comment.