Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5932ddd

Browse files
committed
Add a pkg_path option to add_sconcript.
This is necessary to handle some cases where scons scripts and packages are not in the same directory.
1 parent db41933 commit 5932ddd

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

numpy/distutils/command/scons.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,15 @@ def finalize_options(self):
427427
self.pre_hooks = []
428428
self.post_hooks = []
429429
self.pkg_names = []
430+
self.pkg_paths = []
430431

431432
if self.distribution.has_scons_scripts():
432433
for i in self.distribution.scons_data:
433434
self.sconscripts.append(i.scons_path)
434435
self.pre_hooks.append(i.pre_hook)
435436
self.post_hooks.append(i.post_hook)
436437
self.pkg_names.append(i.parent_name)
438+
self.pkg_paths.append(i.pkg_path)
437439
# This crap is needed to get the build_clib
438440
# directory
439441
build_clib_cmd = get_cmd("build_clib").get_finalized_command("build_clib")
@@ -467,7 +469,7 @@ def finalize_options(self):
467469
if self.package_list:
468470
self.package_list = parse_package_list(self.package_list)
469471

470-
def _call_scons(self, scons_exec, sconscript, pkg_name, bootstrapping):
472+
def _call_scons(self, scons_exec, sconscript, pkg_name, pkg_path, bootstrapping):
471473
# XXX: when a scons script is missing, scons only prints warnings, and
472474
# does not return a failure (status is 0). We have to detect this from
473475
# distutils (this cannot work for recursive scons builds...)
@@ -483,6 +485,7 @@ def _call_scons(self, scons_exec, sconscript, pkg_name, bootstrapping):
483485
cmd.append("inplace=1")
484486
cmd.append('scons_tool_path="%s"' % self.scons_tool_path)
485487
cmd.append('src_dir="%s"' % pdirname(sconscript))
488+
cmd.append('pkg_path="%s"' % pkg_path)
486489
cmd.append('pkg_name="%s"' % pkg_name)
487490
cmd.append('log_level=%s' % self.log_level)
488491
#cmd.append('distutils_libdir=%s' % protect_path(pjoin(self.build_lib,
@@ -553,11 +556,13 @@ def run(self):
553556
pre_hooks = [self.pre_hooks[i] for i in id]
554557
post_hooks = [self.post_hooks[i] for i in id]
555558
pkg_names = [self.pkg_names[i] for i in id]
559+
pkg_paths = [self.pkg_names[i] for i in id]
556560
else:
557561
sconscripts = self.sconscripts
558562
pre_hooks = self.pre_hooks
559563
post_hooks = self.post_hooks
560564
pkg_names = self.pkg_names
565+
pkg_paths = self.pkg_paths
561566

562567
if is_bootstrapping():
563568
bootstrapping = 1
@@ -567,14 +572,14 @@ def run(self):
567572
scons_exec = get_python_exec_invoc()
568573
scons_exec += ' ' + protect_path(pjoin(get_scons_local_path(), 'scons.py'))
569574

570-
for sconscript, pre_hook, post_hook, pkg_name in zip(sconscripts,
575+
for sconscript, pre_hook, post_hook, pkg_name, pkg_path in zip(sconscripts,
571576
pre_hooks, post_hooks,
572-
pkg_names):
577+
pkg_names, pkg_paths):
573578
if pre_hook:
574579
pre_hook()
575580

576581
if sconscript:
577-
self._call_scons(scons_exec, sconscript, pkg_name, bootstrapping)
582+
self._call_scons(scons_exec, sconscript, pkg_name, pkg_path, bootstrapping)
578583

579584
if post_hook:
580585
post_hook(**{'pkg_name': pkg_name, 'scons_cmd' : self})

numpy/distutils/misc_util.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,12 +592,19 @@ def get_frame(level=0):
592592

593593
class SconsInfo(object):
594594
def __init__(self, scons_path, parent_name, pre_hook,
595-
post_hook, source_files):
595+
post_hook, source_files, pkg_path):
596596
self.scons_path = scons_path
597597
self.parent_name = parent_name
598598
self.pre_hook = pre_hook
599599
self.post_hook = post_hook
600600
self.source_files = source_files
601+
if pkg_path:
602+
self.pkg_path = pkg_path
603+
else:
604+
if scons_path:
605+
self.pkg_path = os.path.dirname(scons_path)
606+
else:
607+
self.pkg_path = ''
601608

602609
######################
603610

@@ -1526,7 +1533,7 @@ def add_scons_installed_library(self, name, install_dir):
15261533

15271534
def add_sconscript(self, sconscript, subpackage_path=None,
15281535
standalone = False, pre_hook = None,
1529-
post_hook = None, source_files = None):
1536+
post_hook = None, source_files = None, package_path=None):
15301537
"""Add a sconscript to configuration.
15311538
15321539
pre_hook and post hook should be sequences of callable, which will be
@@ -1553,7 +1560,7 @@ def add_sconscript(self, sconscript, subpackage_path=None,
15531560

15541561
scons_info = SconsInfo(fullsconsname, parent_name,
15551562
pre_hook, post_hook,
1556-
full_source_files)
1563+
full_source_files, package_path)
15571564
if dist is not None:
15581565
dist.scons_data.append(scons_info)
15591566
self.warn('distutils distribution has been initialized,'\

0 commit comments

Comments
 (0)