Skip to content

Commit

Permalink
Replace LaTeX math equations with message to look at API docs, raise …
Browse files Browse the repository at this point in the history
…when type conversion not possible
  • Loading branch information
stellabelin committed Aug 24, 2023
1 parent ed87c01 commit dcdefd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
7 changes: 5 additions & 2 deletions deploy/docs_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def create_r_doc(func):
row = re.sub(r'^\.\. ', '', row)
doc_str += f'{py_to_r_str(row)}\n'

# Replace LaTeX math code
math_pattern = re.compile(r'((:math:)|(math::))\s*`*.+(\\\n)*.+`*')
doc_str = re.sub(math_pattern, '(equation could not be rendered, see API doc on website)', doc_str)

if 'params' in doc_dict.keys():
doc_str += _create_r_params(doc_dict['params'], func)
if 'returns' in doc_dict.keys():
Expand Down Expand Up @@ -102,8 +106,7 @@ def _translate_type_hints(var_type):
if var_type.__module__.startswith('pharmpy'):
return var_type.__name__
elif var_type not in TYPE_DICT:
warnings.warn(f'Could not translate type: {var_type}')
return var_type
raise ValueError(f'Could not translate type: {var_type}')
return TYPE_DICT[var_type]
elif var_type == Any:
return 'any'
Expand Down
12 changes: 1 addition & 11 deletions deploy/help_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,7 @@ def py_to_r_str(arg, example=False):
r'\w+\[Model\]': 'vector of Model', # FIXME: more general pattern
r'\w+\[ModelfitResults\]': 'vector of ModelfitResults'} # FIXME: more general pattern

latex = {r'\\mathsf': '',
r'\\cdot': '*',
r'\\text': '',
r'\\frac': 'frac',
r'\\log': 'log',
r'\\exp': 'exp',
r'\\min': 'min',
r'\\max': 'max',
r'\\epsilon': 'epsilon'}

py_to_r_dict = {**args, **types, **latex}
py_to_r_dict = {**args, **types}

if not example:
py_to_r_dict = {**py_to_r_dict, **{r'\[([0-9]+)\]_*': r'(\1)'}}
Expand Down

0 comments on commit dcdefd0

Please sign in to comment.