Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExecutePreprocessor: Get kernel name when executing, and not during initialization #924

Merged
merged 1 commit into from
Dec 7, 2018

Conversation

mgeier
Copy link
Contributor

@mgeier mgeier commented Dec 4, 2018

Since there doesn't seem to be any progress in PR #886, I'm proposing this more minimalist approach to fixing #878 (that I've already suggested in #886 (comment)).

The underlying design problems (as mentioned in #886 (comment)) are of course still there, but this PR at least fixes the regression introduced in #816. Hopefully this can be incorporated in the next nbconvert release!

If desired, I can make another PR at a later point to fix those other problems, but I think that is not as urgent as the fix in this PR.

... and not during initialization.

Fixes jupyter#878.
Copy link
Contributor

@MSeal MSeal left a comment

Choose a reason for hiding this comment

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

I think I'm ok with this change (though a test would be nice). We can always finish 886 if we want a more exhaustive implementation. @mpacer , thoughts?

@mpacer
Copy link
Member

mpacer commented Dec 7, 2018

This has some issues from a traitlets perspective since it will no longer be a traitlet if set in this way. That shouldn't be an issue per se since it's primarily acting as a default value and there isn't any @observe logic here. Note if anyone is using that aspect of traitlets downstream, this will break it.

I would prefer a test of all expected behaviour if this is to be merged.

@mgeier
Copy link
Contributor Author

mgeier commented Dec 7, 2018

Good point @mpacer, I didn't think about this!

What's the proper way to set the value of a traitlet on a class instance?

I've come up with two ways:

        if not self.kernel_name:
            ExecutePreprocessor.kernel_name.__set__(self, self.nb.metadata.get(
                'kernelspec', {}).get('name', 'python'))
        if not self.kernel_name:
            self._trait_values['kernel_name'] = self.nb.metadata.get(
                'kernelspec', {}).get('name', 'python')

Both work for me, but which is the proper one?
Or is there a different way to do it?

@SylvainCorlay
Copy link
Member

This has some issues from a traitlets perspective since it will no longer be a traitlet if set in this way.

I think that it would still be a trait. This change merely removes the default initialization and sets a value later.

self._trait_values['kernel_name']

I would recommend not to use private functions of traitlets!

@mgeier
Copy link
Contributor Author

mgeier commented Dec 7, 2018

Oh, looks like @SylvainCorlay is right:

import traitlets

class Foo(traitlets.HasTraits):
    bar = traitlets.Int()

x = Foo(bar=55)
x.bar = 99
print(x._trait_values)

This prints:

{'bar': 99}

So it indeed seems to be still a trait(let), otherwise the _trait_values dict would not reflect the latest change, right?

So this means my PR can stay unchanged?

About the tests y'all were mentioning: can someone else please write them?

@MSeal
Copy link
Contributor

MSeal commented Dec 7, 2018

I can copy M's test over and get it merged independently if it helps.

@MSeal
Copy link
Contributor

MSeal commented Dec 7, 2018

Got a soft +1 from M in person. Will merge and will pop up a unittest here in a minute.

@MSeal MSeal merged commit 02c5cd1 into jupyter:master Dec 7, 2018
@SylvainCorlay
Copy link
Member

👍

@mgeier mgeier deleted the issue-878 branch December 8, 2018 09:26
@mgeier
Copy link
Contributor Author

mgeier commented Dec 8, 2018

Thanks a lot @MSeal and all others that were involved, it's great to have a working master branch again!

Are there any plans yet for a new nbconvert release?

@MSeal
Copy link
Contributor

MSeal commented Dec 8, 2018

I was going to see what should finish getting merged this week and get a smaller release going.

@mgeier
Copy link
Contributor Author

mgeier commented Dec 10, 2018

@MSeal That sounds great, thanks!

@MSeal MSeal added this to the 5.4.1 milestone Feb 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants