Browse files

Rearranged dirs for easily running tests; switched to setuptools.

The rearrangement is based on the package structure for PyEphem.

To run tests without installing the package, I can now run

  python setup-devel.py test

and if Nose is installed then

  python setup-devel.py nosetests

The same applies to setup.py.

Distutils doesn't recognize the test or nosetests commands, mentioned
above. Setuptools does have test command and a nosetests command.
But unfortunately setuptools doesn't run Cython on the name.pyx file and
thereby converting it into name.c file. To get setuptools to recognize
Cython, I added the fake_pyrex module from the lxml project. See
comments in the setup*py files for more information.

The test files are also specifed as a sub-module of the package. They
are available as the module pytpm.tests.

Running the tests will create a directory pytpm-egg.info, which was added
to .gitignore.

1. Instead of lib, the main package directory is pytpm.
2. The test directory was copied into pytpm dir and renamed tests
3. The pytpm/tests dir was converted into a package with a dummy
   __init__.py
4. Changed distutils to setuptools.
5. Added fake_pyrex from the lxml project.
6. Changed setup.py and setup-devel.py to reflect the new directory
   structure.
7. Added the test_suite setup option.
  • Loading branch information...
1 parent e4dc805 commit 058202ffe656b1f48987f0391c097f934b171eba @phn committed Mar 16, 2011
View
3 .gitignore
@@ -9,4 +9,5 @@ doc/_build/
*_exe
pytpm-ghpages.rst
.ropeproject/
-setup.cfg
+setup.cfg
+*.egg-info
View
1 fake_pyrex/Pyrex/Distutils/__init__.py
@@ -0,0 +1 @@
+# work around broken setuptools monkey patching
View
1 fake_pyrex/Pyrex/Distutils/build_ext.py
@@ -0,0 +1 @@
+build_ext = "yes, it's there!"
View
1 fake_pyrex/Pyrex/__init__.py
@@ -0,0 +1 @@
+# work around broken setuptools monkey patching
View
0 lib/__init__.py → pytpm/__init__.py
File renamed without changes.
View
0 pytpm/tests/__init__.py
No changes.
View
0 test/test_pytpm_times.py → pytpm/tests/test_pytpm_times.py
File renamed without changes.
View
27 setup-devel.py
@@ -1,9 +1,22 @@
-from distutils.core import setup
-from distutils.extension import Extension
-from Cython.Distutils import build_ext
+#from distutils.core import setup
+#from distutils.extension import Extension
+import sys
import glob
import os
+# For some reason setuptools.setup does not run Cython on *.pyx
+# files and convert it into a *.c. From the discussion at
+# http://www.velocityreviews.com/forums/
+# t693861-cython-setuptools-not-working-with-pyx-only-with-c-files.html
+# I found out that the lxml proect has created a fake_pyrex module
+# that can fix this issue. The fake_pyrex module in this directory
+# was copied from http://pypi.python.org/packages/source/l/lxml/
+# lxml-2.3.tar.gz#md5=a245a015fd59b63e220005f263e1682a.
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "fake_pyrex"))
+
+from setuptools import setup, Extension
+from Cython.Distutils import build_ext
+
# While developing code, I do not want to re-build the tpm library
# every time I make changes to source code. So instead of compiling
# Cython and TPM code into a single module, link to the libtpm.a
@@ -40,11 +53,13 @@
# pytpm/__init__.py
# pytpm/tpm.so
# pytpm/*.py
-# pytpm/*
+# pytpm/tests/
+# pytpm/doc/
+# and so on.
setup(
name = "pytpm",
version = "0.4dev",
cmdclass = {'build_ext': build_ext},
- packages = ['pytpm'],
- package_dir = {'pytpm': 'lib'},
+ packages = ['pytpm','pytpm.tests'],
+ test_suite = "pytpm.tests",
ext_modules = ext_modules)
View
30 setup.py
@@ -1,9 +1,22 @@
-from distutils.core import setup
-from distutils.extension import Extension
-from Cython.Distutils import build_ext
+# from distutils.core import setup
+# from distutils.extension import Extension
+import sys
import glob
import os
+# For some reason setuptools.setup does not run Cython on *.pyx
+# files and convert it into a *.c. From the discussion at
+# http://www.velocityreviews.com/forums/
+# t693861-cython-setuptools-not-working-with-pyx-only-with-c-files.html
+# I found out that the lxml proect has created a fake_pyrex module
+# that can fix this issue. The fake_pyrex module in this directory
+# was copied from http://pypi.python.org/packages/source/l/lxml/
+# lxml-2.3.tar.gz#md5=a245a015fd59b63e220005f263e1682a.
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "fake_pyrex"))
+
+from setuptools import setup, Extension
+from Cython.Distutils import build_ext
+
srcfiles = glob.glob("src/tpm/*.c")
# This is the command line TPM program.
srcfiles.remove("src/tpm/tpm_main.c")
@@ -14,18 +27,21 @@
depends.extend(glob.glob("src/tpm/*.h")) # Just in case.
include_dirs = [os.path.abspath("src/tpm")]
-ext_modules = [Extension("pytpm.tpm", srcfiles, include_dirs = include_dirs,
+ext_modules = [Extension("pytpm.tpm", srcfiles,
+ include_dirs = include_dirs,
depends = depends)]
# Package structure is
# pytpm/__init__.py
# pytpm/tpm.so
# pytpm/*.py
-# pytpm/*
+# pytpm/tests/
+# pytpm/doc/
+# and so on.
setup(
name = "pytpm",
version = "0.4dev",
cmdclass = {'build_ext': build_ext},
- packages = ['pytpm'],
- package_dir = {'pytpm': 'lib'},
+ packages = ['pytpm','pytpm.tests'],
+ test_suite = "pytpm.tests",
ext_modules = ext_modules)

0 comments on commit 058202f

Please sign in to comment.