Magnus Lie Hetland, 17.09.2009 21:02: > why would it need to find > the package to do the compilation?
Because it needs to know the package layout in order to find related modules and .pxd files at compile time and runtime. That doesn't mean it couldn't potentially look for the module.pxd file in the same directory as the .py or .pyx file. It just means that it needs to know the final package hierarchy. > If there's a .pxd file in the same > directory as the .py(x) file, couldn't that be enough? Even in Python 3, the equivalent isn't enough. In that case, you'd have to import ".module" for a relative import. > 1. I'd like to automate the process of finding compilable files, so I > don't have to manually update my setup.py file all the time. > Previously, I globbed for .pyx files You may consider looking for .pxd files instead and compiling the .py files with the same name. Or you can just try to compile everything and ignore errors. > (because I'm forced to > use .py files to get cython to compile pure Python mode correctly, it > seems) "correctly" is not the right wording here. The Cython language is different from the Python language. Cython can compile both, but that doesn't mean you can use file extensions interchangeably. Renaming ".py" to ".c" doesn't magically translate your Python code to C code, either. > I can't do that. So I need some way of discerning Cython > source files from Python files. I thought I'd keep the Python files in > the actual package hierarchy (where they belong), and the Cython > source somewhere else, putting the .so files in the package hierarchy > (where they, too, belong). You can do that, but you still need to keep them in the correct package hierarchy. Just use separate source directories for them. Note that you can also use __init__.pyx instead of __init__.py, which might help here. > 2. I'm just using standard mechanisms for installing, and Distutils > will happily install the Cython source files (with .py endings) > alongside the corresponding .so files. I don't really want this, > although it doesn't hurt ... except it makes me a bit uneasy to think > that there's a chance that the .py file will be imported instead of > the .so file. Not sure if there's a clearly documented Python behavior > here? Not "Python behaviour", but CPython loads .so files before .py files. Plus, having the .py file next to the .so makes it easier for users to look up the code, so that's actually a feature. > 3. I'd like to be able to run tests and so forth in two ways -- one > interpreting the Cython .py files (for coverage, among other things) > and one using the .so files. Now, that's a good reason to use .py instead of .pyx, don't you think? > Haven't thought through exactly how I'll > implement this, but it seems it'll be easier to tell Python what to > import if the (compiled) .py files and their .so files aren't in the > same directory. Then don't install your code and keep the sources in separate source directories. Setting the PYTHONPATH appropriately will do the trick. Or, you can keep them in the same directory and compile the code only after running the coverage tests. Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
