Changeset da63656 in sasmodels for sasmodels/modelinfo.py


Ignore:
Timestamp:
May 4, 2016 11:37:42 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
24d5b30
Parents:
13b99fd (diff), 47e498b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into polydisp

Conflicts:

sasmodels/generate.py
sasmodels/kerneldll.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/modelinfo.py

    r8d62008 rda63656  
    1111from copy import copy 
    1212from os.path import abspath, basename, splitext 
     13import inspect 
    1314 
    1415import numpy as np  # type: ignore 
     
    609610    return isinstance(x, str) 
    610611 
     612 
     613def _find_source_lines(model_info, kernel_module): 
     614    """ 
     615    Identify the location of the C source inside the model definition file. 
     616 
     617    This code runs through the source of the kernel module looking for 
     618    lines that start with 'Iq', 'Iqxy' or 'form_volume'.  Clearly there are 
     619    all sorts of reasons why this might not work (e.g., code commented out 
     620    in a triple-quoted line block, code built using string concatenation, 
     621    or code defined in the branch of an 'if' block), but it should work 
     622    properly in the 95% case, and getting the incorrect line number will 
     623    be harmless. 
     624    """ 
     625    # Check if we need line numbers at all 
     626    if callable(model_info.Iq): 
     627        return None 
     628 
     629    if (model_info.Iq is None 
     630        and model_info.Iqxy is None 
     631        and model_info.form_volume is None): 
     632        return 
     633 
     634    # find the defintion lines for the different code blocks 
     635    source = inspect.getsource(kernel_module) 
     636    for k, v in enumerate(source.split('\n')): 
     637        if v.startswith('Iqxy'): 
     638            model_info._Iqxy_line = k+1 
     639        elif v.startswith('Iq'): 
     640            model_info._Iq_line = k+1 
     641        elif v.startswith('form_volume'): 
     642            model_info._form_volume_line = k+1 
     643 
     644 
    611645def make_model_info(kernel_module): 
    612646    # type: (module) -> ModelInfo 
     
    654688    info.control = getattr(kernel_module, 'control', None) 
    655689    info.hidden = getattr(kernel_module, 'hidden', None) # type: ignore 
     690 
     691    _find_source_lines(info, kernel_module) 
    656692 
    657693    return info 
     
    807843    sesans = None           # type: Optional[Callable[[np.ndarray], np.ndarray]] 
    808844 
     845    # line numbers within the python file for bits of C source, if defined 
     846    _Iqxy_line = 0 
     847    _Iq_line = 0 
     848    _form_volume_line = 0 
     849 
     850 
    809851    def __init__(self): 
    810852        # type: () -> None 
Note: See TracChangeset for help on using the changeset viewer.