Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.

Commit 3844a34

Browse files
committed
Fallback to distutils if setuptools is not available.
1 parent 0dd4236 commit 3844a34

2 files changed

Lines changed: 27 additions & 26 deletions

File tree

doc/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
Development
5+
^^^^^^^^^^^^^^^^^^^^
6+
7+
- Fallback to distutils if setuptools is not available.
8+
49
0.4.6 (Oct 07, 2014)
510
^^^^^^^^^^^^^^^^^^^^
611

setup.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
import textwrap
77

88
from 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
#-----------------------------------------------------------------------------
1621
here = abspath(dirname(__file__))
@@ -46,22 +51,20 @@
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+
#-----------------------------------------------------------------------------
6367
def 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-
108104
if __name__ == '__main__':
109105
setup(**kw)

0 commit comments

Comments
 (0)