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

General cleanup take #2 #30

Merged
merged 5 commits into from
May 11, 2017
Merged

General cleanup take #2 #30

merged 5 commits into from
May 11, 2017

Conversation

parente
Copy link
Contributor

@parente parente commented May 10, 2017

Comments and code cleanup in the other two modules not hit in #29

* Document scala_kernel
* Rename SparkInterpreter to ScalaInterpreter for
  consistency with the factory function and module
  name
@codecov
Copy link

codecov bot commented May 10, 2017

Codecov Report

Merging #30 into master will increase coverage by 0.05%.
The diff coverage is 78.37%.

@@            Coverage Diff             @@
##           master      #30      +/-   ##
==========================================
+ Coverage   84.31%   84.36%   +0.05%     
==========================================
  Files           6        6              
  Lines         408      403       -5     
==========================================
- Hits          344      340       -4     
+ Misses         64       63       -1

@parente parente changed the title [WIP] General cleanup take #2 General cleanup take #2 May 11, 2017
Copy link

@ericdill ericdill left a comment

Choose a reason for hiding this comment

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

Gods work, my friend. Gods work.


Returns
-------
scala.tools.nsc.interpreter.PresentationCompilerCompleter

Choose a reason for hiding this comment

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

this looks almost fully qualified. Should this be: py4j.java_gateway.JVMView. scala.tools.nsc.interpreter.PresentationCompilerCompleter ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

scala.tools.nsc.interpreter.PresentationCompilerCompleter is the Scala type. py4j.java_gateway.JVMView is a made up namespace which allows Python code to reference them I believe. There is no real Python module+type py4j.java_gateway.JVMView. scala.tools.nsc.interpreter.PresentationCompilerCompleter.

What to do, what to do ...

Choose a reason for hiding this comment

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

Ah alright well fair enough then. Made up object paths, yey

# don't actually want that to happen. Simplest is just to have this
# flag as None initially. Furthermore the metakernel will attempt to
# set things like _i1, _i, _ii etc. These we dont want in the kernel
# for now.
if self._scalamagic and (not name.startswith("_i")):

Choose a reason for hiding this comment

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

What are your feelings on logging attempts to set _i... variables? I'm generally 👎 on silent behavior changes but also don't have a clue how metakernel stuff works, so 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will happen after almost every cell execution as MetaKernel will update the FIFO queue of commands and outputs, so the logs will get pretty chatty. We could log at the debug level.

Returns
-------
value : any
Scala variable value, tranformed to a Python type
"""
if self._scalamagic:
intp = self.scala_interpreter
intp.interpret(name)
return intp.last_result()

def do_execute_direct(self, code, silent=False):

Choose a reason for hiding this comment

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

what is this extra kwarg?

-------
list of str
Possible completions for the code
"""
return self._scalamagic.get_completions(info)

def get_kernel_help_on(self, info, level=0, none_on_fail=False):

Choose a reason for hiding this comment

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

another spurious kwarg?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in person, will doc how these are all implementing the expected MetaKernel interface.

level : int
Level of help to request, 0 for basic, 1 for more, etc.
none_on_fail : bool
Ignored

Choose a reason for hiding this comment

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

doesn't look ignored. it's passed to self._scalamagic.get_help_on()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ignored down in _scalamagic.get_help_on. I'll try to figure out from the metakernel source exactly how it's used.

"""Due to the nature of scala's completer we get full method names.
We need to trim out the common pieces. Try longest prefix first etc
"""Due to the nature of Scala's completer we get full method names.
We need to trim out the common pieces. Try longest prefix first, etc.
"""
potential_prefix = os.path.commonprefix(completions)
for i in reversed(range(len(potential_prefix)+1)):

Choose a reason for hiding this comment

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

any chance for adding some in-line comments on this code block? My brain is getting angry with me when I try and parse this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passing on this one for now. I'll need to create some examples to really document this well.

final_completions = [prefix + h[offset:] for h in completions]
self.kernel.log.debug('''info %s
completions %s
final %s''', info, completions, final_completions)

Choose a reason for hiding this comment

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

Do you need to dedent this? I think this will render as:

info <info>
            completions <completions>
            final <final>

but not 100% certain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original log message had indents as well.

Information returned by `metakernel.parser.Parser.parse_code`
including `help_obj`, etc.
level : int
Level of help to request, 0 for basic, 1 for more, etc.

Choose a reason for hiding this comment

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

how high can this number go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Infinity. It's by convention. I'll make note of that.

info : dict
Information returned by `metakernel.parser.Parser.parse_code`
including `help_obj`, etc.
level : int

Choose a reason for hiding this comment

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

int, optional

-------
str
Help text
"""
intp = self._get_scala_interpreter()
self.kernel.log.debug(info['help_obj'])
# Calling this twice produces different output

Choose a reason for hiding this comment

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

what the heck. Why does this produce different results??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's one @mariusvniekerk will need to answer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Basically it's pretty heavily assumed that this is used in the scala repl. So it is the same call for two tabs. It is kinda mad

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, press tab twice for more details. Nice.

REPLs. REPLs all the way down.

@parente
Copy link
Contributor Author

parente commented May 11, 2017

@ericdill Ready for another look.


Returns
-------
scala.tools.nsc.interpreter.PresentationCompilerCompleter

Choose a reason for hiding this comment

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

Ah alright well fair enough then. Made up object paths, yey

@ericdill
Copy link

FWIW this has my blessing

@parente
Copy link
Contributor Author

parente commented May 11, 2017

Thanks for taking the time @ericdill.

@parente parente merged commit 262c12f into vericast:master May 11, 2017
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.

3 participants