Skip to content

Commit 4ed16be

Browse files
committed
Use defaultdict with sets for added_paths_per_key
Simplifies code when using it in easyblocks
1 parent a1e4ecc commit 4ed16be

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

easybuild/tools/module_generator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import os
4040
import re
4141
import tempfile
42+
from collections import defaultdict
4243
from contextlib import contextmanager
4344
from easybuild.tools import LooseVersion
4445
from textwrap import wrap
@@ -153,7 +154,7 @@ def start_module_creation(self):
153154
raise EasyBuildError('Module creation already in process. '
154155
'You cannot create multiple modules at the same time!')
155156
# Mapping of keys/env vars to paths already added
156-
self.added_paths_per_key = dict()
157+
self.added_paths_per_key = defaultdict(set)
157158
txt = self.MODULE_SHEBANG
158159
if txt:
159160
txt += '\n'
@@ -212,7 +213,7 @@ def _filter_paths(self, key, paths):
212213
print_warning('Module creation has not been started. Call start_module_creation first!')
213214
return paths
214215

215-
added_paths = self.added_paths_per_key.setdefault(key, set())
216+
added_paths = self.added_paths_per_key[key]
216217
# paths can be a string
217218
if isinstance(paths, str):
218219
if paths in added_paths:

0 commit comments

Comments
 (0)