Skip to content

Commit

Permalink
Merge pull request #377 from betatim/escape-me
Browse files Browse the repository at this point in the history
[MRG] Escape environment variable when using Python string formatting
  • Loading branch information
minrk authored Aug 20, 2018
2 parents 9cb14b4 + a1df2eb commit bf312ab
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion repo2docker/buildpacks/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def get_assemble_scripts(self):
if os.path.exists(nb_requirements_file):
assemble_scripts.append((
'${NB_USER}',
'${NB_PYTHON_PREFIX}/bin/pip install --no-cache-dir -r "{}"'.format(nb_requirements_file)
# want the $NB_PYHTON_PREFIX environment variable, not for
# Python's string formatting to try and replace this
'${{NB_PYTHON_PREFIX}}/bin/pip install --no-cache-dir -r "{}"'.format(nb_requirements_file)
))

# install requirements.txt in the kernel env
Expand Down
2 changes: 2 additions & 0 deletions tests/venv/py2-with-kernel-requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# install this in the kernel's environment, the user wants Python 2 there
numpy
3 changes: 3 additions & 0 deletions tests/venv/py2-with-kernel-requirements/requirements3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# install this in the environment in which the notebook server
# is running nbgitpuller does not work with Python 2
nbgitpuller==0.6.1
1 change: 1 addition & 0 deletions tests/venv/py2-with-kernel-requirements/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-2.7
19 changes: 19 additions & 0 deletions tests/venv/py2-with-kernel-requirements/verify
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python2
import os
import sys

print(sys.version_info)
assert sys.version_info[:2] == (2, 7)

import numpy

try:
import nbgitpuller
except ImportError:
pass
else:
raise Exception("'nbgitpuller' shouldn't have been installed from requirements3.txt")

# Python 3 is the executable used for the notebook server, this should
# have nbgitpuller installed
os.system("python3 -c 'import nbgitpuller'")

0 comments on commit bf312ab

Please sign in to comment.