sugarlabs / Pippy

Pippy allows the student to examine, execute, and modify simple Python programs. In addition it is possible to write Python statements to play sounds, calculate expressions, or make simple text based interactive games.
GNU General Public License v2.0
11 stars 35 forks source link

Rename notebook.py: conflicts with Jupyter #45

Closed icarito closed 7 years ago

quozl commented 7 years ago

We are wasting our time changing file names and imports to avoid system packages. It is a never-ending task, and impossible to avoid future conflict. There is an underlying problem; the import path resolution for a Sugar activity is wrong.

An interactive Python session or Python script run from a command line do not show a conflict; the local module or file is used rather than the system package. Something is different between the normal Python environment and the environment of an activity within Sugar.

Other examples where we have been doing this are;

So can we instead investigate and fix the underlying problem in Sugar or the toolkit?

Here is sys.path at the start of the Activity.__init__ method:

[
'/usr/bin',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/share/sugar/activities/Maze.activity',
]

Here is sys.path in an interactive Python shell started from the Terminal activity bash prompt;

[
'',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
]

Comparing them we get;

--- INTERACTIVE   2017-03-27 17:23:16.238006463 +1100
+++ ACTIVITY      2017-03-27 17:23:31.701887135 +1100
@@ -1,5 +1,5 @@
 [
-'', 
+'/usr/bin', 
 '/usr/lib/python2.7', 
 '/usr/lib/python2.7/plat-x86_64-linux-gnu', 
 '/usr/lib/python2.7/lib-tk', 
@@ -9,4 +9,5 @@
 '/usr/lib/python2.7/dist-packages', 
 '/usr/lib/python2.7/dist-packages/gst-0.10', 
 '/usr/lib/python2.7/dist-packages/gtk-2.0', 
+'/usr/share/sugar/activities/Maze.activity', 
 ]

Why is the first element of sys.path changed from '' to /usr/bin? Is it because we now call every activity through /usr/bin/sugar-activity?

Why is the activity directory added to the end of sys.path, and not the beginning? See line 117 of bin/sugar-activity

Would it be more correct for sugar-activity to replace /usr/bin/ with the bundle path rather than add the bundle path to the end?

icarito commented 7 years ago

Great! This PR is rendered unnecessary by @quozl 's patch at https://github.com/sugarlabs/sugar-toolkit-gtk3/pull/363