Received: by 10.42.80.3 with SMTP id t3mr2430256ick.24.1349310953666; Wed, 03 Oct 2012 17:35:53 -0700 (PDT) X-BeenThere: cython-users@googlegroups.com Received: by 10.42.98.148 with SMTP id s20ls5052483icn.6.gmail; Wed, 03 Oct 2012 17:35:51 -0700 (PDT) Received: by 10.43.115.73 with SMTP id fd9mr2353527icc.2.1349310951424; Wed, 03 Oct 2012 17:35:51 -0700 (PDT) Received: by 10.43.115.73 with SMTP id fd9mr2353526icc.2.1349310951409; Wed, 03 Oct 2012 17:35:51 -0700 (PDT) Return-Path: Received: from mail-ie0-f182.google.com (mail-ie0-f182.google.com [209.85.223.182]) by gmr-mx.google.com with ESMTPS id s15si603521igi.1.2012.10.03.17.35.51 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 03 Oct 2012 17:35:51 -0700 (PDT) Received-SPF: pass (google.com: domain of rober...@gmail.com designates 209.85.223.182 as permitted sender) client-ip=209.85.223.182; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of rober...@gmail.com designates 209.85.223.182 as permitted sender) smtp.mail=rober...@gmail.com; dkim=pass header...@gmail.com Received: by mail-ie0-f182.google.com with SMTP id k10so19294677iea.41 for ; Wed, 03 Oct 2012 17:35:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=kXvmHXAaWtgwakfKTro8ghaJTeNNi0t8ysiU8xKl00g=; b=0bpC5QGxZkiOKCjxbdCWbK2Cq6E4cImkQ3PBaZdW0F8xFsv7CCQgsyq2o++55aA28n VSNG5J1vsdTmud6ibnrQzcwy9T4b8Xy2BMEO849regcD9xaA4eD96BYYGs776dEoaKFT ZeFizrCV1yueDU2Voa98EO9ypOw0spjiHjmhs6ta74Vd/9NgvcaGOnibO2/2iPTITTqX 0rr3ii8N7GFBuVyduKPM7CJ8yJAQRA4aTS6wEWcfVb0AsCeikJwbHl1giN9cYlsG2JBn igN7FXLi80Y40EnvpCsiWFZKTXFeoBky3BJD03QXCU6H3MCvpDR9mgwMV+LseFzKBR1A HmLQ== Received: by 10.50.150.144 with SMTP id ui16mr3626923igb.68.1349310951310; Wed, 03 Oct 2012 17:35:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.75.234 with HTTP; Wed, 3 Oct 2012 17:35:21 -0700 (PDT) In-Reply-To: References: From: Robert Bradshaw Date: Wed, 3 Oct 2012 17:35:21 -0700 Message-ID: Subject: Re: [cython-users] run-time vs. compile time import paths. To: cython-users@googlegroups.com Content-Type: text/plain; charset=UTF-8 On Wed, Oct 3, 2012 at 5:27 PM, Chris Barker wrote: > On Wed, Oct 3, 2012 at 2:14 PM, Robert Bradshaw wrote: > >>>> (https://github.com/cython/cython/blob/master/Cython/Compiler/Options.py#L66 >>>> might be of interest as well.) > > OK -- that shows the option: > > # Allows cimporting from a pyx file without a pxd file. > cimport_from_pyx = False > > Which looks like a great idea. However: > > 1) how do you change that option -- treating it like compiler > directive, either with: > > #cython: cimport_from_pyx=False > > or passing it in on the comamnd line: > > cython --cplus -X cimport_from_pyx=True multi_rectangle.pyx > > > did not work. > > So I changed it in the Options.py file directly. But I'd rather not > make that a global change! > > After that, Cython now gets psat the cipmport statement, no longer > with the error tha the *.pxd can not be found. But it doesn't seem to > work either. That's why it's not easy to turn on yet :-P. You can set it manually in a setup.py by importing Cython.Compiler.Options, but it's not something I'd worry about at this point. Thanks for the example, I'll take a look. > I borrowed an example from the Wiki, and am adding to it, so in > rectangle.pyx, I have: > > cdef class Rectangle: > cdef c_Rectangle *thisptr # hold a C++ instance which we're wrapping > def __cinit__(self, int x0, int y0, int x1, int y1): > self.thisptr = new_Rectangle(x0, y0, x1, y1) > .... > (and so on) > > > Then in multi_rectangle.pyx, I put: > > > from rectangle cimport Rectangle > ... > def addRect(self, Rectangle rect): > """ > add a rectangle object -- this will only take a rectangle object > """ > > self.rectangles.append(rect) > ... > > But I get: > > > def addRect(self, Rectangle rect): > ^ > ------------------------------------------------------------ > > multi_rectangle.pyx:24:22: 'Rectangle' is not a type identifier > > > so something isn't working. > > I've enclosed the whole package if anyone wants to take a look. > > Thanks, > -Chris > > > -- > > Christopher Barker, Ph.D. > Oceanographer > > Emergency Response Division > NOAA/NOS/OR&R (206) 526-6959 voice > 7600 Sand Point Way NE (206) 526-6329 fax > Seattle, WA 98115 (206) 526-6317 main reception > > Chris.Bar...@noaa.gov