Skip to content
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

Allow the return of combined IDs for multi-id xpaths. #155

Merged
merged 12 commits into from
Oct 10, 2024
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
fetch-depth: 1

- name: Install Java # for pyNeuroML
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '15'
distribution: 'temurin'
java-version: '21'

- name: Install Perl # for BioNetGen
run: |
Expand All @@ -53,7 +53,7 @@ jobs:
sudo apt-get install -y --no-install-recommends wget make gcc libx11-dev libc6-dev xppaut

- name: Install Singularity # to validate that the Docker image can be converted into a Singularity image
uses: eWaterCycle/setup-singularity@v5
uses: eWaterCycle/setup-singularity@v7
with:
singularity-version: 3.7.1

Expand All @@ -67,15 +67,15 @@ jobs:
run: poetry run python -m flake8

- name: Run the tests
uses: GabrielBB/xvfb-action@v1
uses: coactions/setup-xvfb@v1
env:
MPLBACKEND: PDF
# BIOSIMULATORS_API_ENDPOINT: https://api.biosimulators.dev/ # uncomment to execute tests with the dev deployment
with:
run: poetry run python -m pytest tests/ --cov=./biosimulators_utils --cov-report=xml

- name: Upload the coverage report to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
Expand Down
2 changes: 1 addition & 1 deletion biosimulators_utils/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.2'
__version__ = '0.2.3'
17 changes: 15 additions & 2 deletions biosimulators_utils/sedml/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1715,14 +1715,16 @@ def validate_target(target, namespaces, context, language, model_id, model_etree
return errors, warnings


def validate_target_xpaths(targets, model_etree, attr='id'):
def validate_target_xpaths(targets, model_etree, attr='id', separator=None):
""" Validate that the target of each model change or variable matches one object in
an XML-encoded model and, optionally, return the value of one of its attributes
an XML-encoded model and, optionally, return the value of one of its attributes.

Args:
targets (:obj:`list` of :obj:`TargetGroupMixin`): model changes or variables
model_source (:obj:`lxml.etree._ElementTree`): element tree for the XML model document
attr (:obj:`str`, optional): attribute to get values of
separator (:obj:`str`, optional): string to use when combining attributes into a single id
(i.e. 'J0.n' from 'J0' and 'n'.) If None, don't combine and just use final id.

Returns:
:obj:`dict` of :obj:`str` to :obj:`str`: dictionary that maps each XPath to the
Expand All @@ -1736,6 +1738,17 @@ def validate_target_xpaths(targets, model_etree, attr='id'):
x_path, _, _ = x_path.rpartition('/@')
x_path_attrs[target.target] = validate_xpaths_ref_to_unique_objects(
model_etree, [x_path], target.target_namespaces, attr=attr)[x_path]
if separator is None:
return x_path_attrs
for xpath in x_path_attrs:
xpath_list = xpath.split("@" + attr + "=")
if len(xpath_list) < 3:
continue
combined_id = ""
for i in range(1, len(xpath_list)-1):
combined_id = combined_id + xpath_list[i].split(']')[0][1:-1] + separator
x_path_attrs[xpath] = combined_id + x_path_attrs[xpath]

return x_path_attrs


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "biosimulators-utils"
version = "0.2.2"
version = "0.2.3"
description = "description"
license = "MIT"
authors = ["Center for Reproducible Biomedical Modeling <[email protected]>"]
Expand Down
Loading
Loading