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

Allow values in Pipfile to consume Environment Variables #1769

Merged
merged 3 commits into from
Mar 20, 2018

Conversation

dvf
Copy link
Contributor

@dvf dvf commented Mar 16, 2018

Relying on os.path.expandvars() to inject environment variables in strings. Works on Windows, back-supports Python 2.7.

See #1688

I'm not 100% sure that this is the correct place to do this injection.

Some thoughts:

  • The Pipfile hash should be determined after values have attempted to be inserted.
  • Pipfile shouldn't be intelligent by trying to differentiate env vars from regular characters—if an env var can't be inserted, the string should remain intact.
  • As it stands, Pipenv's vendor folder contains some version of this repository. I don't fully understand the reasons behind this, maybe we could pin it as a requirement instead? We could then separate tests.

Mirrored Pipfile PR: pypa/pipfile#105

@jtratner
Copy link
Collaborator

can you add a test that fails when an environment variable is not defined?

@jtratner
Copy link
Collaborator

(looks like it doesn't error just doesn't expand in python 3.6)

>>> os.path.expandvars('${A}')
'${A}'

@dvf
Copy link
Contributor Author

dvf commented Mar 16, 2018 via email

@jtratner
Copy link
Collaborator

I'm concerned about something error about not connecting that turns out to be not being able to connect to $USERNAME:[email protected] or something like that.

Way nicer to error and say USERNAME not defined! :)

Also how does this impact hashing? Which parts of the pipfile are allowed to have env vars in them?

@jtratner
Copy link
Collaborator

(but I'm def not BDFL here :) )

Copy link
Member

@techalchemy techalchemy left a comment

Choose a reason for hiding this comment

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

I like the approach, but think this should be PR'ed to the pipfile repo as well- and any changes to packages in the vendor directory will require the package to move to the patched folder

@@ -62,6 +62,24 @@ def __init__(self, filename='Pipfile'):
def __repr__(self):
return '<PipfileParser path={0!r}'.format(self.filename)

def inject_environment_variables(self, d):
Copy link
Member

Choose a reason for hiding this comment

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

Generally anything in the vendor directory needs to be kept pristine, any modifications would require this package to move into the patched directory

More significantly you should simultaneously PR this change back up to the pipfile repository as well since we are not the only project which uses pipfiles

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did that here: pypa/pipfile#105

Choose a reason for hiding this comment

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

Just for curiosity, which other projects are using Pipfiles?

@techalchemy techalchemy added the Status: Requires Approval This issue requires additional approval to move forward. label Mar 16, 2018
@dvf
Copy link
Contributor Author

dvf commented Mar 17, 2018

After some thought I don't think this is ready. Would appreciate some clarity here.

Some thoughts:

  • The Pipfile hash should not be affected by the values of the env vars, only the keys. This means the hash will have to be calculated before injection.
  • Disagree with @jtratner regarding raising errors: Pipfile shouldn't be intelligent by trying to differentiate env vars from regular characters—if an env var can't be inserted, the string should remain the same.
  • The reasons for having a vendor folder aren't clear to me if they haven't been patched: Why not just add Pipfile as a requirement?

@jtratner
Copy link
Collaborator

jtratner commented Mar 17, 2018 via email

@dvf
Copy link
Contributor Author

dvf commented Mar 17, 2018

@techalchemy, I'm confused by your concern about package hashes. Maybe I'm missing something, but it would be weird if package hashes depended on the Pipfile itself.

Generally, not sure where it would ever make sense to have $ as a name.

It's bad to make assumptions about values: $ is an allowable character for an URL.

@jtratner
Copy link
Collaborator

jtratner commented Mar 17, 2018 via email

@dvf
Copy link
Contributor Author

dvf commented Mar 17, 2018

Thanks for everyone's interest.
I'm taking the contributors' advice and opening pypa/pipfile#105 instead.

@dvf dvf closed this Mar 17, 2018
@dvf
Copy link
Contributor Author

dvf commented Mar 19, 2018

@kennethreitz @jtratner @techalchemy do you guys mind taking a peek at pypa/pipfile#105

@techalchemy
Copy link
Member

We vendor things to isolate them from system dependencies. This is a common practice.

@dvf
Copy link
Contributor Author

dvf commented Mar 19, 2018

I'm re-opening after taking suggestions and making the mirrored Pipfile pypa/pipfile#105

@dvf dvf reopened this Mar 19, 2018
@kennethreitz kennethreitz merged commit e8e38d7 into pypa:master Mar 20, 2018
@kennethreitz
Copy link
Contributor

🍰

@kennethreitz
Copy link
Contributor

Made some changes to this — primarily, env vars are not propogated to the pipfile.lock, as they are here. They are also expanded at runtime. We want to keep secrets out of source control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Requires Approval This issue requires additional approval to move forward.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants