Implementing module name parsing with os.path.
authorDan Miller <dnmiller@gmail.com>
Sat, 17 Nov 2012 04:54:55 +0000 (20:54 -0800)
committerDan Miller <dnmiller@gmail.com>
Sat, 17 Nov 2012 04:54:55 +0000 (20:54 -0800)
bin/cython_freeze

index 2702ce7..74f3656 100755 (executable)
@@ -7,6 +7,7 @@ See Demos/freeze/README.txt for more details.
 """
 
 import optparse
+from os.path import splitext, basename
 
 usage= '%prog [-o outfile] [-p] module [module ...]'
 description = 'Create a C file for embedding Cython modules.'
@@ -27,14 +28,7 @@ if options.output:
     old_stdout = sys.stdout
     sys.stdout = open(options.output, 'w')
 
-def format_modname(name):
-    if name.endswith('.pyx'):
-        name = name[:-4]
-    elif name.endswith('.py'):
-        name = name[:-3]
-    return name.replace('.','_')
-
-modules = [format_modname(x) for x in args]
+modules = [basename(splitext(x)[0]).replace('.', '_') for x in args]
 
 print """\
 #include <Python.h>