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

Add support for Wolfram Language #1014

Merged
merged 1 commit into from
Dec 11, 2022
Merged

Add support for Wolfram Language #1014

merged 1 commit into from
Dec 11, 2022

Conversation

dechamps
Copy link
Contributor

This adds support for Wolfram Language notebooks. For background, see:
https://github.com/WolframResearch/WolframLanguageForJupyter

Unfortunately, the way the Wolfram Language Jupyter kernel was designed poses a couple of issues with jupytext which I had to work around in this commit:

  • The language_info name is "Wolfram Language", which has unusual capitalization and whitespace. jupytext is mostly fine with this, except for Rmd where I had to hack around it in the parser.

  • The file extension is .m which clashes with Matlab. The current code structure seems to assume that an extension always maps to a single language. I worked around it by inventing a new extension (.wolfram), which is clearly not great but works fine for most use cases.

This adds support for Wolfram Language notebooks. For background, see:
  https://github.com/WolframResearch/WolframLanguageForJupyter

Unfortunately, the way the Wolfram Language Jupyter kernel was designed
poses a couple of issues with jupytext which I had to work around in
this commit:

 - The language_info name is "Wolfram Language", which has unusual
   capitalization and whitespace. jupytext is mostly fine with this,
   except for Rmd where I had to hack around it in the parser.

 - The file extension is .m which clashes with Matlab. The current code
   structure seems to assume that an extension always maps to a single
   language. I worked around it by inventing a new extension (.wolfram),
   which is clearly not great but works fine for most use cases.
@mwouts
Copy link
Owner

mwouts commented Nov 18, 2022

Hello @dechamps , thank you for the PR which looks great! I will have a further look at it in the middle of next week. Cheers

@mwouts
Copy link
Owner

mwouts commented Dec 6, 2022

Hi @dechamps , sorry it took me longer than expected before I could have a look at this PR. I like it very much!

One question: you seem to regret to not use the .m extension for Wolfram notebook, maybe I can have a look and see if I could find some workaround? Given how different the two file types are we might be able to distinguish easily between matlab/octave notebooks and wolfram ones, don't you think so?

@dechamps
Copy link
Contributor Author

dechamps commented Dec 6, 2022

One question: you seem to regret to not use the .m extension for Wolfram notebook, maybe I can have a look and see if I could find some workaround?

Honestly I don't mind this limitation. I only use Jupytext to store notebooks as Markdown files instead of .ipynb. In this use case I don't read nor write Wolfram Language files and so the extension doesn't matter (but I still had to come up with one to make the code work). I guess it's conceivable other users might care.

Given how different the two file types are we might be able to distinguish easily between matlab/octave notebooks and wolfram ones, don't you think so?

I'm not sure that's feasible in the general case without relying on heuristics. Consider the following file, for example:

a = 1
b = a

It's impossible to tell if this code is Matlab or Wolfram. It's valid in both. The fact they both chose to use the .m extension is really… unfortunate (and annoying).

One possible way out could be to require the use of a distinguisher, for example Wolfram Language files could be required to start with (* Wolfram Language *) in order to be recognized as such by Jupytext. I'll leave it up to you if you want to spend the time to implement such a solution.

@mwouts
Copy link
Owner

mwouts commented Dec 7, 2022

Interesting! Thanks for your answer! Well I'll think a bit more about it, see if we can do something simple (or not), and in any case I'll make my best to integrate your PR asap. Thanks!

@mwouts
Copy link
Owner

mwouts commented Dec 11, 2022

I am afraid you're right, allowing the same extension for Matlab or Wolfram Language seems overly complicated, at least I am afraid I can't do that now! So I'll take your PR as is, and many thanks again!

@mwouts mwouts merged commit c511119 into mwouts:main Dec 11, 2022
@mwouts mwouts mentioned this pull request Feb 20, 2023
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.

2 participants