diff --git a/.gitignore b/.gitignore index 8d0d1105a1d0437ff8c02a4875bc6d7efab39d1f..e4aea17e189dc0aadd17482fdcb8c5ff5543255b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc site +.DS_Store diff --git a/bin/compile b/bin/compile index bda4df3472584b43ed4659430f85c797054a3acc..52378a702a664ac20434134191c6e5237ac2eda4 100755 --- a/bin/compile +++ b/bin/compile @@ -42,7 +42,7 @@ export WARNINGS_LOG=$(mktemp) export RECOMMENDED_PYTHON_VERSION=$DEFAULT_PYTHON_VERSION # Setup bpwatch -export PATH=$PATH:$ROOT_DIR/vendor/bpwatch +export PATH=$PATH:$ROOT_DIR/vendor/:$ROOT_DIR/vendor/bpwatch LOGPLEX_KEY="t.b90d9d29-5388-4908-9737-b4576af1d4ce" export BPWATCH_STORE_PATH=$CACHE_DIR/bpwatch.json BUILDPACK_VERSION=v28 @@ -107,12 +107,6 @@ bpwatch start pre_compile source $BIN_DIR/steps/hooks/pre_compile bpwatch stop pre_compile -# If no requirements.txt file given, assume `setup.py develop` is intended. -if [ ! -f requirements.txt ]; then - echo "-e ." > requirements.txt -fi - - # Sticky runtimes. if [ -f $CACHE_DIR/.heroku/python-version ]; then DEFAULT_PYTHON_VERSION=$(cat $CACHE_DIR/.heroku/python-version) @@ -125,6 +119,9 @@ else CACHED_PYTHON_STACK=$STACK fi +# Pipenv Python version support. +source $BIN_DIR/steps/pipenv-python-version + # If no runtime given, assume default version. if [ ! -f runtime.txt ]; then echo $DEFAULT_PYTHON_VERSION > runtime.txt @@ -172,6 +169,14 @@ source $BIN_DIR/steps/python # Sanity check for setuptools/distribute. source $BIN_DIR/steps/setuptools +# Pipenv support. +source $BIN_DIR/steps/pipenv + +# If no requirements.txt file given, assume `setup.py develop` is intended. +if [ ! -f requirements.txt ]; then + echo "-e ." > requirements.txt +fi + # Uninstall removed dependencies with Pip. source $BIN_DIR/steps/pip-uninstall diff --git a/bin/detect b/bin/detect index e114d71c6324efca29e7551b01d62b925051f6ab..cee85b1982865c722a6fba5da4d01264bbcc9435 100755 --- a/bin/detect +++ b/bin/detect @@ -15,7 +15,7 @@ BUILD_DIR=$1 # Exit early if app is clearly not Python. -if [ ! -f $BUILD_DIR/requirements.txt ] && [ ! -f $BUILD_DIR/setup.py ]; then +if [ ! -f $BUILD_DIR/requirements.txt ] && [ ! -f $BUILD_DIR/setup.py ] && [ ! -f $BUILD_DIR/Pipfile ]; then exit 1 fi diff --git a/bin/steps/pipenv b/bin/steps/pipenv new file mode 100755 index 0000000000000000000000000000000000000000..d16c153cb53ef7ac2e9900c3914b545b274acceb --- /dev/null +++ b/bin/steps/pipenv @@ -0,0 +1,13 @@ +# Generate requriements.txt with pipenv. + +if [[ -f Pipfile ]]; then + if [[ ! -f requirements.txt ]]; then + puts-step "Generating 'requirements.txt' with pipenv" + + pip install git+https://github.com/kennethreitz/pipenv.git#egg=pipenv &> /dev/null + pipenv lock --requirements > requirements.txt 2> /dev/null + + pipstrip requirements.txt + fi +fi + diff --git a/bin/steps/pipenv-python-version b/bin/steps/pipenv-python-version new file mode 100755 index 0000000000000000000000000000000000000000..e49813a328ab24b955209973d20bea0a7a5c7c6a --- /dev/null +++ b/bin/steps/pipenv-python-version @@ -0,0 +1,22 @@ +# Detect Python-version with Pipenv. + +if [[ -f $BUILD_DIR/Pipfile.lock ]]; then + + if [[ ! -f $BUILD_DIR/runtime.txt ]]; then + if [[ ! -f Pipfile.lock ]]; then + pipenv lock 2> /dev/null + fi + + set +e + PYTHON=$(cat $BUILD_DIR/Pipfile.lock | jq '._meta.requires.python_version' -r) + set -e + + if [ "$PYTHON" = 2.7 ]; then + echo "python-2.7.13" > $BUILD_DIR/runtime.txt + fi + if [ "$PYTHON" = 3.6 ]; then + echo "python-3.6.0" > $BUILD_DIR/runtime.txt + fi + fi +fi + diff --git a/vendor/jq b/vendor/jq new file mode 100755 index 0000000000000000000000000000000000000000..7b920c4317d03febb6a31852ad9879fa58043c7f Binary files /dev/null and b/vendor/jq differ diff --git a/vendor/pipstrip b/vendor/pipstrip new file mode 100755 index 0000000000000000000000000000000000000000..67cd04941aefc0845693decab4a56cce0f59c29f --- /dev/null +++ b/vendor/pipstrip @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +import sys + +req_file = sys.argv[1] + +lines = [] + +with open(req_file, 'r') as f: + r = f.readlines() + for l in r: + lines.append(l.split('--hash')[0]) + +with open(req_file, 'w') as f: + f.write('\n'.join(lines))