Skip to content

Allow --force to use regex if --try-toolchain cannot map intelligently.#2605

Merged
ocaisa merged 5 commits intoeasybuilders:developfrom
ComputeCanada:force-try-toolchain
Oct 5, 2018
Merged

Allow --force to use regex if --try-toolchain cannot map intelligently.#2605
ocaisa merged 5 commits intoeasybuilders:developfrom
ComputeCanada:force-try-toolchain

Conversation

@bartoldeman
Copy link
Copy Markdown
Contributor

Fixes #2592

Comment thread easybuild/framework/easyconfig/tweak.py Outdated
raise EasyBuildError("Toolchain %s is not equivalent to toolchain %s in terms of capabilities. "
"Use --force if you are sure.",
target_toolchain['name'], source_toolchain['name'])
print_warning("Combining --try-toolchain with --force for toolchains with unequal capabilities: using regex.")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (126 > 120 characters)

@bartoldeman
Copy link
Copy Markdown
Contributor Author

This just moves the exception two levels up in the call stack and adjusts for --force. Maybe there is a better way @ocaisa?

@boegel boegel added this to the 3.7.1 milestone Oct 3, 2018
ocaisa
ocaisa previously approved these changes Oct 4, 2018
Copy link
Copy Markdown
Member

@ocaisa ocaisa left a comment

Choose a reason for hiding this comment

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

LGTM just need to fix the tests that expect map_toolchain_hierarchies to throw an error if no mapping exists

Comment thread easybuild/framework/easyconfig/tweak.py Outdated
print_warning("Combining --try-toolchain with --force for toolchains with unequal capabilities: "
"using regex.")
revert_to_regex = True
modifying_toolchains = False
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.

@bartoldeman Please refactor this a bit to i) use positive logic, ii) use if/else (it's a bit confusing now imho).

I would also clarify the "regex" part a bit in the warning, and also the error message(see below).

if build_option('force'):
    print_warning("Combining --try-toolchain with --force for toolchains with unequal capabilities: "
                  "disabling recursion & not changing (sub)toolchains.")
    revert_to_regex = True
    modifying_toolchains = False
else:
    raise EasyBuildError("Toolchain %s is not equivalent to toolchain %s in terms of capabilities, aborting "
                         "(if you know what you are doing, you can use --force to proceed anyway)",
                         target_toolchain['name'], source_toolchain['name'])

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.

Of course this should go below the if src_to_dst_tc_mapping is None: :)

Comment thread easybuild/framework/easyconfig/tweak.py Outdated
minimal_matching_toolchain = match_minimum_tc_specs(toolchain_spec, target_tc_hierarchy)
if not minimal_matching_toolchain:
return None
tc_mapping[toolchain_spec['name']] = minimal_matching_toolchain
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.

Same here, please use positive logic + if/else, and maybe also add a debug log message:

if minimal_matching_toolchain:
    tc_mapping[toolchain_spec['name']] = minimal_matching_toolchain
else:
    _log.debug("No minimal matching toolchain found for %s using %s", toolchain_spec, target_tc_hierarchy)
    return None

I'm also not a big fan of the inline return statement. Can we avoid this?

Comment thread easybuild/framework/easyconfig/tweak.py Outdated

# Warn if we are changing compiler families, this is very likely to cause problems
if target_compiler_family != source_tc_spec['comp_family']:
if minimal_matching_toolchain and target_compiler_family != source_tc_spec['comp_family']:
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.

@bartoldeman Wouldn't this make more sense?

if target_compiler_family and target_compiler_family != source_tc_spec['comp_family']:

@boegel
Copy link
Copy Markdown
Member

boegel commented Oct 4, 2018

Why is the test failing anyway? The error should still be thrown unless --force is used?

It seems to signal that the default behavior is being changed?

@ocaisa
Copy link
Copy Markdown
Member

ocaisa commented Oct 4, 2018

The failing tests are for match_minimum_tc_specs but with these changes this no longer throws the error, the error has been moved up the tree. The tests just need to changed to instead check for an empty dict...and maybe add another test to actually check the error throwing to where it's been moved.

@bartoldeman
Copy link
Copy Markdown
Contributor Author

I simplified the change by simply catching the deeper down exception into a new higher-level exception. This way I no longer need to distinguish between {} and None which is always a bit icky IMHO

@easybuilders easybuilders deleted a comment from boegelbot Oct 4, 2018
Comment thread easybuild/framework/easyconfig/tweak.py Outdated
try:
src_to_dst_tc_mapping = map_toolchain_hierarchies(source_toolchain, target_toolchain, modtool)
except EasyBuildError as err:
if build_option('force'):
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.

@bartoldeman We should probably check whether the raised exception is indeed the one raised by match_minimum_tc_specs, since (at least in theory) an EasyBuildError could be raised for a variety of reasons....

That could look something like this (untested):

except EasyBuildError as err:
    # make sure exception was raised by match_minimum_tc_specs because toolchain mapping could not be done
    if "No possible mapping from source toolchain" in err.msg:

        if build_option('force'):
            warning_msg = "Combining --try-toolchain with --force for toolchains with unequal capabilities: "
            warning_msg += "disabling recursion and not changing (sub)toolchains for dependencies."
            print_warning(warning_msg)
            revert_to_regex = True
            modifying_toolchains = False
        else:
            error_msg = err.msg + '\n'
            error_msg += "Toolchain %s is not equivalent to toolchain %s in terms of capabilities. "
            error_msg += "(if you know what you are doing, you can use --force to proceed anyway)"
            raise EasyBuildError(error_msg, target_toolchain['name'], source_toolchain['name'])
    else:
        # simply re-raise the exception if something else went wrong
        raise err

@bartoldeman
Copy link
Copy Markdown
Contributor Author

Reopening for @boegelbot and his master @boegel to see if this was a Travis glitch with Ubuntu updates...

@bartoldeman bartoldeman closed this Oct 5, 2018
@bartoldeman bartoldeman reopened this Oct 5, 2018
@easybuilders easybuilders deleted a comment from boegelbot Oct 5, 2018
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, I'll give @ocaisa the final work on this since it builds on top of his earlier work

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants