mirror of
https://github.com/kennethreitz/heroku-buildpack-python.git
synced 2026-06-05 15:00:19 +00:00
Pipenv uninstall, and other improvements (#650)
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# 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
|
||||
|
||||
Set `PYTHONPATH` during collectstatic runs, other updates.
|
||||
|
||||
+8
-13
@@ -100,12 +100,6 @@ export PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/li
|
||||
# Switch to the repo's context.
|
||||
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.
|
||||
mkdir -p "$CACHE_DIR"
|
||||
|
||||
@@ -166,7 +160,14 @@ mtime "python.install.time" "${start}"
|
||||
|
||||
# Pipenv support.
|
||||
# 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 [ ! -f requirements.txt ] && [ ! -f Pipfile ]; then
|
||||
@@ -197,12 +198,6 @@ sub_env "$BIN_DIR/steps/geo-libs"
|
||||
# shellcheck source=bin/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).
|
||||
let start=$(nowms)
|
||||
# shellcheck source=bin/steps/pip-install
|
||||
|
||||
+13
-8
@@ -2,19 +2,24 @@
|
||||
|
||||
set +e
|
||||
# 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
|
||||
|
||||
cp .heroku/python/requirements-declared.txt requirements-declared.txt
|
||||
if [[ -f .heroku/python/requirements-declared.txt ]]; then
|
||||
|
||||
pip-diff --stale requirements-declared.txt requirements.txt --exclude setuptools pip wheel > .heroku/python/requirements-stale.txt
|
||||
cp .heroku/python/requirements-declared.txt requirements-declared.txt
|
||||
|
||||
rm -fr requirements-declared.txt
|
||||
pip-diff --stale requirements-declared.txt requirements.txt --exclude setuptools pip wheel > .heroku/python/requirements-stale.txt
|
||||
|
||||
if [[ -s .heroku/python/requirements-stale.txt ]]; then
|
||||
puts-step "Uninstalling stale dependencies"
|
||||
/app/.heroku/python/bin/pip uninstall -r .heroku/python/requirements-stale.txt -y --exists-action=w | cleanup | indent
|
||||
rm -fr requirements-declared.txt
|
||||
|
||||
if [[ -s .heroku/python/requirements-stale.txt ]]; then
|
||||
puts-step "Uninstalling stale dependencies"
|
||||
/app/.heroku/python/bin/pip uninstall -r .heroku/python/requirements-stale.txt -y --exists-action=w | cleanup | indent
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
set -e
|
||||
|
||||
Regular → Executable
+64
-33
@@ -5,41 +5,72 @@
|
||||
# shellcheck source=bin/utils
|
||||
source $BIN_DIR/utils
|
||||
|
||||
# Pipenv support (Generate requriements.txt with pipenv).
|
||||
if [[ -f Pipfile ]]; then
|
||||
if [[ ! -f requirements.txt ]]; then
|
||||
puts-step "Installing requirements with latest Pipenv…"
|
||||
|
||||
# Measure that we're using Pipenv.
|
||||
mcount "tool.pipenv"
|
||||
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
|
||||
|
||||
# Set PIP_EXTRA_INDEX_URL
|
||||
if [[ -r $ENV_DIR/PIP_EXTRA_INDEX_URL ]]; then
|
||||
PIP_EXTRA_INDEX_URL="$(cat "$ENV_DIR/PIP_EXTRA_INDEX_URL")"
|
||||
export PIP_EXTRA_INDEX_URL
|
||||
SKIP_PIPENV_INSTALL=1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Install pipenv.
|
||||
/app/.heroku/python/bin/pip install pipenv --upgrade &> /dev/null
|
||||
|
||||
# Install the dependencies.
|
||||
if [[ ! -f Pipfile.lock ]]; then
|
||||
/app/.heroku/python/bin/pipenv install --system --skip-lock 2>&1 | indent
|
||||
else
|
||||
/app/.heroku/python/bin/pipenv install --system --deploy 2>&1 | indent
|
||||
fi
|
||||
|
||||
# Install the test dependencies, for CI.
|
||||
if [ "$INSTALL_TEST" ]; then
|
||||
puts-step "Installing test dependencies…"
|
||||
/app/.heroku/python/bin/pipenv install --dev --system --deploy 2>&1 | cleanup | indent
|
||||
fi
|
||||
|
||||
# Skip pip install, later.
|
||||
export SKIP_PIP_INSTALL=1
|
||||
|
||||
# Pip freeze, for compatibility.
|
||||
/app/.heroku/python/bin/pip freeze > requirements.txt
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ ! "$SKIP_PIPENV_INSTALL" ]; then
|
||||
|
||||
# Pipenv support (Generate requriements.txt with pipenv).
|
||||
if [[ -f Pipfile ]]; then
|
||||
if [[ ! -f requirements.txt ]]; then
|
||||
puts-step "Installing requirements with latest Pipenv…"
|
||||
|
||||
# Measure that we're using Pipenv.
|
||||
mcount "tool.pipenv"
|
||||
|
||||
# Set PIP_EXTRA_INDEX_URL
|
||||
if [[ -r $ENV_DIR/PIP_EXTRA_INDEX_URL ]]; then
|
||||
PIP_EXTRA_INDEX_URL="$(cat "$ENV_DIR/PIP_EXTRA_INDEX_URL")"
|
||||
export PIP_EXTRA_INDEX_URL
|
||||
fi
|
||||
|
||||
# if [[ -f .heroku/python/requirements-declared.txt ]]; then
|
||||
# cp .heroku/python/requirements-declared.txt requirements.txt
|
||||
# fi
|
||||
|
||||
# Install pipenv.
|
||||
/app/.heroku/python/bin/pip install pipenv --upgrade &> /dev/null
|
||||
|
||||
# Install the dependencies.
|
||||
if [[ ! -f Pipfile.lock ]]; then
|
||||
/app/.heroku/python/bin/pipenv install --system --skip-lock 2>&1 | indent
|
||||
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
|
||||
fi
|
||||
|
||||
# Install the test dependencies, for CI.
|
||||
if [ "$INSTALL_TEST" ]; then
|
||||
puts-step "Installing test dependencies…"
|
||||
/app/.heroku/python/bin/pipenv install --dev --system --deploy 2>&1 | cleanup | indent
|
||||
fi
|
||||
|
||||
# Skip pip install, later.
|
||||
export SKIP_PIP_INSTALL=1
|
||||
|
||||
# Pip freeze, for compatibility.
|
||||
pip freeze > requirements.txt
|
||||
fi
|
||||
fi
|
||||
else
|
||||
pipenv-to-pip Pipfile.lock > requirements.txt
|
||||
export SKIP_PIP_INSTALL=1
|
||||
fi
|
||||
|
||||
Vendored
+1
@@ -41,6 +41,7 @@ class Requirements(object):
|
||||
if not getattr(requirement.req, 'name', None):
|
||||
# Prior to pip 8.1.2 the attribute `name` did not exist.
|
||||
requirement.req.name = requirement.req.project_name
|
||||
requirement.req.name = requirement.req.name.lower()
|
||||
self.requirements.append(requirement.req)
|
||||
|
||||
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user