Skip to content

Commit 52fe390

Browse files
committed
Add support of pipenv packaging tool
Pipenv, the higher-level Python packaging tool can be used to manage application dependencies on user demand. Pipenv and its dependecies are sandboxed so they cannot conflict with neither system packages nor application dependencies. Resolves sclorg#214.
1 parent e546d35 commit 52fe390

36 files changed

Lines changed: 919 additions & 27 deletions

File tree

2.7/README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ a `.s2i/environment` file inside your source code repository.
105105
106106
Set this variable to use a custom index URL or mirror to download required packages
107107
during build process. This only affects packages listed in requirements.txt.
108+
Pipenv ignores this variable.
108109
109110
* **UPGRADE_PIP_TO_LATEST**
110111
@@ -113,6 +114,14 @@ a `.s2i/environment` file inside your source code repository.
113114
before any Python packages are installed. If not set it will use whatever
114115
the default version is included by the platform for the Python version being used.
115116
117+
* **ENABLE_PIPENV**
118+
119+
Set this variable to use [Pipenv](https://github.com/kennethreitz/pipenv),
120+
the higher-level Python packaging tool, to manage dependencies of the application.
121+
This should be used only if your project contains properly formated Pipfile
122+
and Pipfile.lock. (Implies `UPGRADE_PIP_TO_LATEST` to satisfy dependencies of
123+
Pipenv.)
124+
116125
* **WEB_CONCURRENCY**
117126
118127
Set this to change the default setting for the number of
@@ -131,14 +140,22 @@ However, if these files exist they will affect the behavior of the build process
131140
[here](https://pip.pypa.io/en/latest/user_guide.html#requirements-files).
132141
133142
143+
* **Pipfile**
144+
145+
The replacement for requirements.txt, project is currently under active
146+
design and development, as documented [here](https://github.com/pypa/pipfile).
147+
Set `ENABLE_PIPENV` environment variable to true in order to process this file.
148+
149+
134150
* **setup.py**
135151
136152
Configures various aspects of the project, including installation of
137153
dependencies, as documented
138154
[here](https://packaging.python.org/en/latest/distributing.html#setup-py).
139-
For most projects, it is sufficient to simply use `requirements.txt`, if this
140-
file is present `setup.py` is not processed by default, please use `-e .` to
141-
trigger its processing from the requirements.txt file.
155+
For most projects, it is sufficient to simply use `requirements.txt` or
156+
`Pipfile`, if one of these files is present `setup.py` is not processed
157+
by default, please use `-e .` to trigger its processing from above mentioned
158+
files.
142159
143160
144161
Run strategies

2.7/s2i/bin/assemble

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,41 @@ function should_collectstatic() {
88
is_django_installed && [[ -z "$DISABLE_COLLECTSTATIC" ]]
99
}
1010

11+
# Install pipenv to the separate virtualenv to isolate it
12+
# from system Python packages and packages in the main
13+
# virtualenv. Executable is simlinked into ~/.local/bin
14+
# to be accessible. This approach is inspired by pipsi
15+
# (pip script installer).
16+
function install_pipenv() {
17+
echo "---> Installing pipenv packaging tool ..."
18+
VENV_DIR=$HOME/.local/venvs/pipenv
19+
virtualenv $VENV_DIR
20+
$VENV_DIR/bin/pip --isolated install -U pipenv
21+
mkdir -p $HOME/.local/bin
22+
ln -s $VENV_DIR/bin/pipenv $HOME/.local/bin/pipenv
23+
}
24+
1125
set -e
1226

1327
shopt -s dotglob
1428
echo "---> Installing application source ..."
1529
mv /tmp/src/* ./
1630

17-
if [[ ! -z "$UPGRADE_PIP_TO_LATEST" ]]; then
31+
if [[ ! -z "$UPGRADE_PIP_TO_LATEST" || ! -z "$ENABLE_PIPENV" ]]; then
1832
echo "---> Upgrading pip to latest version ..."
1933
pip install -U pip setuptools wheel
2034
fi
2135

22-
if [[ -f requirements.txt ]]; then
36+
if [[ ! -z "$ENABLE_PIPENV" ]]; then
37+
install_pipenv
38+
echo "---> Installing dependencies via pipenv ..."
39+
if [[ -f Pipfile ]]; then
40+
pipenv install --deploy
41+
elif [[ -f requirements.txt ]]; then
42+
pipenv install -r requirements.txt
43+
fi
44+
pipenv check
45+
elif [[ -f requirements.txt ]]; then
2346
echo "---> Installing dependencies ..."
2447
pip install -r requirements.txt
2548
elif [[ -f setup.py ]]; then
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
env/
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
26+
# PyInstaller
27+
# Usually these files are written by a python script from a template
28+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
29+
*.manifest
30+
*.spec
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
36+
# Unit test / coverage reports
37+
htmlcov/
38+
.tox/
39+
.coverage
40+
.coverage.*
41+
.cache
42+
nosetests.xml
43+
coverage.xml
44+
*,cover
45+
46+
# Translations
47+
*.mo
48+
*.pot
49+
50+
# Django stuff:
51+
*.log
52+
53+
# Sphinx documentation
54+
docs/_build/
55+
56+
# PyBuilder
57+
target/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ENABLE_PIPENV=true

2.7/test/pipenv-test-app/Pipfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[source]]
2+
url = "https://pypi.python.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
"e1839a8" = {path = ".", editable = true}
8+
requests = "==2.17.0"
9+
10+
[dev-packages]
11+
pytest = ">=2.8.0"
12+
13+
[requires]
14+
python_version = "2.7"

2.7/test/pipenv-test-app/Pipfile.lock

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2.7/test/pipenv-test-app/setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from setuptools import setup, find_packages
2+
3+
4+
setup (
5+
name = "testapp",
6+
version = "0.1",
7+
description = "Example application to be deployed.",
8+
packages = find_packages(),
9+
install_requires = ["gunicorn"],
10+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import requests
2+
3+
4+
def application(environ, start_response):
5+
start_response('200 OK', [('Content-Type', 'text/plain')])
6+
assert requests.__version__ == '2.17.0'
7+
return [b"Hello from gunicorn WSGI application!"]

2.7/test/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
IMAGE_NAME=${IMAGE_NAME:-centos/python-27-centos7-candidate}
1010

11-
declare -a WEB_APPS=({standalone,setup,setup-requirements,django,numpy,app-home,npm-virtualenv-uwsgi,locale,mod-wsgi}-test-app)
11+
declare -a WEB_APPS=({standalone,setup,setup-requirements,django,pipenv,numpy,app-home,npm-virtualenv-uwsgi,locale,mod-wsgi}-test-app)
1212

1313
# TODO: Make command compatible for Mac users
1414
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"

3.4/README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ file inside your source code repository.
105105
106106
Set this variable to use a custom index URL or mirror to download required packages
107107
during build process. This only affects packages listed in requirements.txt.
108+
Pipenv ignores this variable.
108109
109110
* **UPGRADE_PIP_TO_LATEST**
110111
@@ -113,6 +114,14 @@ file inside your source code repository.
113114
before any Python packages are installed. If not set it will use whatever
114115
the default version is included by the platform for the Python version being used.
115116
117+
* **ENABLE_PIPENV**
118+
119+
Set this variable to use [Pipenv](https://github.com/kennethreitz/pipenv),
120+
the higher-level Python packaging tool, to manage dependencies of the application.
121+
This should be used only if your project contains properly formated Pipfile
122+
and Pipfile.lock. (Implies `UPGRADE_PIP_TO_LATEST` to satisfy dependencies of
123+
Pipenv.)
124+
116125
* **WEB_CONCURRENCY**
117126
118127
Set this to change the default setting for the number of
@@ -131,14 +140,22 @@ However, if these files exist they will affect the behavior of the build process
131140
[here](https://pip.pypa.io/en/latest/user_guide.html#requirements-files).
132141
133142
143+
* **Pipfile**
144+
145+
The replacement for requirements.txt, project is currently under active
146+
design and development, as documented [here](https://github.com/pypa/pipfile).
147+
Set `ENABLE_PIPENV` environment variable to true in order to process this file.
148+
149+
134150
* **setup.py**
135151
136152
Configures various aspects of the project, including installation of
137153
dependencies, as documented
138154
[here](https://packaging.python.org/en/latest/distributing.html#setup-py).
139-
For most projects, it is sufficient to simply use `requirements.txt`, if this
140-
file is present `setup.py` is not processed by default, please use `-e .` to
141-
trigger its processing from the requirements.txt file.
155+
For most projects, it is sufficient to simply use `requirements.txt` or
156+
`Pipfile`, if one of these files is present `setup.py` is not processed
157+
by default, please use `-e .` to trigger its processing from above mentioned
158+
files.
142159
143160
144161
Run strategies

0 commit comments

Comments
 (0)