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

Creating a package inside the notebook cells? #141

Open
oderwat opened this issue Oct 14, 2024 · 2 comments
Open

Creating a package inside the notebook cells? #141

oderwat opened this issue Oct 14, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@oderwat
Copy link

oderwat commented Oct 14, 2024

Hello @janpfeifer,

I just wondered if it is possible to create a package inside of the cells of a notebook. Would that be difficulty to implement?

How about something like %package something in the head of the cell to indicate that the code goes into a package. GONB then would create a directory named something and adds the code of all cells with that same package name into a file and prepends it with the package something header.

This package could then getting imported as all the others and help to write code that can easier be copied 1:1 into external projects.

@janpfeifer janpfeifer added the enhancement New feature or request label Oct 15, 2024
@janpfeifer
Copy link
Owner

So, this is interesting and naturally would be cool to add.

But I would put this on the back of the list for now, because I believe it would be lots of work. Things it would require from the top of my head:

  1. Supporting multiple memories of the current Go definitions (one per defined package)
  2. Special handling for go get, go import and some hacks to make it work, that I'm not sure would work the same when building a package as opposed to main. Not sure.
  3. Extend the %ls, %rm and %reset special commands to handle packages.

(As always, if you want to take a stab at it be my guest).

As an alternative -- probably not what you want, but ... -- during the GoMLX project development, I worked the whole time with gonb opened, using go work use <local gomlx path>, so I could keep editing in GoLand and playing around in GoNB, without having to do anything. Even the auto-complete in GoNB would pick up changes I made in GoLand immediately.

@oderwat
Copy link
Author

oderwat commented Oct 23, 2024

I am using go.work files similarly. But that is indeed not what I thought of.

When I see it correctly, a "package something" line in a cell is ignored. And even if not.

Could you add a feature that will ignore that package name in the go source? I mean if I write package something in a cell and then later use something.Func() that you remove the something. from the code for compilation and auto-completion?

This way one could write code "as if" it were in that package until one creates that package for real. When you created it for real, you do not need to rewrite all the code again and just need to remove the cells with those package names.

I could also try to take the original notebook and extract all the code for the packages, auto-create it and optionally update the code in the notebook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants