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

Ability to explicitly set which arguments will be exposed/visible in the web ui #1876

Closed
fabito opened this issue Sep 6, 2021 · 4 comments · Fixed by #1881
Closed

Ability to explicitly set which arguments will be exposed/visible in the web ui #1876

fabito opened this issue Sep 6, 2021 · 4 comments · Fixed by #1881

Comments

@fabito
Copy link
Contributor

fabito commented Sep 6, 2021

Is your feature request related to a problem? Please describe.

All custom arguments are shown in the web UI

@events.init_command_line_parser.add_listener
def _(parser):
    parser.add_argument("--a1", type=str, env_var="MYAPP_A1", default="a1_value", help="a1 help")
    parser.add_argument("--a2", type=str, env_var="MYAPP_A2", default="a2_value", help="a2 help")
    parser.add_argument("--a3", type=str, env_var="MYAPP_A3", default="a3_value", help="a3 help")
    parser.add_argument("--a4", type=str, env_var="MYAPP_A4", default="a4_value", help="a4 help")
    parser.add_argument("--a5", type=str, env_var="MYAPP_A5", default="a5_value", help="a5 help") 

Screenshot from 2021-09-06 15-18-08

Describe the solution you'd like

Ability to explicitly set which arguments will be exposed/visible in the web ui.

Perhaps a new flag ?

--web_hide_extra_args=a4,a5

Or a new param to add_argument:

@events.init_command_line_parser.add_listener
def _(parser):
    parser.add_argument("--a1", type=str, env_var="MYAPP_A1", default="a1_value", help="a1 help")
    parser.add_argument("--a2", type=str, env_var="MYAPP_A2", default="a2_value", help="a2 help")
    parser.add_argument("--a3", type=str, env_var="MYAPP_A3", default="a3_value", help="a3 help")
    parser.add_argument("--a4", type=str, env_var="MYAPP_A4", default="a4_value", help="a4 help", exclude_from_ui=True)
    parser.add_argument("--a5", type=str, env_var="MYAPP_A5", default="a5_value", help="a5 help", exclude_from_ui=True) 

Describe alternatives you've considered

ATM I am removing the options from CLI and just reading them directly from env variables.

@cyberw
Copy link
Collaborator

cyberw commented Sep 6, 2021

Yes this would be nice. Maybe have a go at implementing it yourself?

@cyberw
Copy link
Collaborator

cyberw commented Sep 6, 2021

(either of your suggested solutions are fine but the second one is nicest, but I’m not sure how to implement it)

@fabito
Copy link
Contributor Author

fabito commented Sep 11, 2021

A bit hacky, but something like this, could work:

import unittest
from typing import List

import configargparse


class LocustArgumentParser(configargparse.ArgumentParser):

    actions_excluded_from_ui: List[configargparse.Action] = []

    def add_argument(self, *args, **kwargs):
        exclude_from_ui = kwargs.pop('exclude_from_ui') if 'exclude_from_ui' in kwargs else None
        action = super().add_argument(*args, **kwargs)
        if exclude_from_ui:
            self.actions_excluded_from_ui.append(action)
        return action


class LocustArgumentParserTests(unittest.TestCase):

    def test_sanity(self):
        parser = LocustArgumentParser()
        parser.add_argument("--a1", type=str, env_var="MYAPP_A1", default="a1_value", help="a1 help")
        parser.add_argument("--a2", type=str, env_var="MYAPP_A2", default="a2_value", help="a2 help")
        parser.add_argument("--a3", type=str, env_var="MYAPP_A3", default="a3_value", help="a3 help")
        parser.add_argument("--a4", type=str, env_var="MYAPP_A4", default="a4_value", help="a4 help",
                            exclude_from_ui=True)
        parser.add_argument("--a5", type=str, env_var="MYAPP_A5", default="a5_value", help="a5 help",
                            exclude_from_ui=True)
        parser.parse_args([])

        self.assertTrue(len(parser.actions_excluded_from_ui) == 2)
        self.assertEqual('a4', parser.actions_excluded_from_ui[0].dest)
        self.assertEqual('a5', parser.actions_excluded_from_ui[1].dest)

One drawback is that the Environment currently references the parsed_options object (

parsed_options = None
).

@cyberw
Copy link
Collaborator

cyberw commented Sep 11, 2021

Looks nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants