Skip to content

tiltfile: add os.getenv, os.putenv, os.unsetenv. Fixes https://github.com/windmilleng/tilt/issues/2564#3329

Merged
nicks merged 1 commit into
masterfrom
nicks/ch6958/putenv
May 13, 2020
Merged

tiltfile: add os.getenv, os.putenv, os.unsetenv. Fixes https://github.com/windmilleng/tilt/issues/2564#3329
nicks merged 1 commit into
masterfrom
nicks/ch6958/putenv

Conversation

@nicks

@nicks nicks commented May 12, 2020

Copy link
Copy Markdown
Contributor

Hello @jazzdan,

Please review the following commits I made in branch nicks/ch6958/putenv:

fcf4b19 (2020-05-12 17:01:51 -0400)
tiltfile: add os.getenv, os.putenv, os.unsetenv. Fixes #2564

Code review reminders, by giving a LGTM you attest that:

  • Commits are adequately tested
  • Code is easy to understand and conforms to style guides
  • Incomplete code is marked with TODOs
  • Code is suitably instrumented with logging and metrics

@nicks
nicks requested a review from jazzdan May 12, 2020 21:02
@nicks
nicks force-pushed the nicks/ch6958/putenv branch from fcf4b19 to 644a0bc Compare May 12, 2020 21:05
@nicks

nicks commented May 12, 2020

Copy link
Copy Markdown
Contributor Author

actually, this isn't quite right, one sec

@nicks
nicks force-pushed the nicks/ch6958/putenv branch from 644a0bc to 6786b1a Compare May 12, 2020 21:27
@nicks

nicks commented May 12, 2020

Copy link
Copy Markdown
Contributor Author

ok, fixed.

I am...not happy about how much code I needed to duplicate from starlark to get this to work right. The core problem is that we need to make sure updates to the dict are reflected in the environment. The code in environ_methods is basically just copied-and-pasted mechanically, where I just replaced *Dict with Environ (since they use the same API)

@nicks

nicks commented May 12, 2020

Copy link
Copy Markdown
Contributor Author

(There's obviously a simpler implementation possible where *Dict supports different backing stores, but I'm not sure starlark would accept that upstream)

@nicks
nicks force-pushed the nicks/ch6958/putenv branch from 6786b1a to 710af3b Compare May 12, 2020 21:33
Comment thread internal/tiltfile/os/os.go Outdated
var defaultVal starlark.Value = starlark.None
err := starkit.UnpackArgs(t, fn.Name(), args, kwargs,
"varname", &varname,
"value?", &defaultVal,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"value?", &defaultVal,
"default?", &defaultVal,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ahhhh...good catch! this doc
https://docs.python.org/2/library/os.html
says it's value but this doc says it's default
https://docs.python.org/3/library/os.html
and when i tried it out in a real python interpreter, they all only accepted 'default' :rolledeyes:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Weird. Windows weird.

Comment thread internal/tiltfile/os/os.go Outdated

varnameStr, ok := value.AsString(varname)
if !ok {
return nil, fmt.Errorf("varname must be a string, actual: %s", varname)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does defaultVal also need to be enforced to be a string?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

surprisingly no!

python -c "import os; print(os.getenv('x', {}))"
{}

@nicks
nicks force-pushed the nicks/ch6958/putenv branch from 710af3b to efe1661 Compare May 12, 2020 22:55
@nicks
nicks merged commit 6c85e66 into master May 13, 2020
@nicks
nicks deleted the nicks/ch6958/putenv branch May 13, 2020 14:36
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.

Ability to set environment variables from Tiltfile

2 participants