gophernotes icon indicating copy to clipboard operation
gophernotes copied to clipboard

[Question] Import a specific version of a package?

Open cosmos72 opened this issue 5 years ago • 6 comments

@mattn wrote in #184

Sorry off topic. Can I import specific version of package in notebook?

cosmos72 avatar Sep 04 '20 19:09 cosmos72

Currently it's not possible.

My first impression is that it would require two changes:

  1. a syntax to specify both the package and its version - for example something like import "some/[email protected]" except that @ should be replaced with a character that cannot be part of a package name - anyone knows any such character?
  2. a mechanism to forward the package version to go build - it should be enough to put it in the file go.mod of the plugin created on-the-fly and compiled to load the package.

cosmos72 avatar Sep 04 '20 19:09 cosmos72

this would be a very appreciated addition. A space character would not work?

elamre avatar Sep 08 '20 12:09 elamre

Directory names can contain spaces. Actually, at least on Linux, directory names can contain any character except ASCII 47 (i.e. forward slash '/') and ASCII 0.

Thus import "some/package\000v1.2" could technically work on Linux, and probably also on most Unix-like systems. It's also really ugly.

cosmos72 avatar Sep 08 '20 12:09 cosmos72

I prefer that gophernotes recognize go.mod file placed in same location of notebook file.

mattn avatar Sep 08 '20 12:09 mattn

Has there been any thought on this? @cosmos72

elamre avatar Jul 26 '22 11:07 elamre

The implementation is relatively straightforward: it's just a matter of propagating the requested version through some functions, and write it in the go.mod file of the plugin that will be compiled.

About the syntax: official command line tools go get and go install now accept the syntax example.com/my/package@latest and example.com/my/[email protected] so the syntax

import "some/[email protected]"

is now acceptable, as that's exactly what these tools use too. Any package whose path contains '@' will now break the official tools go get and go install so there will be a strong pressure to rename it and remove the '@'.

In summary: it's now just a matter of implementing it. Don't expect me to have time in the next few weeks, though...

cosmos72 avatar Aug 05 '22 16:08 cosmos72