Skip to content

add-run-command - #50

Closed
sloev wants to merge 7 commits into
theskumar:masterfrom
sloev:master
Closed

add-run-command#50
sloev wants to merge 7 commits into
theskumar:masterfrom
sloev:master

Conversation

@sloev

@sloev sloev commented Feb 10, 2017

Copy link
Copy Markdown

I think it would be neat if the dotenv cli tool had an option to run a given commandline WITH the environment vars sourced from specified file, like a RUNNER.

# using the env command to print out env
echo "foo=bar" > .env
$ dotenv -f .env env 
foo=bar

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.4%) to 82.813% when pulling fcfbec5 on sloev:master into 9552db8 on theskumar:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.4%) to 82.813% when pulling 242dd97 on sloev:master into 9552db8 on theskumar:master.

@coveralls

coveralls commented Feb 10, 2017

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.4%) to 82.813% when pulling ab08024 on sloev:master into 9552db8 on theskumar:master.

@sloev

sloev commented Feb 14, 2017

Copy link
Copy Markdown
Author

any news on merge ... ?

@theskumar

Copy link
Copy Markdown
Owner

Hi, sorry for keeping you guys waiting, this looks amazing!

I'll have sometime today to look into it and then merge release.

Thanks @sloev

@theskumar theskumar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hi @sloev, i tried the dotenv and it seems it removes the existing env variable and keeps what's in the .env file only. Ideally it should only update the non-existing variables, i.e. behavior of environ.set_dafault. https://github.com/theskumar/python-dotenv/blob/master/dotenv/main.py#L27

How to reproduce:

# .env file
FOO=BAR
  1. Create a file called testrun.sh
!# /bin/bash
echo "From .env" $FOO
echo "From system env" $HOME
  1. chmod a+x testrun.sh then use dotenv run testrun.sh

@sloev

sloev commented Feb 19, 2017

Copy link
Copy Markdown
Author

Thanks for the feedback.
I will look into conforming to expected behaviour tomorrow.
Yep, set_default is the way to go.

@sloev

sloev commented Feb 20, 2017

Copy link
Copy Markdown
Author

all fixed in 0d5e22c now using load_dotenv and os.environ instead.
This means that existing envs will be set_defaultedwith provided .env file.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.4%) to 82.813% when pulling 0d5e22c on sloev:master into 9552db8 on theskumar:master.

3 similar comments
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.4%) to 82.813% when pulling 0d5e22c on sloev:master into 9552db8 on theskumar:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.4%) to 82.813% when pulling 0d5e22c on sloev:master into 9552db8 on theskumar:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.4%) to 82.813% when pulling 0d5e22c on sloev:master into 9552db8 on theskumar:master.

@theskumar

Copy link
Copy Markdown
Owner

Given a test.sh file

~/work/theskumar/python-dotenv pr/50
(pytho…/venv)❯ cat test.sh
#!/bin/bash
echo "From .env" $hello
echo "From system" $HOME

Uninstalled and re-install the latest code from this PR.

~/work/theskumar/python-dotenv pr/50
(pytho…/venv)❯ pip uninstall python-dotenv
Uninstalling python-dotenv-0.6.3:
  /Users/theskumar/work/theskumar/python-dotenv/venv/bin/dotenv
  /Users/theskumar/work/theskumar/python-dotenv/venv/lib/python2.7/site-packages/python-dotenv.egg-link
Proceed (y/n)? y
  Successfully uninstalled python-dotenv-0.6.3
~/work/theskumar/python-dotenv pr/50
(pytho…/venv)❯ pip install -e .
Obtaining file:///Users/theskumar/work/theskumar/python-dotenv
Requirement already satisfied (use --upgrade to upgrade): click>=5.0 in ./venv/lib/python2.7/site-packages (from python-dotenv==0.6.3)
Installing collected packages: python-dotenv
  Running setup.py develop for python-dotenv
Successfully installed python-dotenv

Now the run the dotenv run command:

~/work/theskumar/python-dotenv
(pytho…/venv)❯ dotenv run test.sh
Traceback (most recent call last):
  File "/Users/theskumar/work/theskumar/python-dotenv/venv/bin/dotenv", line 9, in <module>
    load_entry_point('python-dotenv==0.6.3', 'console_scripts', 'dotenv')()
  File "/Users/theskumar/work/theskumar/python-dotenv/venv/lib/python2.7/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/Users/theskumar/work/theskumar/python-dotenv/venv/lib/python2.7/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/Users/theskumar/work/theskumar/python-dotenv/venv/lib/python2.7/site-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/theskumar/work/theskumar/python-dotenv/venv/lib/python2.7/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/theskumar/work/theskumar/python-dotenv/venv/lib/python2.7/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "/Users/theskumar/work/theskumar/python-dotenv/venv/lib/python2.7/site-packages/click/decorators.py", line 16, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/theskumar/work/theskumar/python-dotenv/dotenv/cli.py", line 45, in run
    call(args, env=os.environ)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Do you get the same error, or it's just me?

@sloev

sloev commented Feb 20, 2017

Copy link
Copy Markdown
Author

No i didnt get the same error. I will get back to you.

@sloev

sloev commented Feb 20, 2017

Copy link
Copy Markdown
Author

I think it is a non populated 'file' arg

@uranusjr

Copy link
Copy Markdown

I pulled out this idea and created https://github.com/uranusjr/python-dotenv-run. It uses os.execlp to run the command when possible, to avoid creating a subprocess, and the --override flag which I find useful.

@theskumar

Copy link
Copy Markdown
Owner

Done in #105

@theskumar theskumar closed this Apr 5, 2018
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.

4 participants