From ed36aecf5093c13df92ad8e0eb3608ee81db5b83 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 2 Nov 2010 15:45:00 -0400 Subject: [PATCH] Better pysawsim.sawsim.SAWSIM detection via distutils.spawn.find_executable(). --- pysawsim/parameter_error.py | 3 +-- pysawsim/parameter_scan.py | 5 ++--- pysawsim/sawsim.py | 12 ++++++++---- pysawsim/sawsim_histogram.py | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pysawsim/parameter_error.py b/pysawsim/parameter_error.py index ee915b2..b75b310 100644 --- a/pysawsim/parameter_error.py +++ b/pysawsim/parameter_error.py @@ -80,8 +80,7 @@ def main(argv=None): >>> f = tempfile.NamedTemporaryFile() >>> f.write(EXAMPLE_HISTOGRAM_FILE_CONTENTS) >>> f.flush() - >>> main(['-s', 'bin/sawsim', - ... '-r', '[1e-6,1e-4,3]', '--log', + >>> main(['-r', '[1e-6,1e-4,3]', '--log', ... '-N', '4', '-t', '0.8', ... f.name]) ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF diff --git a/pysawsim/parameter_scan.py b/pysawsim/parameter_scan.py index ff34a44..3d6e99b 100644 --- a/pysawsim/parameter_scan.py +++ b/pysawsim/parameter_scan.py @@ -157,7 +157,7 @@ class HistogramMatcher (object): ... '-s "unfolded,wlc,{0.39e-9,28e-9}" ' ... '-k "folded,unfolded,bell,{%g,%g}" -q folded') >>> m = ThreadManager() - >>> sr = SawsimRunner(sawsim='bin/sawsim', manager=m) + >>> sr = SawsimRunner(manager=m) >>> hm = HistogramMatcher(histogram_stream, param_format_string, sr, N=3) >>> hm.plot([[1e-5,1e-3,3],[0.1e-9,1e-9,3]], logx=True, logy=False) >>> m.teardown() @@ -343,8 +343,7 @@ def main(argv=None): >>> f = tempfile.NamedTemporaryFile() >>> f.write(EXAMPLE_HISTOGRAM_FILE_CONTENTS) >>> f.flush() - >>> main(['-s', 'bin/sawsim', - ... '-r', '[1e-5,1e-3,3],[0.1e-9,1e-9,3]', + >>> main(['-r', '[1e-5,1e-3,3],[0.1e-9,1e-9,3]', ... '-N', '2', ... f.name]) >>> f.close() diff --git a/pysawsim/sawsim.py b/pysawsim/sawsim.py index 4f34da8..0f85869 100644 --- a/pysawsim/sawsim.py +++ b/pysawsim/sawsim.py @@ -27,6 +27,7 @@ try: from collections import namedtuple except ImportError: # work around Python < 2.6 from ._collections import namedtuple +from distutils.spawn import find_executable import hashlib from optparse import Option import os @@ -43,7 +44,10 @@ _multiprocess_can_split_ = True """Allow nosetests to split tests between processes. """ -SAWSIM = 'sawsim' # os.path.expand(os.path.join('~', 'bin', 'sawsim')) +SAWSIM = find_executable('sawsim') +if SAWSIM == None: + SAWSIM = os.path.join('bin', 'sawsim') + CACHE_DIR = os.path.expanduser(os.path.join('~', '.sawsim-cache')) DEFAULT_PARAM_STRING = ( '-s cantilever,hooke,0.05 -N1 ' @@ -62,7 +66,7 @@ Event = namedtuple( class SawsimRunner (object): """ >>> m = get_manager()() - >>> sr = SawsimRunner(sawsim='bin/sawsim', manager=m) + >>> sr = SawsimRunner(manager=m) >>> for run in sr(param_string=DEFAULT_PARAM_STRING, N=2): ... print 'New run' ... for i,event in enumerate(run): @@ -272,11 +276,11 @@ def main(argv=None): Options: -h, --help show this help message and exit -s PATH, --sawsim=PATH - Set sawsim binary (sawsim). + Set sawsim binary (...sawsim). ... >>> print e 0 - >>> main(['--sawsim', 'bin/sawsim', '-N', '2']) + >>> main(['-N', '2']) ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE #Force (N) Initial state Final state ... folded unfolded diff --git a/pysawsim/sawsim_histogram.py b/pysawsim/sawsim_histogram.py index 969ad46..14b94ed 100644 --- a/pysawsim/sawsim_histogram.py +++ b/pysawsim/sawsim_histogram.py @@ -50,7 +50,7 @@ def sawsim_histogram(sawsim_runner, param_string, N=400, bin_edges=None): def main(argv=None): """ - >>> main(['--sawsim', 'bin/sawsim', '-N', '2']) + >>> main(['-N', '2']) ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE #Force (N) Unfolding events ... -- 2.26.2