ShedSkin

(Building the package)
(wikify, categorize)
 
(5 intermediate revisions not shown)
Line 3: Line 3:
For more information, check out http://code.google.com/p/shedskin/
For more information, check out http://code.google.com/p/shedskin/
-
On a simple test I could see a speed improvement of up to 18 times.
+
On a simple test I could see a speed improvement of up to 18 times. The great thing is that you can more or less write normal Python and then let ShedSkin convert it to C code, so it can get compiled by gcc.
-
The great thing is, you can more or less write normal python and then let ShedSkin convert it to C code, so it can get compiled by gcc.
+
 
-
To see an application which uses Shedskin, have a look in SleepAnalyser. It has one file "mylib.py" which gets normal imported into the python application. How ever if there is a file mylib.so in the same folder, python will use that one.
+
To see an application which uses Shedskin, have a look in SleepAnalyser. It has one file <code>mylib.py</code> which gets normal imported into the Python application. How ever if there is a file <code>mylib.so</code> in the same folder, Python will use that one.
 +
 
 +
== Example ==
 +
As an example how to use ShedSkin for [[Open development/Maemo roadmap/Fremantle|Maemo 5]], have a look on sleepanalyser > 1.7.
== How to start ==  
== How to start ==  
-
You might have built your python package with one of the nice tools like PyPacker. But as you now have to edit the debian files, you will have to use scratchbox.
+
You might have built your Python package with one of the nice tools like PyPacker. But as you now have to edit the debian files, you will have to use Scratchbox.
-
Install scratchbox as described in http://wiki.maemo.org/Documentation/Maemo_5_Final_SDK_Installation .
+
Install scratchbox as described in [[Documentation/Maemo 5 Final SDK Installation|the documentation]].
-
Then install Shedskin with "apt-get install shedskin" from the Extras-Devel repository.
+
Then install Shedskin with "apt-get install shedskin" from the [[extras-devel]] repository.
There is also a good tutorial of how to use it: http://shedskin.googlecode.com/files/shedskin-tutorial-0.6.html .
There is also a good tutorial of how to use it: http://shedskin.googlecode.com/files/shedskin-tutorial-0.6.html .
== Building the package ==
== Building the package ==
-
If you already have the .tar.gz file, then you already have the structure with the files. Just unpack the .tar.gz file into a folder.
+
=== Preparations ===
-
If you have to pack it for the first time, MohammadAG has a good page about how to generate the needed files: http://wiki.maemo.org/User:Mohammad7410/Packaging
+
If you already have the .tar.gz file, then you already have the structure with the files. Just unpack the .tar.gz file into a folder. If you have to pack it for the first time, MohammadAG has a good page about how to generate the needed files: [[User:Mohammad7410/Packaging]]
   
   
Now in the debian folder, you will have to modify some files:
Now in the debian folder, you will have to modify some files:
Line 23: Line 26:
'''control:'''
'''control:'''
-
Behind the line "Build-Depends:" you have to add "shedskin". This is needed, so the autobuilder knows he has to install it.
+
Behind the line "<code>Build-Depends:</code>" you have to add "<code>shedskin</code>". This is needed, so the autobuilder knows he has to install it.
-
You might also have to add some normal dependencies like "libgc1c2" and "libpcre" behind the line with "Depends:".
+
You might also have to add some normal dependencies like "<code>libgc1c2</code>" and "<code>libpcre</code>" behind the line with "<code>Depends:</code>".
'''rules:'''
'''rules:'''
-
Under the line with "install: build" should be many lines with "mkdir" and "cp -a". After the last one of them, add those two lines:
+
Under the line with "install: build" should be many lines with "<code>mkdir</code>" and "<code>cp -a</code>". After the last one of them, add those two lines:
-
  cd debian/PATH_TO_mylib.py/; /usr/bin/shedskin -e mylib.py
+
cd debian/PATH_TO_mylib.py/; /usr/bin/shedskin -e mylib.py
-
  cd debian/PATH_TO_mylib.py/opt/SleepAnalyser/lib/; make
+
cd debian/PATH_TO_mylib.py/opt/SleepAnalyser/lib/; make
Where mylib.py is the python file you wnat to get compiled into a C module.
Where mylib.py is the python file you wnat to get compiled into a C module.
-
PATH_TO_mylib.py is usually the same folder as the other python files are in, or mayby you put them into a subfolder /lib.
+
<code>PATH_TO_mylib.py</code> is usually the same folder as the other python files are in, or maybe you put them into a subfolder <code>/lib</code>.
-
== How to use it with the autobuilder ==
+
=== Packing ===
-
First of all, try to test it on your device with the deb-package generated in scratchbox.
+
Now you are ready to pack and upload the package. In Scratchbox, type the command
-
Do not forget to change the architecture to ARMEL, else it will not run:
+
dpkg-buildpackage -rfakeroot -sa -S
 +
This will create the files you need to upload. Alternatively, you can also use the command
 +
dpkg-buildpackage -sa -rfakeroot -kEMAILADRESS
 +
This will also compile it and generate a deb file, which you then can test on the phone. I suggest to do it that way. If Scratchbox can build the package, the the autobuilder will most likely be able to do it as well. But before you can do that, you have to set the compile rtarget to <code>armel</code>. Do that with the command
   sb-conf se FREMANTLE_ARMEL
   sb-conf se FREMANTLE_ARMEL
-
  dpkg-buildpackage -sa -rfakeroot -k<my email address>
+
inside Scratchbox.
 +
 
 +
== Check for missing dependencies ==
 +
The generated module is dependent on some other modules. When you have the module on your phone or in Scratchbox, you can see the dependencies with <code>ldd</code>:
 +
<pre>
 +
ldd
 +
      libgc.so.1 => not found
 +
      libpcre.so.3 => /usr/lib/libpcre.so.3 (0x40053000)
 +
      libpthread.so.0 => /lib/libpthread.so.0 (0x40079000)
 +
      libdl.so.2 => /lib/libdl.so.2 (0x4009a000)
 +
      libutil.so.1 => /lib/libutil.so.1 (0x400a5000)
 +
      libpython2.5.so.1.0 => /usr/lib/libpython2.5.so.1.0 (0x400b0000)
 +
      libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x401d4000)
 +
      libm.so.6 => /lib/libm.so.6 (0x402b7000)
 +
      libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x4032d000)
 +
      libc.so.6 => /lib/libc.so.6 (0x40340000)
 +
      /lib/ld-linux.so.3 (0x2a000000)
 +
</pre>
-
== Missing depencies ==
+
There you also will see if a dependency is missing and you have to add it to your package. In the above example you can see that <code>libgc</code> is missing, so you should add it as a dependency to your application.
-
The generated module is dependant on some other modules.
+
-
When you have the module on your phone or in scratchbox, you can see the dependencies with ldd:
+
-
  ldd
+
-
        libgc.so.1 => not found
+
-
        libpcre.so.3 => /usr/lib/libpcre.so.3 (0x40053000)
+
-
        libpthread.so.0 => /lib/libpthread.so.0 (0x40079000)
+
-
        libdl.so.2 => /lib/libdl.so.2 (0x4009a000)
+
-
        libutil.so.1 => /lib/libutil.so.1 (0x400a5000)
+
-
        libpython2.5.so.1.0 => /usr/lib/libpython2.5.so.1.0 (0x400b0000)
+
-
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x401d4000)
+
-
        libm.so.6 => /lib/libm.so.6 (0x402b7000)
+
-
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x4032d000)
+
-
        libc.so.6 => /lib/libc.so.6 (0x40340000)
+
-
        /lib/ld-linux.so.3 (0x2a000000)
+
-
There you also will see if a dependency is missing and you have to add it to your package. In the above example you can see that libgc is missing, so you should add it as a dependency to your application.
+
[[Category:Development]]
 +
[[Category:Python]]

Latest revision as of 09:12, 25 November 2010

Shed Skin is an experimental compiler, that can translate pure, but implicitly statically typed Python programs into optimized C++. It can generate stand-alone programs or extension modules that can be imported and used in larger Python programs.

For more information, check out http://code.google.com/p/shedskin/

On a simple test I could see a speed improvement of up to 18 times. The great thing is that you can more or less write normal Python and then let ShedSkin convert it to C code, so it can get compiled by gcc.

To see an application which uses Shedskin, have a look in SleepAnalyser. It has one file mylib.py which gets normal imported into the Python application. How ever if there is a file mylib.so in the same folder, Python will use that one.

Contents

[edit] Example

As an example how to use ShedSkin for Maemo 5, have a look on sleepanalyser > 1.7.

[edit] How to start

You might have built your Python package with one of the nice tools like PyPacker. But as you now have to edit the debian files, you will have to use Scratchbox.

Install scratchbox as described in the documentation. Then install Shedskin with "apt-get install shedskin" from the extras-devel repository.

There is also a good tutorial of how to use it: http://shedskin.googlecode.com/files/shedskin-tutorial-0.6.html .

[edit] Building the package

[edit] Preparations

If you already have the .tar.gz file, then you already have the structure with the files. Just unpack the .tar.gz file into a folder. If you have to pack it for the first time, MohammadAG has a good page about how to generate the needed files: User:Mohammad7410/Packaging

Now in the debian folder, you will have to modify some files:

control:

Behind the line "Build-Depends:" you have to add "shedskin". This is needed, so the autobuilder knows he has to install it.

You might also have to add some normal dependencies like "libgc1c2" and "libpcre" behind the line with "Depends:".


rules:

Under the line with "install: build" should be many lines with "mkdir" and "cp -a". After the last one of them, add those two lines:

cd debian/PATH_TO_mylib.py/; /usr/bin/shedskin -e mylib.py
cd debian/PATH_TO_mylib.py/opt/SleepAnalyser/lib/; make

Where mylib.py is the python file you wnat to get compiled into a C module. PATH_TO_mylib.py is usually the same folder as the other python files are in, or maybe you put them into a subfolder /lib.

[edit] Packing

Now you are ready to pack and upload the package. In Scratchbox, type the command

dpkg-buildpackage -rfakeroot -sa -S

This will create the files you need to upload. Alternatively, you can also use the command

dpkg-buildpackage -sa -rfakeroot -kEMAILADRESS

This will also compile it and generate a deb file, which you then can test on the phone. I suggest to do it that way. If Scratchbox can build the package, the the autobuilder will most likely be able to do it as well. But before you can do that, you have to set the compile rtarget to armel. Do that with the command

 sb-conf se FREMANTLE_ARMEL

inside Scratchbox.

[edit] Check for missing dependencies

The generated module is dependent on some other modules. When you have the module on your phone or in Scratchbox, you can see the dependencies with ldd:

ldd
      libgc.so.1 => not found
      libpcre.so.3 => /usr/lib/libpcre.so.3 (0x40053000)
      libpthread.so.0 => /lib/libpthread.so.0 (0x40079000)
      libdl.so.2 => /lib/libdl.so.2 (0x4009a000)
      libutil.so.1 => /lib/libutil.so.1 (0x400a5000)
      libpython2.5.so.1.0 => /usr/lib/libpython2.5.so.1.0 (0x400b0000)
      libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x401d4000)
      libm.so.6 => /lib/libm.so.6 (0x402b7000)
      libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x4032d000)
      libc.so.6 => /lib/libc.so.6 (0x40340000)
      /lib/ld-linux.so.3 (0x2a000000)

There you also will see if a dependency is missing and you have to add it to your package. In the above example you can see that libgc is missing, so you should add it as a dependency to your application.