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

Fix export to python script not appearing #5407

Merged
merged 4 commits into from
Apr 5, 2021
Merged

Fix export to python script not appearing #5407

merged 4 commits into from
Apr 5, 2021

Conversation

DavidKutu
Copy link

@DavidKutu DavidKutu commented Apr 5, 2021

Assume a notebook is a python notebook if the kernelspec name includes 'python'

For #5403
(and still works with #4965)

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR).
  • Title summarizes what is changing.
  • Has a news entry file (remember to thank yourself!).
  • Appropriate comments and documentation strings in the code.
  • Has sufficient logging.
  • Has telemetry for enhancements.
  • Unit tests & system/integration tests are added/updated.
  • Test plan is updated as appropriate.
  • package-lock.json has been regenerated by running npm install (if dependencies have changed).

kernelspec name includes python
if (kernelSpec?.name.includes(PYTHON_LANGUAGE)) {
return true;
}

// Valid notebooks will have a language information in the metadata.
Copy link
Author

Choose a reason for hiding this comment

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

There's exceptions to this, sometime the kernelspec only has name and displayname

@DavidKutu DavidKutu marked this pull request as ready for review April 5, 2021 20:15
@DavidKutu DavidKutu requested a review from a team as a code owner April 5, 2021 20:15
@DavidKutu DavidKutu changed the title Fix export not appearing Fix export to python script not appearing Apr 5, 2021
@@ -109,6 +109,11 @@ export function isPythonNotebook(metadata?: nbformat.INotebookMetadata) {
if (metadata?.language_info?.name && metadata.language_info.name !== PYTHON_LANGUAGE) {
return false;
}

if (kernelSpec?.name.includes(PYTHON_LANGUAGE)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it won't work consistently. What line here is causing the notebook to not be python otherwise?

@DavidKutu
Copy link
Author

@rchiodo its the next bit

// Valid notebooks will have a language information in the metadata.
return kernelSpec?.language === PYTHON_LANGUAGE;

Sometime kernelspecs don't have the language (the minimum I've seen is to only have the name). The notebooks we create with our command don't have it, that's why Export to Python script is missing, it thinks its not a python notebook.

@rchiodo
Copy link
Contributor

rchiodo commented Apr 5, 2021

@rchiodo its the next bit

// Valid notebooks will have a language information in the metadata.
return kernelSpec?.language === PYTHON_LANGUAGE;

Sometime kernelspecs don't have the language (the minimum I've seen is to only have the name). The notebooks we create with our command don't have it, that's why Export to Python script is missing, it thinks its not a python notebook.

Maybe there's more we can do then? I think the 'name' check for python will work in some cases, but may not. Could we not also check the 'executable' being run for the kernelspec? It should have 'python' in it somewhere.

@codecov-io
Copy link

Codecov Report

Merging #5407 (d3f6e3f) into main (b1f70d0) will decrease coverage by 0%.
The diff coverage is 100%.

❗ Current head d3f6e3f differs from pull request most recent head 1520e78. Consider uploading reports for the commit 1520e78 to get more accurate results

@@          Coverage Diff          @@
##            main   #5407   +/-   ##
=====================================
- Coverage     73%     73%   -1%     
=====================================
  Files        401     401           
  Lines      26580   26583    +3     
  Branches    3878    3879    +1     
=====================================
- Hits       19510   19506    -4     
- Misses      5454    5459    +5     
- Partials    1616    1618    +2     
Impacted Files Coverage Δ
src/client/datascience/notebook/helpers/helpers.ts 72% <100%> (+<1%) ⬆️
src/client/datascience/raw-kernel/rawSocket.ts 84% <0%> (-2%) ⬇️
...datascience/notebookStorage/nativeEditorStorage.ts 80% <0%> (-1%) ⬇️
src/client/datascience/baseJupyterSession.ts 75% <0%> (-1%) ⬇️
src/client/datascience/jupyter/jupyterNotebook.ts 75% <0%> (-1%) ⬇️
...active-common/intellisense/intellisenseProvider.ts 74% <0%> (-1%) ⬇️
src/client/datascience/notebook/remoteSwitcher.ts 91% <0%> (+<1%) ⬆️


if (notebook.metadata && isPythonNotebook(notebook.metadata)) {
if (interpreter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we don't have the python extension installed?

I think this would be better off being an or with the previous condition.

@DavidKutu DavidKutu merged commit af1c020 into main Apr 5, 2021
@DavidKutu DavidKutu deleted the david/exportFix branch April 5, 2021 22:08
IanMatthewHuff pushed a commit that referenced this pull request Apr 8, 2021
* assume a notebook is a python notebook if the
kernelspec name includes python

* news

* use intepreter to decide if its a python notebook

* keep both conditions
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.

5 participants