From 49683aeb07e87d03646a4f1d21cca9c6a78c01d0 Mon Sep 17 00:00:00 2001 From: Stella Date: Fri, 18 Oct 2024 16:53:55 +0200 Subject: [PATCH] Replace leading underscores in argument names with . --- deploy/docs_conversion.py | 3 ++- deploy/func_conversion.py | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/deploy/docs_conversion.py b/deploy/docs_conversion.py index 6cec2a2..bffdfdd 100644 --- a/deploy/docs_conversion.py +++ b/deploy/docs_conversion.py @@ -84,7 +84,8 @@ def _create_r_params(doc_list, func): r_params += f'@param ... {desc_dict[key]}' unbound_added = True else: - r_params += f'@param {key} ({value}) {desc_dict[key]}' + param_name = re.sub(r'^_', '.', key) + r_params += f'@param {param_name} ({value}) {desc_dict[key]}' return r_params + ' \n' diff --git a/deploy/func_conversion.py b/deploy/func_conversion.py index d68b154..b69961d 100644 --- a/deploy/func_conversion.py +++ b/deploy/func_conversion.py @@ -29,7 +29,7 @@ def create_r_func(func, module): func_def = f'{func_name} <- function({wrapper_arg_str})' func_execute = f'func_out <- pharmpy${module_name}${func_name}({pyfunc_arg_str})' - if module_name == 'tools' and func_name.startswith("run_"): + if module_name == 'tools': r_func_body = _create_func_body_tool(func, func_execute) else: r_func_body = _create_func_body_modeling(func, func_execute) @@ -45,14 +45,15 @@ def create_r_func(func, module): def _get_args(params): wrapper_args, pyfunc_args = [], [] for param in params.values(): + param_name = re.sub(r'^_', '.', param.name) if param.kind == param.VAR_KEYWORD or param.kind == param.VAR_POSITIONAL: if '...' not in wrapper_args: wrapper_args.append('...'), pyfunc_args.append('...') elif param.default is param.empty: - wrapper_args.append(f'{param.name}'), pyfunc_args.append(f'{param.name}') + wrapper_args.append(f'{param_name}'), pyfunc_args.append(f'{param_name}') else: - wrapper_args.append(f'{param.name}={py_to_r_arg(param.default)}') - pyfunc_args.append(f'{param.name}={param.name}') + wrapper_args.append(f'{param_name}={py_to_r_arg(param.default)}') + pyfunc_args.append(f'{param_name}={param_name}') return ', '.join(wrapper_args), ', '.join(pyfunc_args)