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 platform: module to expose platform data #927
Conversation
pkg/eval/sys/sys.go
Outdated
|
||
func init() { | ||
Ns.Add("arch", vars.NewReadOnly(runtime.GOARCH)) | ||
Ns.Add("platform", vars.NewReadOnly(runtime.GOOS)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine you called it after Python's sys.platform
, but I'd rather this be called os
to align with Go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did but on second thought agree with using os
for consistency given how tightly Elvish is bound to Go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also assume you'll want the namespace changed from sys
to os
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the straightforward rename exposes a problem:
pkg/program/shell/runtime.go:18:2: os redeclared as imported package name
previous declaration at pkg/program/shell/runtime.go:7:2
Which means that any import of the elvish os module must rename it. Which means we now need to establish a convention for this situation. 😦 I have tentatively settled on importing elvish_os "github.com/elves/elvish/pkg/eval/os"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference is calling this module sys
; it is a bit awkward to have a variable called $os:os
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that my first incarnation did call this the sys:
namespace 😄 Not sure what you mean by your $os:os
example. There is no such var at this time. There is $os:platform
and $os:arch
. I deliberately used platform
because os
has too much baggage. For example, why is the value darwin
rather than macos
on my Macs? Or linux
rather than ubuntu
? Etcetera. I think platform
better conveys the meaning of this var.
pkg/eval/sys/sys.go
Outdated
@@ -0,0 +1,25 @@ | |||
// Package sys exposes variables and functions that deal with the specific |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am considering putting these variables related to interpreter internals in this module too:
Lines 148 to 162 in 7868b68
beforeChdirElvish, afterChdirElvish := vector.Empty, vector.Empty | |
ev.beforeChdir = append(ev.beforeChdir, | |
adaptChdirHook("before-chdir", ev, &beforeChdirElvish)) | |
ev.afterChdir = append(ev.afterChdir, | |
adaptChdirHook("after-chdir", ev, &afterChdirElvish)) | |
builtin["before-chdir"] = vars.FromPtr(&beforeChdirElvish) | |
builtin["after-chdir"] = vars.FromPtr(&afterChdirElvish) | |
builtin["value-out-indicator"] = vars.FromPtrWithMutex( | |
&ev.state.valuePrefix, &ev.state.mutex) | |
builtin["notify-bg-job-success"] = vars.FromPtrWithMutex( | |
&ev.state.notifyBgJobSuccess, &ev.state.mutex) | |
builtin["num-bg-jobs"] = vars.FromGet(func() interface{} { | |
return strconv.Itoa(ev.state.getNumBgJobs()) | |
}) |
Which won't fit this description something along the description Python's sys module would be more accurate:
This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference is for anything that is explicitly tied to the OS or architecture, and which cannot be papered over by an OS agnostic API, be in the os
namespace rather than in the builtin namespace.
15485ae
to
c8fd862
Compare
@xiaq Please take another look. |
c8fd862
to
b004f71
Compare
I posted a comment, but actually I think we need to think harder on how to name this module and what its scope should be. I was considering modelling the module after Python's
I think it's wise to separate both things, and the variables in this PR definitely belong to the second bullet. Your proposed name of Maybe (I am inspired by Python's platform module, although the Python module makes the mistake of including information about the interpreter.) It's probably also worth researching how other languages call such modules. |
Okay, but since it seems like we're still a ways away from a elvish 1.0 release it seems like doing something reasonable, if not ideal, is better than not doing anything and forcing people to use the
I'm not bothered by the length of those two example var names. However, I was thinking that builtins like |
@krader1961 I agree with what you said, so let's rename the module in this PR to platform and we are good to go. |
b004f71
to
881ccf9
Compare
@xiaq, Please take another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few final nitpicks, almost ready to go.
Resolves #916