Unverified Commit 97ac451a authored by Kenneth Reitz's avatar Kenneth Reitz Committed by GitHub

Pipenv uninstall, and other improvements (#650)

parent 06fa6d23
# Python Buildpack Changelog # Python Buildpack Changelog
# 126
Skip installs if Pipfile.lock hasn't changed, and uninstall stale dependencies with Pipenv.
- No longer warn if there is no `Procfile`.
# 125 # 125
Set `PYTHONPATH` during collectstatic runs, other updates. Set `PYTHONPATH` during collectstatic runs, other updates.
......
...@@ -100,12 +100,6 @@ export PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/li ...@@ -100,12 +100,6 @@ export PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/li
# Switch to the repo's context. # Switch to the repo's context.
cd "$BUILD_DIR" cd "$BUILD_DIR"
# Warn for lack of Procfile.
if [[ ! -f Procfile ]]; then
puts-warn 'Warning: Your application is missing a Procfile. This file tells Heroku how to run your application.'
puts-warn 'Learn more: https://devcenter.heroku.com/articles/procfile'
fi
# Prepare the cache. # Prepare the cache.
mkdir -p "$CACHE_DIR" mkdir -p "$CACHE_DIR"
...@@ -166,7 +160,14 @@ mtime "python.install.time" "${start}" ...@@ -166,7 +160,14 @@ mtime "python.install.time" "${start}"
# Pipenv support. # Pipenv support.
# shellcheck source=bin/steps/pipenv # shellcheck source=bin/steps/pipenv
source "$BIN_DIR/steps/pipenv" sub_env "$BIN_DIR/steps/pipenv"
# Uninstall removed dependencies with Pip.
let start=$(nowms)
# shellcheck source=bin/steps/pip-uninstall
source "$BIN_DIR/steps/pip-uninstall"
mtime "pip.uninstall.time" "${start}"
# If no requirements.txt file given, assume `setup.py develop` is intended. # If no requirements.txt file given, assume `setup.py develop` is intended.
if [ ! -f requirements.txt ] && [ ! -f Pipfile ]; then if [ ! -f requirements.txt ] && [ ! -f Pipfile ]; then
...@@ -197,12 +198,6 @@ sub_env "$BIN_DIR/steps/geo-libs" ...@@ -197,12 +198,6 @@ sub_env "$BIN_DIR/steps/geo-libs"
# shellcheck source=bin/steps/gdal # shellcheck source=bin/steps/gdal
source "$BIN_DIR/steps/gdal" source "$BIN_DIR/steps/gdal"
# Uninstall removed dependencies with Pip.
let start=$(nowms)
# shellcheck source=bin/steps/pip-uninstall
source "$BIN_DIR/steps/pip-uninstall"
mtime "pip.uninstall.time" "${start}"
# Install dependencies with Pip (where the magic happens). # Install dependencies with Pip (where the magic happens).
let start=$(nowms) let start=$(nowms)
# shellcheck source=bin/steps/pip-install # shellcheck source=bin/steps/pip-install
......
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
set +e set +e
# Install dependencies with Pip. # Install dependencies with Pip.
# shellcheck source=bin/utils
source $BIN_DIR/utils
if [[ -f .heroku/python/requirements-declared.txt ]]; then if [ ! "$SKIP_PIP_INSTALL" ]; then
if [[ -f .heroku/python/requirements-declared.txt ]]; then
cp .heroku/python/requirements-declared.txt requirements-declared.txt cp .heroku/python/requirements-declared.txt requirements-declared.txt
...@@ -15,6 +19,7 @@ if [[ -f .heroku/python/requirements-declared.txt ]]; then ...@@ -15,6 +19,7 @@ if [[ -f .heroku/python/requirements-declared.txt ]]; then
puts-step "Uninstalling stale dependencies" puts-step "Uninstalling stale dependencies"
/app/.heroku/python/bin/pip uninstall -r .heroku/python/requirements-stale.txt -y --exists-action=w | cleanup | indent /app/.heroku/python/bin/pip uninstall -r .heroku/python/requirements-stale.txt -y --exists-action=w | cleanup | indent
fi fi
fi fi
fi
set -e set -e
...@@ -5,8 +5,27 @@ ...@@ -5,8 +5,27 @@
# shellcheck source=bin/utils # shellcheck source=bin/utils
source $BIN_DIR/utils source $BIN_DIR/utils
# Pipenv support (Generate requriements.txt with pipenv).
if [[ -f Pipfile ]]; then if [[ -f Pipfile.lock ]]; then
if [[ -f .heroku/python/Pipfile.lock.sha256 ]]; then
if [[ $(openssl dgst -sha256 Pipfile.lock) == $(cat .heroku/python/Pipfile.lock.sha256) ]]; then
if [[ ! "$PIPENV_ALWAYS_INSTALL" ]]; then
echo "Skipping installation, as Pipfile.lock hasn't changed since last deploy." | indent
echo "To disable this functionality, run the following command:"
echo ""
echo " $ heroku config:set PIPENV_ALWAYS_INSTALL=1" | indent
SKIP_PIPENV_INSTALL=1
fi
fi
fi
fi
if [ ! "$SKIP_PIPENV_INSTALL" ]; then
# Pipenv support (Generate requriements.txt with pipenv).
if [[ -f Pipfile ]]; then
if [[ ! -f requirements.txt ]]; then if [[ ! -f requirements.txt ]]; then
puts-step "Installing requirements with latest Pipenv…" puts-step "Installing requirements with latest Pipenv…"
...@@ -19,6 +38,10 @@ if [[ -f Pipfile ]]; then ...@@ -19,6 +38,10 @@ if [[ -f Pipfile ]]; then
export PIP_EXTRA_INDEX_URL export PIP_EXTRA_INDEX_URL
fi fi
# if [[ -f .heroku/python/requirements-declared.txt ]]; then
# cp .heroku/python/requirements-declared.txt requirements.txt
# fi
# Install pipenv. # Install pipenv.
/app/.heroku/python/bin/pip install pipenv --upgrade &> /dev/null /app/.heroku/python/bin/pip install pipenv --upgrade &> /dev/null
...@@ -26,6 +49,11 @@ if [[ -f Pipfile ]]; then ...@@ -26,6 +49,11 @@ if [[ -f Pipfile ]]; then
if [[ ! -f Pipfile.lock ]]; then if [[ ! -f Pipfile.lock ]]; then
/app/.heroku/python/bin/pipenv install --system --skip-lock 2>&1 | indent /app/.heroku/python/bin/pipenv install --system --skip-lock 2>&1 | indent
else else
pipenv-to-pip Pipfile.lock > requirements.txt
"$BIN_DIR/steps/pip-uninstall"
cp requirements.txt .heroku/python/requirements-declared.txt
openssl dgst -sha256 Pipfile.lock > .heroku/python/Pipfile.lock.sha256
/app/.heroku/python/bin/pipenv install --system --deploy 2>&1 | indent /app/.heroku/python/bin/pipenv install --system --deploy 2>&1 | indent
fi fi
...@@ -39,7 +67,10 @@ if [[ -f Pipfile ]]; then ...@@ -39,7 +67,10 @@ if [[ -f Pipfile ]]; then
export SKIP_PIP_INSTALL=1 export SKIP_PIP_INSTALL=1
# Pip freeze, for compatibility. # Pip freeze, for compatibility.
/app/.heroku/python/bin/pip freeze > requirements.txt pip freeze > requirements.txt
fi
fi fi
else
pipenv-to-pip Pipfile.lock > requirements.txt
export SKIP_PIP_INSTALL=1
fi fi
...@@ -41,6 +41,7 @@ class Requirements(object): ...@@ -41,6 +41,7 @@ class Requirements(object):
if not getattr(requirement.req, 'name', None): if not getattr(requirement.req, 'name', None):
# Prior to pip 8.1.2 the attribute `name` did not exist. # Prior to pip 8.1.2 the attribute `name` did not exist.
requirement.req.name = requirement.req.project_name requirement.req.name = requirement.req.project_name
requirement.req.name = requirement.req.name.lower()
self.requirements.append(requirement.req) self.requirements.append(requirement.req)
......
#!/usr/bin/env python
import json
import sys
def main():
INFILE = sys.argv[1]
with open(INFILE, 'rb') as f:
lockfile = json.load(f)
packages = []
for package in lockfile.get('default', {}):
try:
packages.append('{0}{1}'.format(package, lockfile['default'][package]['version']))
except KeyError:
pass
print('\n'.join(packages))
try:
main()
except Exception:
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment