Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
BUGFIX: Extending PYTHONPATH to fix local imports (#863)
Browse files Browse the repository at this point in the history
* BUGFIX: Adding PYTHONPATH to fix local imports

TODO: necessary for 2.7? How do we test that this is ok
with respect to the mount point?

* Revert "BUGFIX: Adding PYTHONPATH to fix local imports"

This reverts commit 6da1fba.

* fix: Extending PYTHONPATH to contain user files

* fixup -- wrong usage of string.Join

* Extending deps example/test to import foo from a local file

* fixup

* Deploy zip instead of deploying single python file

* fixup path

* fixup

* Fix handler name in test setup

* Changing command so it zips w/o folder
  • Loading branch information
alexander-alvarez authored and andresmgot committed Jul 30, 2018
1 parent f83503c commit 8beda89
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion examples/Makefile
Expand Up @@ -15,7 +15,8 @@ get-python-update-verify:
kubeless function call get-python |egrep hello.world.updated

get-python-deps:
kubeless function deploy get-python-deps --runtime python2.7 --handler helloget.foo --from-file python/hellowithdeps.py --dependencies python/requirements.txt
cd python && zip hellowithdeps.zip hellowithdeps.py hellowithdepshelper.py && cd ..
kubeless function deploy get-python-deps --runtime python2.7 --handler hellowithdeps.foo --from-file python/hellowithdeps.zip --dependencies python/requirements.txt

get-python-deps-verify:
kubeless function call get-python-deps |egrep Google
Expand Down
8 changes: 1 addition & 7 deletions examples/python/hellowithdeps.py
@@ -1,7 +1 @@
from bs4 import BeautifulSoup
import urllib2

def foo(event, context):
page = urllib2.urlopen("https://www.google.com/").read()
soup = BeautifulSoup(page, 'html.parser')
return soup.title.string
from hellowithdepshelper import foo
7 changes: 7 additions & 0 deletions examples/python/hellowithdepshelper.py
@@ -0,0 +1,7 @@
from bs4 import BeautifulSoup
import urllib2

def foo(event, context):
page = urllib2.urlopen("https://www.google.com/").read()
soup = BeautifulSoup(page, 'html.parser')
return soup.title.string
3 changes: 2 additions & 1 deletion pkg/langruntime/langruntime.go
Expand Up @@ -291,9 +291,10 @@ func (l *Langruntimes) GetBuildContainer(runtime, depsChecksum string, env []v1.
func (l *Langruntimes) UpdateDeployment(dpm *v1beta1.Deployment, depsPath, runtime string) {
switch {
case strings.Contains(runtime, "python"):
pythonPaths := []string{path.Join(depsPath, "lib/python"+l.getVersionFromRuntime(runtime)+"/site-packages"), depsPath}
dpm.Spec.Template.Spec.Containers[0].Env = append(dpm.Spec.Template.Spec.Containers[0].Env, v1.EnvVar{
Name: "PYTHONPATH",
Value: path.Join(depsPath, "lib/python"+l.getVersionFromRuntime(runtime)+"/site-packages"),
Value: strings.Join(pythonPaths, ":"),
})
case strings.Contains(runtime, "nodejs"):
dpm.Spec.Template.Spec.Containers[0].Env = append(dpm.Spec.Template.Spec.Containers[0].Env, v1.EnvVar{
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/kubelessutil_test.go
Expand Up @@ -538,7 +538,7 @@ func TestEnsureDeployment(t *testing.T) {
},
{
Name: "PYTHONPATH",
Value: "/kubeless/lib/python2.7/site-packages",
Value: "/kubeless/lib/python2.7/site-packages:/kubeless",
},
},
VolumeMounts: []v1.VolumeMount{
Expand Down

0 comments on commit 8beda89

Please sign in to comment.