Skip to content

Commit

Permalink
Remove default value for defaults
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 committed Sep 20, 2024
1 parent 9e26fee commit 5074e9c
Show file tree
Hide file tree
Showing 8 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
26 changes: 13 additions & 13 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 All @@ -110,7 +110,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 All @@ -133,7 +133,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 @@ -156,7 +156,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 @@ -182,7 +182,7 @@ def get_docker_args(self, cliargs):
return ' '.join(args)

@staticmethod
def register_arguments(parser, defaults={}):
def register_arguments(parser, defaults):
parser.add_argument('--expose',
default=defaults.get('expose', None),
action='append',
Expand All @@ -208,7 +208,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 @@ -246,7 +246,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 @@ -265,7 +265,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 @@ -321,7 +321,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 @@ -377,7 +377,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 @@ -413,7 +413,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 @@ -440,7 +440,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 @@ -71,7 +71,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 @@ -134,7 +134,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 @@ -196,7 +196,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_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 5074e9c

Please sign in to comment.