Skip to content

Commit

Permalink
Merge pull request LudovicRousseau#20 from ccpost/fix/pip-install
Browse files Browse the repository at this point in the history
Fix LudovicRousseau#15 - installing from `pip` and `easy_install`
  • Loading branch information
LudovicRousseau committed Mar 27, 2016
2 parents f793225 + 41ca7d1 commit 9277d45
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
"""

from distutils.util import get_platform
import distutils.command.install as install_orig
import inspect
import sys

from setuptools import setup, Extension
from setuptools.command.bdist_egg import bdist_egg
from setuptools.command.install import install


if sys.version_info[0:2] < (2, 6):
Expand Down Expand Up @@ -83,6 +87,35 @@
VERSION_ALT = '%i,%01i,%01i,%04i' % VERSION_INFO


# Workaround for `pip install` and direct `setup.py install`
class InstallBuildExtFirst(install):
"""Workaround substitute `install` command"""
def run(self):
# Run built_ext first so that SWIG generated files are included
self.run_command("build_ext")
# Copy the rest of the logic from setuptools install so that the
# stack frame logic is preserved

# Explicit request for old-style install? Just do it
if self.old_and_unmanageable or self.single_version_externally_managed:
return install_orig.install.run(self)

if not self._called_from_setup(inspect.currentframe()):
# Run in backward-compatibility mode to support bdist_* commands.
install_orig.install.run(self)
else:
self.do_egg_install()


# Workaround for `easy_install`
class BdistEggBuildExtFirst(bdist_egg):
"""Workaround substitute `bdist_egg` command"""
def run(self):
# Run build_ext first so that SWIG generated files are included
self.run_command("build_ext")
return bdist_egg.run(self)


kw = {'name': "pyscard",
'version': VERSION_STR,
'description': "Smartcard module for Python.",
Expand All @@ -106,6 +139,10 @@
"smartcard/wx": ["resources/*.ico"],
},

'cmdclass': {
'install': InstallBuildExtFirst,
'bdist_egg': BdistEggBuildExtFirst,
},
# the _scard.pyd extension to build
'ext_modules': [Extension("smartcard.scard._scard",
define_macros=[
Expand Down

0 comments on commit 9277d45

Please sign in to comment.