Skip to content

Commit 9350013

Browse files
author
uri.akavia
committed
fixed some errors, fixed setup.cfg, tox.ini
1 parent eab6a6f commit 9350013

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ where = src
8080
[options.package_data]
8181
cobra =
8282
data/*
83+
io/*.json
8384

8485
[options.extras_require]
8586
array =

src/cobra/io/web/cobrapy_repository.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
class Cobrapy(AbstractModelRepository):
1010
"""
1111
Define a concrete implementation of the cobrapy (local package) repository.
12+
13+
Attributes
14+
----------
15+
name : str
16+
The name of the Cobrapy repository.
1217
"""
1318

19+
name: str = "Cobrapy"
20+
1421
def __init__(
1522
self,
1623
**kwargs,
@@ -40,12 +47,6 @@ def get_sbml(self, model_id: str) -> bytes:
4047
-------
4148
bytes
4249
A gzip-compressed, UTF-8 encoded SBML document.
43-
44-
Raises
45-
------
46-
httpx.HTTPError
47-
In case there are any connection problems.
48-
4950
"""
5051
cobra_data_dir = importlib_resources.files("cobra.data")
5152
model_file = cobra_data_dir.joinpath(f"{model_id}.xml.gz")

src/cobra/io/web/load.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@
2828
def load_model(
2929
model_id: str,
3030
repositories: Iterable[AbstractModelRepository] = (
31+
Cobrapy(),
3132
BiGGModels(),
3233
BioModels(),
33-
Cobrapy(),
3434
),
3535
cache: bool = True,
3636
) -> "Model":
3737
"""
3838
Download an SBML model from a remote repository.
3939
40+
It will try the local repository first.
41+
4042
Downloaded SBML documents are by default stored in a cache on disk such that future
4143
access is much faster. By default, models can be loaded from the following
4244
repositories:
@@ -155,6 +157,11 @@ def _fetch_model(
155157
)
156158
try:
157159
return repository.get_sbml(model_id=model_id)
160+
except FileNotFoundError:
161+
logger.debug(
162+
f"Model '{model_id} not found in the local "
163+
f"repository {repository.name}.'"
164+
)
158165
except httpx.HTTPStatusError as error:
159166
if error.response.status_code == 404:
160167
logger.debug(

tests/test_io/test_json.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Any, Callable, Dict, Union
66

77
import pytest
8-
from importlib_resources import open_text
8+
from importlib_resources import files
99

1010
from cobra import Model
1111
from cobra import io as cio
@@ -14,7 +14,7 @@
1414
@pytest.fixture(scope="module")
1515
def json_schema_v1() -> Dict[str, Union[str, bool, Any]]:
1616
"""Fixture for cobra JSON-schema."""
17-
with open_text(cio, "schema_v1.json") as handle:
17+
with files(cio).joinpath("schema_v1.json").open('r') as handle:
1818
schema_v1 = json.load(handle)
1919
return schema_v1
2020

tests/test_io/test_web/test_load.py

+5
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,8 @@ def test_cache(monkeypatch, tmp_path, bigg_models, biomodels):
7171
biomodels.get_sbml.assert_not_called()
7272
assert len(cached_model.metabolites) == len(remote_model.metabolites)
7373
assert len(cached_model.reactions) == len(remote_model.reactions)
74+
75+
76+
def test_local_load(model, compare_models):
77+
model_local = load_model("textbook")
78+
compare_models(model, model_local)

tox.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ commands=
6868

6969
[pytest]
7070
testpaths =
71-
src/tests
71+
tests
7272
markers =
7373
raises
7474

@@ -81,15 +81,15 @@ source =
8181
branch = true
8282
parallel = true
8383
omit =
84-
*/tests/*
84+
tests/*
8585

8686
[coverage:report]
8787
exclude_lines =
8888
# Have to re-enable the standard pragma
8989
pragma: no cover
9090
precision = 2
9191
omit =
92-
*/tests/*
92+
tests/*
9393

9494
[isort]
9595
skip = __init__.py

0 commit comments

Comments
 (0)