Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Support Pipfile #168

Merged
merged 6 commits into from
Jun 6, 2018
Merged

Support Pipfile #168

merged 6 commits into from
Jun 6, 2018

Conversation

stlk
Copy link
Contributor

@stlk stlk commented Apr 2, 2018

As mentioned in #151 python community is heavily adopting dependency manager Pipenv. It's even recommended in official guide Managing Application Dependencies. It combines virtualenv creation, runtime specification, dependencies and their locked versions into two files.

I added support for Pipfile. The script first checks for runtime.txt and then for Pipfile.

You can test the implementation on https://github.com/Liduska/pipenv-build-example, which is copy of repository I use with requirements.txt and runtime.txt removed. You can find original repository on https://github.com/Liduska/coffeeshop-netlify.

Thanks for the great product!

@brycekahle
Copy link
Contributor

It looks like this is forcing python 3.6 if you want to use Pipenv. Is there some restriction on using that version of Python when using Pipenv?

@stlk
Copy link
Contributor Author

stlk commented Apr 2, 2018

@brycekahle Ah sorry, I should have mentioned that. Python version set in PIPENV_RUNTIME=3.6 variable is used to run Pipenv itself. Pipenv will then create environment based on version specified in Pipfile. It can be any version installed on the machine.

[requires]
python_version = "2.7"

You can see complete example at https://docs.pipenv.org/basics/#specifying-versions-of-python

@brycekahle
Copy link
Contributor

If there is no python_version in the Pipfile, would it create an environment based on 3.6?

@stlk
Copy link
Contributor Author

stlk commented Apr 6, 2018

Yes, it defaults to virtualenv's python. I tried it to be sure. We can easily change that to 2.7 using Pipenv's PIPENV_DEFAULT_PYTHON_VERSION env variable.
What should the default python be?

@brycekahle
Copy link
Contributor

Currently we have 2.7 as the default, so I think we should maintain that for Pipenv.

Copy link

@jayvdb jayvdb left a comment

Choose a reason for hiding this comment

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

Maybe some ways to improve it, but it already looks very good.

if $HOME/python$PIPENV_RUNTIME/bin/pipenv install
then
echo "Pipenv dependencies installed"
if source $($HOME/python$PIPENV_RUNTIME/bin/pipenv --venv)/bin/activate
Copy link

Choose a reason for hiding this comment

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

fwiw, doing this instead of pipenv shell and pipenv run means .env loading is not supported, which could break some Pipfile if it is expecting variables from .env to be present.

https://github.com/pypa/pipenv/blob/master/docs/advanced.rst#-automatic-loading-of-env
https://github.com/pypa/pipenv/blob/master/docs/advanced.rst#-support-for-environment-variables

Note that it isnt even possible to use .env vars during pipenv install. see pypa/pipenv#1906 (comment)

As a result, probably a good idea to set PIPENV_DONT_LOAD_ENV and document that .env isnt used by Netlify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! It seems to me that ENV variables are meant to be handled some other way on production. E.g. using https://www.netlify.com/docs/continuous-deployment/#build-environment-variables.

Based on discussion in pypa/pipenv#773 (comment) pipenv shell is meant only for development and using source .../bin/activate is OK for production.

echo "Python version set to $(python -V)"
else
echo "Error activating Pipenv environment"
echo "Please see https://github.com/netlify/build-image/#included-software for current versions"
Copy link

Choose a reason for hiding this comment

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

this isnt particularly useful here, as they would go to that page to learn that "Latest version." is the current version, and they would find the current version was actually in the log a few lines above this. ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I thought this refers to list of python versions user can use.

elif [ -f Pipfile ]
then
echo "Installing dependencies from Pipfile"
if $HOME/python$PIPENV_RUNTIME/bin/pipenv install
Copy link

Choose a reason for hiding this comment

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

might be useful to set PIPENV_VENV_IN_PROJECT as multiple venvs are not needed on Netlify builds. setting that might improve performance a little.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks! 🥇

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should move this (and the export lines from above) to the Dockerfile if possible. I'd rather pipenv be installed already, rather than done every build on-demand.

stlk added 2 commits April 7, 2018 09:32
This way we use virtualenv directly without going through Python Env Wrapper.
@jayvdb
Copy link

jayvdb commented Apr 27, 2018

ping @brycekahle

@brycekahle
Copy link
Contributor

@jayvdb Sorry for the delay. I need some time to look at this more in depth.

@@ -14,6 +14,11 @@ export GIMME_CGO_ENABLED=true
export NVM_DIR="$HOME/.nvm"
export RVM_DIR="$HOME/.rvm"

# Pipenv configuration
export PIPENV_RUNTIME=3.6
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would prefer this to be 2.7 if possible, since that is our default python version at the moment.

elif [ -f Pipfile ]
then
echo "Installing dependencies from Pipfile"
if $HOME/python$PIPENV_RUNTIME/bin/pipenv install
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should move this (and the export lines from above) to the Dockerfile if possible. I'd rather pipenv be installed already, rather than done every build on-demand.

@stlk
Copy link
Contributor Author

stlk commented May 4, 2018

@brycekahle I'm on vacation so I'll look into it as soon as I can :)

stlk added 2 commits May 11, 2018 08:11
So it goes in line with default Python version.
@stlk
Copy link
Contributor Author

stlk commented May 11, 2018

@brycekahle Thanks for the feedback! I made the changes you requested.

@brycekahle brycekahle merged commit 8790a1e into netlify:master Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants