Skip to content

Commit

Permalink
Merge pull request #21 from ccpost/fix/pip-install-take-two
Browse files Browse the repository at this point in the history
Fix #15 - installing from `pip` and `easy_install` (Take 2)
  • Loading branch information
LudovicRousseau committed Mar 28, 2016
2 parents defecae + 0f59ade commit 087c8f2
Showing 1 changed file with 6 additions and 38 deletions.
44 changes: 6 additions & 38 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
"""

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
from setuptools.command.build_py import build_py


if sys.version_info[0:2] < (2, 6):
Expand Down Expand Up @@ -87,38 +84,12 @@
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)

try:
have_called_from_setup = self._called_from_setup is not None
except AttributeError:
have_called_from_setup = False

if not have_called_from_setup or 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"""
class BuildPyBuildExtFirst(build_py):
"""Workaround substitude `build_py` command for SWIG"""
def run(self):
# Run build_ext first so that SWIG generated files are included
self.run_command("build_ext")
return bdist_egg.run(self)
self.run_command('build_ext')
return build_py.run(self)


kw = {'name': "pyscard",
Expand All @@ -144,10 +115,7 @@ def run(self):
"smartcard/wx": ["resources/*.ico"],
},

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

0 comments on commit 087c8f2

Please sign in to comment.