Re: [Sugar-devel] [PATCH sugar-toolkit] Insert activity root path in front of the reset of sys.path

2011-02-12 Thread Sascha Silbe
Excerpts from Martin Langhoff's message of Tue Feb 08 04:46:32 +0100 2011:

 To wit, note the first entry at
 
 $ python
 Python 2.7 (r27:82500, Sep 16 2010, 18:03:06)
[...]
  sys.path
 ['', '/usr/lib/python27.zip', '/usr/lib/python2.7',
[...]

 The behaviour sought by Aleksey's patch makes sense. I am surprised
 that CWD isn't set to SUGAR_BUNDLE_PATH, maybe that needs to get fixed
 instead.

Thanks for disproving my assumption that it's something Python 2.x does
differently and pointing at the actual issue.

I agree that we should either change the working directory or tweak
sys.path, but I'm still a bit worried about compatibility.

Sascha

-- 
http://sascha.silbe.org/
http://www.infra-silbe.de/


signature.asc
Description: PGP signature
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] [PATCH sugar-toolkit] Insert activity root path in front of the reset of sys.path

2011-02-12 Thread Martin Langhoff
On Sat, Feb 12, 2011 at 1:57 PM, Sascha Silbe si...@activitycentral.com wrote:
 The behaviour sought by Aleksey's patch makes sense. I am surprised
 that CWD isn't set to SUGAR_BUNDLE_PATH, maybe that needs to get fixed
 instead.

 Thanks for disproving my assumption that it's something Python 2.x does
 differently and pointing at the actual issue.

 I agree that we should either change the working directory or tweak
 sys.path, but I'm still a bit worried about compatibility.

Hm. AFAICS, when an activity starts under S-0.84 the cwd is set
correctly. I've been debugging an activity that starts from a shell
script (as activities using libsugarize are prone to do) and the
script assumes (correctly) that CWD is the activity directory.

So I am intrigued about Aleksey's patch. Aleksey -- did you prep your
patch in response to an observed behaviour? What was it? Maybe the
problem was misdiagnosed?

cheers,


m
-- 
 martin.langh...@gmail.com
 mar...@laptop.org -- Software Architect - OLPC
 - ask interesting questions
 - don't get distracted with shiny stuff  - working code first
 - http://wiki.laptop.org/go/User:Martinlanghoff
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] [PATCH sugar-toolkit] Insert activity root path in front of the reset of sys.path

2011-02-12 Thread Aleksey Lim
On Sat, Feb 12, 2011 at 02:47:32PM -0500, Martin Langhoff wrote:
 On Sat, Feb 12, 2011 at 1:57 PM, Sascha Silbe si...@activitycentral.com 
 wrote:
  The behaviour sought by Aleksey's patch makes sense. I am surprised
  that CWD isn't set to SUGAR_BUNDLE_PATH, maybe that needs to get fixed
  instead.
 
  Thanks for disproving my assumption that it's something Python 2.x does
  differently and pointing at the actual issue.
 
  I agree that we should either change the working directory or tweak
  sys.path, but I'm still a bit worried about compatibility.
 
 Hm. AFAICS, when an activity starts under S-0.84 the cwd is set
 correctly. I've been debugging an activity that starts from a shell
 script (as activities using libsugarize are prone to do) and the
 script assumes (correctly) that CWD is the activity directory.
 
 So I am intrigued about Aleksey's patch. Aleksey -- did you prep your
 patch in response to an observed behaviour? What was it? Maybe the
 problem was misdiagnosed?

The problem is, if I got it right, that cwd means nothing for searching
modules, only sys.path(and so) makes sense. After launching Python
interpreter, the $0 becomes sys.path[0]. But the problem is that
activities start from sugar-activity command, thus sys.path[0] is
/usr/bin/. So, there is need in adding SUGAR_BUNDLE_PATH to the sys.path
manually (ie simulate Python interpreter behaviour). But existed code
does it wrong (add to the end of sys.path).

 
 cheers,
 
 
 m
 -- 
  martin.langh...@gmail.com
  mar...@laptop.org -- Software Architect - OLPC
  - ask interesting questions
  - don't get distracted with shiny stuff  - working code first
  - http://wiki.laptop.org/go/User:Martinlanghoff
 ___
 Sugar-devel mailing list
 Sugar-devel@lists.sugarlabs.org
 http://lists.sugarlabs.org/listinfo/sugar-devel
 

-- 
Aleksey
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] [PATCH sugar-toolkit] Insert activity root path in front of the reset of sys.path

2011-02-12 Thread Martin Langhoff
On Sat, Feb 12, 2011 at 6:57 PM, Aleksey Lim
alsr...@activitycentral.org wrote:
 The problem is, if I got it right, that cwd means nothing for searching
 modules, only sys.path(and so) makes sense. After launching Python
 interpreter, the $0 becomes sys.path[0]. But the problem is that
 activities start from sugar-activity command, thus sys.path[0] is
 /usr/bin/. So, there is need in adding SUGAR_BUNDLE_PATH to the sys.path
 manually (ie simulate Python interpreter behaviour). But existed code
 does it wrong (add to the end of sys.path).

OK - so when starting pure Python activities, the shell is never
involved, and we just fork the python interpreter.

In that case, yes, it makes sense to put SUGAR_BUNDLE_PATH in
sys.path[0]. It mimics what Python would normally do.



m
-- 
 martin.langh...@gmail.com
 mar...@laptop.org -- Software Architect - OLPC
 - ask interesting questions
 - don't get distracted with shiny stuff  - working code first
 - http://wiki.laptop.org/go/User:Martinlanghoff
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


[Sugar-devel] [PATCH sugar-toolkit] Insert activity root path in front of the reset of sys.path

2011-02-05 Thread Aleksey Lim
From: Aleksey Lim alsr...@member.fsf.org

Otherwise it is possible to include, eg, system modules before local ones.
---
 src/sugar/activity/main.py |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/sugar/activity/main.py b/src/sugar/activity/main.py
index 10d0031..eee717e 100644
--- a/src/sugar/activity/main.py
+++ b/src/sugar/activity/main.py
@@ -88,7 +88,7 @@ def main():
 sys.exit(1)
 
 bundle_path = os.environ['SUGAR_BUNDLE_PATH']
-sys.path.append(bundle_path)
+sys.path.insert(0, bundle_path)
 
 bundle = ActivityBundle(bundle_path)
 
-- 
1.7.3.4

___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel