Skip to content

Fix EasyConfig.update code to handle both strings and lists as input.#3170

Merged
boegel merged 7 commits intoeasybuilders:developfrom
akesandgren:correct-easyconfig-update-code
Feb 10, 2020
Merged

Fix EasyConfig.update code to handle both strings and lists as input.#3170
boegel merged 7 commits intoeasybuilders:developfrom
akesandgren:correct-easyconfig-update-code

Conversation

@akesandgren
Copy link
Copy Markdown
Contributor

Correctly handle allow_duplicate=False when "value" is a partial match
for an item in key when key is a string.

Correctly handle allow_duplicate=False when "value" is a partial match
for an item in key when key is a string.
@akesandgren akesandgren added this to the 4.x milestone Jan 22, 2020
Comment thread easybuild/framework/easyconfig/easyconfig.py Outdated
Comment thread easybuild/framework/easyconfig/easyconfig.py Outdated
Comment thread easybuild/framework/easyconfig/easyconfig.py Outdated
Comment thread easybuild/framework/easyconfig/easyconfig.py Outdated
Comment thread easybuild/framework/easyconfig/easyconfig.py Outdated
Comment thread easybuild/framework/easyconfig/easyconfig.py Outdated
Comment thread easybuild/framework/easyconfig/easyconfig.py Outdated
@akesandgren
Copy link
Copy Markdown
Contributor Author

akesandgren commented Jan 25, 2020

This fixes the build problem for VMD described in easybuilders/easybuild-easyblocks#1755

@easybuilders easybuilders deleted a comment from boegelbot Feb 10, 2020
msg += "attempted update value, '%s', is not a string or list."
raise EasyBuildError(msg, key, value)

prev_value = self[key]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prev_value should be renamed now that we're updating it in place?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any suggestions? new_value?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param_value?

self[key] = prev_value + [item]
for item in lval:
if allow_duplicate or item not in prev_value:
prev_value.append(item)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to be careful here... prev_value is a reference to the original value, .append will append to the original value, whereas before we were creating a new value using prev_value + [item]. That was not by accident probably...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, can never remember the reference thingie...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it doesn't really matter, we could use self[key] directly, since the checks should be performed on the whole string/list each time.

I.e. get rid of prev_value altogether.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were not changing the existing value in self[key] inline, but we were constructing a new value and assigning self[key] to that value. You should keep that behavior, or we may run into surprises.

Fictic example in an easyblock:

alist = ['--foo']
self.cfg['configopts'] = alist
self.cfg.update('configopts', '--bar')
for x in alist:
    ...

The contents of alist should not change (self.cfg.update should not have side effects)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, those pescy references...

if allow_duplicate or value not in prev_value:
self[key] = '%s %s ' % (prev_value, value)
for item in lval:
if allow_duplicate or (not re.search(r'(^|\s+)%s(\s+|$)' % re.escape(item), prev_value)):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the re.search deserves a clarifying comment above? Something like:

"# only add value to string if it's not there yet (surrounded by whitespace)

Rename temp variable to better match usage.
Copy link
Copy Markdown
Member

@boegel boegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@boegel boegel merged commit eef8487 into easybuilders:develop Feb 10, 2020
@boegel boegel modified the milestones: 4.x, next release (4.1.2?) Feb 10, 2020
@akesandgren akesandgren deleted the correct-easyconfig-update-code branch February 10, 2020 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants