Skip to content

Commit

Permalink
Remove default value for defaults (#289)
Browse files Browse the repository at this point in the history
This is a dangerous practice becuse the default values could be mutated. And it should always be passed in.
Supercedes #286
  • Loading branch information
tfoote authored Sep 20, 2024
1 parent b76c363 commit 3f02bdc
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/rocker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def check_args_for_activation(cls, cli_args):
return True if cli_args.get(cls.get_name()) else False

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
raise NotImplementedError


Expand Down
24 changes: 12 additions & 12 deletions src/rocker/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_docker_args(self, cliargs):
return args

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument('--devices',
default=defaults.get('devices', None),
nargs='*',
Expand Down Expand Up @@ -84,7 +84,7 @@ def get_snippet(self, cliargs):
return empy_expand(snippet, self.get_environment_subs())

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(name_to_argument(DevHelpers.get_name()),
action='store_true',
default=defaults.get('dev_helpers', None),
Expand Down Expand Up @@ -136,7 +136,7 @@ def get_docker_args(self, cliargs):
return args

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument('--hostname', default=defaults.get('hostname', ''),
help='Hostname of the container.')

Expand Down Expand Up @@ -182,7 +182,7 @@ def get_docker_args(self, cliargs):
return args

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument('--name', default=defaults.get('name', ''),
help='Name of the container.')

Expand All @@ -205,7 +205,7 @@ def get_docker_args(self, cliargs):
return args

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
client = get_docker_client()
parser.add_argument('--network', choices=[n['Name'] for n in client.networks()],
default=defaults.get('network', None),
Expand All @@ -231,7 +231,7 @@ def get_docker_args(self, cliargs):
return ' '.join(args)

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument('--port',
default=defaults.get('port', None),
action='append',
Expand Down Expand Up @@ -269,7 +269,7 @@ def get_docker_args(self, cliargs):
return args % self.get_environment_subs()

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(name_to_argument(PulseAudio.get_name()),
action='store_true',
default=defaults.get(PulseAudio.get_name(), None),
Expand All @@ -288,7 +288,7 @@ def get_docker_args(self, cliargs):
return ' -v %s:%s ' % (Path.home(), Path.home())

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(name_to_argument(HomeDir.get_name()),
action='store_true',
default=defaults.get(HomeDir.get_name(), None),
Expand Down Expand Up @@ -344,7 +344,7 @@ def get_snippet(self, cliargs):
return empy_expand(snippet, substitutions)

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(name_to_argument(User.get_name()),
action='store_true',
default=defaults.get('user', None),
Expand Down Expand Up @@ -400,7 +400,7 @@ def get_docker_args(self, cli_args):
return ' '.join(args)

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument('--env', '-e',
metavar='NAME[=VALUE]',
type=str,
Expand Down Expand Up @@ -436,7 +436,7 @@ def get_docker_args(self, cli_args):
return ' --privileged'

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(name_to_argument(Privileged.get_name()),
action='store_true',
default=defaults.get(Privileged.get_name(), None),
Expand All @@ -463,7 +463,7 @@ def get_docker_args(self, cliargs):
return ' '.join(args)

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(name_to_argument(GroupAdd.get_name()),
default=defaults.get(GroupAdd.get_name(), None),
action='append',
Expand Down
2 changes: 1 addition & 1 deletion src/rocker/git_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_docker_args(self, cli_args):
return args

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument('--git',
action='store_true',
default=defaults.get(Git.get_name(), None),
Expand Down
6 changes: 3 additions & 3 deletions src/rocker/nvidia_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def precondition_environment(self, cliargs):
raise ex

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(name_to_argument(X11.get_name()),
action='store_true',
default=defaults.get(X11.get_name(), None),
Expand Down Expand Up @@ -161,7 +161,7 @@ def get_docker_args(self, cliargs):
return " --runtime=nvidia"

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(name_to_argument(Nvidia.get_name()),
choices=['auto', 'runtime', 'gpus'],
nargs='?',
Expand Down Expand Up @@ -231,7 +231,7 @@ def get_docker_args(self, cliargs):
# Runtime requires --nvidia option too

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(name_to_argument(Cuda.get_name()),
action='store_true',
default=defaults.get('cuda', None),
Expand Down
2 changes: 1 addition & 1 deletion src/rocker/rmw_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_snippet(self, cliargs):
return empy_expand(snippet, data)

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(name_to_argument(RMW.get_name()),
default=defaults.get('rmw', None),
nargs=1,
Expand Down
2 changes: 1 addition & 1 deletion src/rocker/ssh_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_docker_args(self, cli_args):
return args

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument('--ssh',
action='store_true',
default=defaults.get(Ssh.get_name(), None),
Expand Down
2 changes: 1 addition & 1 deletion src/rocker/volume_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_docker_args(self, cli_args):
return ' '.join(args)

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument(Volume.ARG_ROCKER_VOLUME,
metavar='HOST-DIR[:CONTAINER-DIR[:OPTIONS]]',
type=str,
Expand Down
2 changes: 1 addition & 1 deletion test/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def plugin_load_parser_correctly(plugin):
"""A helper function to test that the plugins at least
register an option for their own name."""
parser = argparse.ArgumentParser(description='test_parser')
plugin.register_arguments(parser)
plugin.register_arguments(parser, {})
argument_name = name_to_argument(plugin.get_name())
for action in parser._actions:
option_strings = getattr(action, 'option_strings', [])
Expand Down
2 changes: 1 addition & 1 deletion test/test_file_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_files(self, cliargs):


@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument('--test-file-injection',
action='store_true',
default=defaults.get('test_file_injection', False),
Expand Down

0 comments on commit 3f02bdc

Please sign in to comment.