[Biopython-dev] Build & Test

Peter biopython at maubp.freeserve.co.uk
Thu Oct 28 16:36:31 UTC 2010


On Thu, Oct 28, 2010 at 5:24 PM, Dragoslav Zaric
<zaricdragoslav at gmail.com> wrote:
> Hi Peter,
>
> To bring me up to speed for build&test process, can I ask you how
> exactly this process should go.
>
> For example if I put this in setup.py file:
>
> class build_ext_biopython(build_ext):
>    def run(self):
>        if not check_dependencies_once():
>            return
>        if is_Numpy_installed():
>            import numpy
>            numpy_include_dir = numpy.get_include()
>            self.extensions.append(
>                Extension('Bio.Motif._pwm',
>                          ["Bio/Motif/_pwm.c"],
>                          include_dirs=[numpy_include_dir],
>                          ))
>        build_ext.run(self)
>
> what command I should run from command line to build and test:
>
> python3.1 setup.py build
> or/and
> python3.1 setup.py install
>
> After this I will have folder build/lib/Bio, so should I go to folder build/lib
> and start python3.1 to test this, or after python3.1 setup.py install it is
> copied to root folder.

You can do this:

python3.1 setup,py build
python3.1 setup.py test

and it should use the compiled C code from the build folder.
This is equivalent to:

python3.1 setup,py build
cd Tests
python3.1 run_tests.py

The advantage of calling run_tests.py directly is you can test particular
bits of Biopython rather than all of it, e.g.

python3.1 setup,py build
cd Tests
python3.1 run_tests.py test_Motif.py

If you try and run a test directly (e.g. python3.31 test_Motif.py) then
in will use the installed version of Biopython (and it will fail if you
haven't installed Biopython).

> Also after building I will have -pwm.so file, is this final file that
> is imported from python code ?
>
> Currently i can import Seq and Motif but when I run
>
> m.scanPWM(Seq.Seq("ACGTGTGCGTAGTGCGT",m.alphabet))
>
> I get:
>
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "Bio/Motif/_Motif.py", line 778, in scanPWM
>    import _pwm
> ImportError: No module named _pwm
>

On Python 2.6 (on my Mac) I have these files:

$ ls build/lib.macosx-10.6-universal-2.6/Bio/Motif/
Applications   Thresholds.py  _Motif.py      __init__.py    _pwm.so
Parsers        Thresholds.pyc _Motif.pyc     __init__.pyc

Trying to import _pwm will load the _pwm.so file.

It sounds like you were able to compile _pwm.so under
Python 3, but it doesn't import. Is your _pwm.c file still
using Py_InitModule4 or have you changed it to something
Python 3 compatible yet like PyModule_Create?

[It may not have been clear to you earlier, but porting
Python C extensions from Python 2 to Python 3 requires
quite a lot of background knowledge about Python, C,
compiling, and so on. I hope this wasn't too ambitious.]

Regards,

Peter




More information about the Biopython-dev mailing list