Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pymoose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]
python-version: [3.7, 3.8, 3.9, '3.10']

steps:
- uses: actions/checkout@v2
Expand Down
45 changes: 0 additions & 45 deletions python/moose/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from __future__ import absolute_import

import types
import parser
import token
import symbol
import math
from datetime import datetime
from collections import defaultdict
Expand Down Expand Up @@ -225,49 +223,6 @@ def apply_to_tree(moose_wildcard, python_filter=None, value=None):
)


def tweak_field(moose_wildcard, field, assignment_string):
"""Tweak a specified field of all objects that match the
moose_wildcard using assignment string. All identifiers in
assignment string must be fields of the target object.

Example:

tweak_field('/mycell/##[Class=Compartment]', 'Rm', '1.5 / (3.1416 * diameter * length')

will assign Rm to every compartment in mycell such that the
specific membrane resistance is 1.5 Ohm-m2.
"""
if not isinstance(moose_wildcard, str):
raise TypeError("moose_wildcard must be a string.")
id_list = moose.getWildcardList(moose_wildcard, True)
expression = parser.expr(assignment_string)
expr_list = expression.tolist()
# This is a hack: I just tried out some possible syntax trees and
# hand coded the replacement such that any identifier is replaced
# by moose_obj.identifier
def replace_fields_with_value(x):
if len(x) > 1:
if (
x[0] == symbol.power
and x[1][0] == symbol.atom
and x[1][1][0] == token.NAME
):
field = x[1][1][1]
x[1] = [symbol.atom, [token.NAME, "moose_obj"]]
x.append([symbol.trailer, [token.DOT, "."], [token.NAME, field]])
for item in x:
if isinstance(item, list):
replace_fields_with_value(item)
return x

tmp = replace_fields_with_value(expr_list)
new_expr = parser.sequence2st(tmp)
code = new_expr.compile()
for moose_id in id_list:
moose_obj = eval("moose.%s(moose_id)" % (moose.Neutral(moose_id).className))
value = eval(code)
moose.setField(moose_id, field, str(value))


# 2012-01-11 19:20:39 (+0530) Subha: checked for compatibility with dh_branch
def printtree(root, vchar="|", hchar="__", vcount=1, depth=0, prefix="", is_last=False):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

numCores_ = multiprocessing.cpu_count()

version_ = '3.3.0.dev%s' % stamp
version_ = '4.0.0.dev%s' % stamp

# importlib is available only for python3. Since we build wheels, prefer .so
# extension. This way a wheel built by any python3.x will work with any python3.
Expand Down