66import textwrap
77
88from os .path import abspath , dirname , join as pjoin
9- from distutils .command .build import build
10- from setuptools .command .develop import develop
11- from setuptools .command .bdist_egg import bdist_egg
12- from setuptools import setup , Extension
9+ from distutils .command import build
1310
11+ #-----------------------------------------------------------------------------
12+ try :
13+ from setuptools import setup , Extension
14+ from setuptools .command import bdist_egg , develop
15+ except ImportError :
16+ from distutils .core import setup , Extension
17+ from distutils .command import build
18+ develop , bdist_egg = None , None
1419
1520#-----------------------------------------------------------------------------
1621here = abspath (dirname (__file__ ))
4651 'author' : 'Georgi Valkov' ,
4752 'author_email' : 'georgi.t.valkov@gmail.com' ,
4853 'license' : 'Revised BSD License' ,
49-
5054 'keywords' : 'evdev input uinput' ,
51- 'classifiers' : classifiers ,
5255 'url' : 'https://github.com/gvalkov/python-evdev' ,
56+ 'classifiers' : classifiers ,
5357
5458 'packages' : ['evdev' ],
5559 'ext_modules' : [input_c , uinput_c , ecodes_c ],
56-
5760 'include_package_data' : False ,
5861 'zip_safe' : True ,
5962 'cmdclass' : {},
6063}
6164
6265
66+ #-----------------------------------------------------------------------------
6367def create_ecodes ():
64- # :todo: expose as a command option
6568 header = '/usr/include/linux/input.h'
6669
6770 if not os .path .isfile (header ):
@@ -83,27 +86,20 @@ def create_ecodes():
8386 check_call (cmd , cwd = "%s/evdev" % here , shell = True )
8487
8588
86- # :todo: figure out a smarter way to do this
87- # :note: subclassing build_ext doesn't really cut it
88- class BuildCommand ( build ):
89- def run ( self ):
90- create_ecodes ( )
91- build . run ( self )
89+ def cmdfactory ( cmd ):
90+ class cls ( cmd ):
91+ def run ( self ):
92+ create_ecodes ()
93+ cmd . run ( self )
94+ return cls
9295
93- class DevelopCommand (develop ):
94- def run (self ):
95- create_ecodes ()
96- develop .run (self )
96+ #-----------------------------------------------------------------------------
97+ kw ['cmdclass' ]['build' ] = cmdfactory (build .build )
9798
98- class BdistEggCommand (bdist_egg ):
99- def run (self ):
100- create_ecodes ()
101- bdist_egg .run (self )
99+ if develop and bdist_egg :
100+ kw ['cmdclass' ]['develop' ] = cmdfactory (develop .develop )
101+ kw ['cmdclass' ]['bdist_egg' ] = cmdfactory (bdist_egg .bdist_egg )
102102
103103#-----------------------------------------------------------------------------
104- kw ['cmdclass' ]['build' ] = BuildCommand
105- kw ['cmdclass' ]['develop' ] = DevelopCommand
106- kw ['cmdclass' ]['bdist_egg' ] = BdistEggCommand
107-
108104if __name__ == '__main__' :
109105 setup (** kw )
0 commit comments