New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to setuptools #89
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
wheel==0.29.0 | ||
wheel==0.29.0 | ||
setuptools==22.0.5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
SKBUILD_DIR = "_skbuild" | ||
CMAKE_BUILD_DIR = os.path.join(SKBUILD_DIR, "cmake-build") | ||
CMAKE_INSTALL_DIR = os.path.join(SKBUILD_DIR, "cmake-install") | ||
DISTUTILS_INSTALL_DIR = os.path.join(SKBUILD_DIR, "distutils") | ||
SETUPTOOLS_INSTALL_DIR = os.path.join(SKBUILD_DIR, "setuptools") | ||
|
||
RE_FILE_INSTALL = re.compile( | ||
r"""[ \t]*file\(INSTALL DESTINATION "([^"]+)".*"([^"]+)"\).*""") | ||
|
@@ -70,8 +70,7 @@ def __init__(self, **defines): | |
self.platform = get_platform() | ||
|
||
def configure(self, clargs=(), generator_id=None): | ||
"""Calls cmake to generate the makefile (or VS solution, | ||
or XCode project). | ||
"""Calls cmake to generate the Makefile/VS Solution/XCode project. | ||
|
||
Input: | ||
------ | ||
|
@@ -103,24 +102,45 @@ def configure(self, clargs=(), generator_id=None): | |
if not os.path.exists(CMAKE_INSTALL_DIR): | ||
os.makedirs(CMAKE_INSTALL_DIR) | ||
|
||
if not os.path.exists(DISTUTILS_INSTALL_DIR): | ||
os.makedirs(DISTUTILS_INSTALL_DIR) | ||
if not os.path.exists(SETUPTOOLS_INSTALL_DIR): | ||
os.makedirs(SETUPTOOLS_INSTALL_DIR) | ||
|
||
python_version = CMaker.get_python_version() | ||
python_include_dir = CMaker.get_python_include_dir(python_version) | ||
python_library = CMaker.get_python_library(python_version) | ||
|
||
cmd = ['cmake', os.getcwd(), '-G', generator_id, | ||
'-DCMAKE_INSTALL_PREFIX:PATH={0}'.format( | ||
os.path.join(os.getcwd(), CMAKE_INSTALL_DIR)), | ||
'-DPYTHON_EXECUTABLE:FILEPATH=' + sys.executable, | ||
'-DPYTHON_VERSION_STRING:STRING=' + sys.version.split(' ')[0], | ||
'-DPYTHON_INCLUDE_DIR:PATH=' + python_include_dir, | ||
'-DPYTHON_LIBRARY:FILEPATH=' + python_library, | ||
'-DSKBUILD:BOOL=TRUE', | ||
"-DCMAKE_MODULE_PATH:PATH={}".format( | ||
os.path.dirname(__file__) + '/resources/cmake') | ||
] | ||
cwd = os.getcwd() | ||
cmd = ['cmake', cwd, '-G', generator_id] | ||
cmd.extend( | ||
"=".join((cmake_variable, value)) for cmake_variable, value in ( | ||
( | ||
"-DCMAKE_INSTALL_PREFIX:PATH", | ||
os.path.join(cwd, CMAKE_INSTALL_DIR) | ||
), ( | ||
"-DPYTHON_EXECUTABLE:FILEPATH", | ||
sys.executable | ||
), ( | ||
"-DPYTHON_VERSION_STRING:STRING", | ||
sys.version.split(' ')[0] | ||
), ( | ||
"-DPYTHON_INCLUDE_DIR:PATH", | ||
python_include_dir | ||
), ( | ||
"-DPYTHON_LIBRARY:FILEPATH", | ||
python_library | ||
), ( | ||
"-DSKBUILD:BOOL", | ||
"TRUE" | ||
), ( | ||
"-DCMAKE_MODULE_PATH:PATH", | ||
os.path.join( | ||
os.path.dirname(__file__), | ||
"resources", | ||
"cmake" | ||
) | ||
) | ||
) | ||
) | ||
|
||
cmd.extend(clargs) | ||
|
||
|
@@ -151,27 +171,61 @@ def get_python_version(): | |
|
||
return python_version | ||
|
||
@staticmethod | ||
# NOTE(opadron): The try-excepts raise the cyclomatic complexity, but we | ||
# need them for this function. | ||
@staticmethod # noqa: C901: Complexity | ||
def get_python_include_dir(python_version): | ||
# determine python include dir | ||
python_include_dir = sysconfig.get_config_var('INCLUDEPY') | ||
|
||
# if Python.h not found (or python_include_dir is None), try to find a | ||
# suitable include dir | ||
found_python_h = os.path.exists( | ||
os.path.join(python_include_dir, 'Python.h')) | ||
|
||
if python_include_dir is None or not found_python_h: | ||
found_python_h = ( | ||
python_include_dir is not None or | ||
os.path.exists(os.path.join(python_include_dir, 'Python.h')) | ||
) | ||
|
||
candidate_prefixes = [ | ||
os.path.dirname(sysconfig.get_config_var('INCLUDEPY')), | ||
sysconfig.get_config_var('INCLUDEDIR'), | ||
os.path.dirname(sysconfig.get_path('include')), | ||
os.path.dirname(sysconfig.get_path('platinclude')), | ||
os.path.join(sysconfig.get_python_inc(), | ||
".".join(map(str, sys.version_info[:2]))), | ||
sysconfig.get_python_inc() | ||
] | ||
if not found_python_h: | ||
candidate_prefixes = [] | ||
|
||
# NOTE(opadron): these possible prefixes must be guarded against | ||
# AttributeErrors and KeyErrors because they each can throw on | ||
# different platforms or even different builds on the same platform. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the documentation indicate
On Linux, no error:
On MacOSx, no error:
On windows, I expect the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, that particular piece does not need to be guarded. |
||
try: | ||
candidate_prefixes.append( | ||
os.path.dirname(sysconfig.get_config_var('INCLUDEPY'))) | ||
except (AttributeError, KeyError): | ||
pass | ||
|
||
try: | ||
candidate_prefixes.append( | ||
sysconfig.get_config_var('INCLUDEDIR')) | ||
except (AttributeError, KeyError): | ||
pass | ||
|
||
try: | ||
candidate_prefixes.append( | ||
os.path.dirname(sysconfig.get_path('include'))) | ||
except (AttributeError, KeyError): | ||
pass | ||
|
||
try: | ||
candidate_prefixes.append( | ||
os.path.dirname(sysconfig.get_path('platinclude'))) | ||
except (AttributeError, KeyError): | ||
pass | ||
|
||
try: | ||
candidate_prefixes.append( | ||
os.path.join(sysconfig.get_python_inc(), | ||
".".join(map(str, sys.version_info[:2])))) | ||
except (AttributeError, KeyError): | ||
pass | ||
|
||
try: | ||
candidate_prefixes.append(sysconfig.get_python_inc()) | ||
except (AttributeError, KeyError): | ||
pass | ||
|
||
candidate_prefixes = tuple(filter(bool, candidate_prefixes)) | ||
|
||
|
@@ -322,7 +376,7 @@ def make(self, clargs=(), config="Release", source_dir="."): | |
|
||
def install(self): | ||
"""Returns a list of tuples of (install location, file list) to install | ||
via distutils that is compatible with the data_files keyword argument. | ||
via setuptools that is compatible with the data_files keyword argument. | ||
""" | ||
return self._parse_manifest() | ||
|
||
|
@@ -331,3 +385,5 @@ def _parse_manifest(self): | |
"install_manifest.txt") | ||
with open(install_manifest_path, "r") as manifest: | ||
return [_remove_cwd_prefix(path) for path in manifest] | ||
|
||
return [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
try: | ||
from setuptools.command.bdist import bdist as _bdist | ||
except ImportError: | ||
from distutils.command.bdist import bdist as _bdist | ||
|
||
from ..cmaker import SETUPTOOLS_INSTALL_DIR | ||
|
||
|
||
class bdist(_bdist): | ||
def finalize_options(self): | ||
try: | ||
if not self.build_base or self.build_base == 'build': | ||
self.build_base = SETUPTOOLS_INSTALL_DIR | ||
except AttributeError: | ||
pass | ||
_bdist.finalize_options(self) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel | ||
|
||
from ..cmaker import SETUPTOOLS_INSTALL_DIR | ||
|
||
|
||
class bdist_wheel(_bdist_wheel): | ||
def finalize_options(self): | ||
try: | ||
if not self.build_base or self.build_base == 'build': | ||
self.build_base = SETUPTOOLS_INSTALL_DIR | ||
except AttributeError: | ||
pass | ||
_bdist_wheel.finalize_options(self) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
|
||
from distutils.command.build import build as _build | ||
try: | ||
from setuptools.command.build import build as _build | ||
except ImportError: | ||
from distutils.command.build import build as _build | ||
|
||
from .. import cmaker | ||
|
||
|
||
class build(_build): | ||
def finalize_options(self): | ||
if not self.build_base or self.build_base == 'build': | ||
self.build_base = cmaker.DISTUTILS_INSTALL_DIR | ||
try: | ||
if not self.build_base or self.build_base == 'build': | ||
self.build_base = cmaker.SETUPTOOLS_INSTALL_DIR | ||
except AttributeError: | ||
pass | ||
_build.finalize_options(self) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
|
||
from distutils.command.install import install as _install | ||
try: | ||
from setuptools.command.install import install as _install | ||
except ImportError: | ||
from distutils.command.install import install as _install | ||
|
||
from .. import cmaker | ||
|
||
|
||
class install(_install): | ||
def finalize_options(self): | ||
if not self.build_base or self.build_base == 'build': | ||
self.build_base = cmaker.DISTUTILS_INSTALL_DIR | ||
try: | ||
if not self.build_base or self.build_base == 'build': | ||
self.build_base = cmaker.SETUPTOOLS_INSTALL_DIR | ||
except AttributeError: | ||
pass | ||
_install.finalize_options(self) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
"""This module provides functionality for wrapping key components of the | ||
distutils infrastructure. | ||
"""This module provides functionality for wrapping key infrastructure components | ||
from distutils and setuptools. | ||
""" | ||
|
||
import os | ||
import os.path | ||
import sys | ||
import argparse | ||
import distutils.core | ||
|
||
from . import cmaker | ||
from .command import build, install, clean | ||
from .command import build, install, clean, bdist, bdist_wheel | ||
from .exceptions import SKBuildError | ||
|
||
try: | ||
from setuptools import setup as upstream_setup | ||
except ImportError: | ||
from distutils.core import setup as upstream_setup | ||
|
||
|
||
def move_arg(arg, a, b, newarg=None, f=lambda x: x, concatenate_value=False): | ||
"""Moves an argument from a list to b list, possibly giving it a new name | ||
|
@@ -59,19 +63,21 @@ def parse_args(): | |
concatenate_value=True) | ||
dutils, cmake = move_arg('-G', dutils, cmake) | ||
dutils, make = move_arg('-j', dutils, make) | ||
op = os.path | ||
|
||
def absappend(x): | ||
return op.join(op.dirname(op.abspath(sys.argv[0])), x) | ||
absappend = ( | ||
lambda x: os.path.join( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not use lambda here. See 1cd88e7 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JC provided a link in the patch linked: PEP-8 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @blowekamp I see, now. I didn't notice that link. Makes sense to me. |
||
os.path.dirname(os.path.abspath(sys.argv[0])), | ||
x | ||
) | ||
) | ||
|
||
dutils, dutils = move_arg('--egg-base', dutils, dutils, f=absappend) | ||
|
||
return dutils, cmake, make | ||
|
||
|
||
def setup(*args, **kw): | ||
"""This function wraps distutils.core.setup() so that we can run cmake, make, | ||
CMake build, then proceed as usual with a distutils, appending the | ||
"""This function wraps setup() so that we can run cmake, make, | ||
CMake build, then proceed as usual with setuptools, appending the | ||
CMake-generated output as necessary. | ||
""" | ||
sys.argv, cmake_args, make_args = parse_args() | ||
|
@@ -226,6 +232,9 @@ def setup(*args, **kw): | |
cmdclass['build'] = cmdclass.get('build', build.build) | ||
cmdclass['install'] = cmdclass.get('install', install.install) | ||
cmdclass['clean'] = cmdclass.get('clean', clean.clean) | ||
cmdclass['bdist'] = cmdclass.get('bdist', bdist.bdist) | ||
cmdclass['bdist_wheel'] = cmdclass.get( | ||
'bdist_wheel', bdist_wheel.bdist_wheel) | ||
kw['cmdclass'] = cmdclass | ||
|
||
return distutils.core.setup(*args, **kw) | ||
return upstream_setup(*args, **kw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we simply extend the list, I don't think using the join and for loop give us much here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different strokes, I guess. I had hoped this would make the arguments that we're passing easier to read through.