Skip to content

Commit a1f6b62

Browse files
committed
update pytest config
1 parent ed88e90 commit a1f6b62

File tree

8 files changed

+211
-52
lines changed

8 files changed

+211
-52
lines changed

docs/conf.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
3-
sys.path.insert(0, os.path.abspath('../src/epidemik/'))
3+
4+
sys.path.insert(0, os.path.abspath("../src/epidemik/"))
45
import epidemik
56

67
# Configuration file for the Sphinx documentation builder.
@@ -11,45 +12,44 @@
1112
# -- Project information -----------------------------------------------------
1213
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
1314

14-
project = 'epidemik'
15-
copyright = '2024, Bruno Gonçalves'
16-
author = 'Bruno Gonçalves'
15+
project = "epidemik"
16+
copyright = "2024, Bruno Gonçalves"
17+
author = "Bruno Gonçalves"
1718
release = epidemik.__version__
1819

1920
# -- General configuration ---------------------------------------------------
2021
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
2122

2223
extensions = [
23-
'sphinx_rtd_theme',
24-
'sphinx.ext.duration',
25-
'sphinx.ext.doctest',
26-
'sphinx.ext.autodoc',
27-
'sphinx.ext.autosummary',
24+
"sphinx_rtd_theme",
25+
"sphinx.ext.duration",
26+
"sphinx.ext.doctest",
27+
"sphinx.ext.autodoc",
28+
"sphinx.ext.autosummary",
2829
]
2930

30-
templates_path = ['_templates']
31-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
32-
31+
templates_path = ["_templates"]
32+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
3333

3434

3535
# -- Options for HTML output -------------------------------------------------
3636
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
3737

38-
html_theme = 'sphinx_rtd_theme'
39-
html_static_path = ['_static']
38+
html_theme = "sphinx_rtd_theme"
39+
html_static_path = ["_static"]
4040
html_theme_options = {
41-
'analytics_id': 'G-HKWS10TRJ1',
42-
'analytics_anonymize_ip': False,
43-
'logo_only': False,
44-
'display_version': True,
45-
'prev_next_buttons_location': 'bottom',
46-
'style_external_links': True,
47-
'vcs_pageview_mode': '',
48-
'style_nav_header_background': 'white',
41+
"analytics_id": "G-HKWS10TRJ1",
42+
"analytics_anonymize_ip": False,
43+
"logo_only": False,
44+
"display_version": True,
45+
"prev_next_buttons_location": "bottom",
46+
"style_external_links": True,
47+
"vcs_pageview_mode": "",
48+
"style_nav_header_background": "white",
4949
# Toc options
50-
'collapse_navigation': True,
51-
'sticky_navigation': True,
52-
'navigation_depth': 4,
53-
'includehidden': True,
54-
'titles_only': False
55-
}
50+
"collapse_navigation": True,
51+
"sticky_navigation": True,
52+
"navigation_depth": 4,
53+
"includehidden": True,
54+
"titles_only": False,
55+
}

poetry.lock

Lines changed: 101 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ enable = true
3333

3434
[tool.poetry.group.dev.dependencies]
3535
pytest = "^8.3.4"
36+
pytest-cov = "^6.0.0"
3637

3738
[build-system]
3839
requires = ["poetry-core>=2.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts = --ignore=.venv --cov=epidemik

src/epidemik/EpiModel.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# @author Bruno Goncalves
44
######################################################
55

6-
from typing import Dict, List, Set, Union
6+
from typing import Dict, List, Set, Union, Self
77
import warnings
88
import string
99
import time
@@ -789,6 +789,33 @@ def save_model(self, filename: str) -> None:
789789
with open(filename, "wt") as f:
790790
f.write(self.__repr__())
791791

792+
def list_models() -> List[str]:
793+
"""
794+
List the models available in the official repository
795+
"""
796+
remote_path = utils.get_remote_path()
797+
remote_path = os.path.join(remote_path, "model_list.txt")
798+
799+
cache_dir = utils.get_cache_directory()
800+
801+
if not os.path.exists(cache_dir):
802+
os.makedirs(cache_dir)
803+
804+
local_path = os.path.join(cache_dir, "model_list.txt")
805+
806+
# Always get the latest version
807+
urlretrieve(remote_path, local_path)
808+
models = [line.strip() for line in open(local_path, "rt").readlines()]
809+
810+
# Add any user models
811+
if os.path.exists(cache_dir):
812+
for file in os.listdir(cache_dir):
813+
if file.endswith(".yaml"):
814+
models.append(file)
815+
816+
# Make sure to remove duplicates
817+
return sorted(set(models))
818+
792819
def load_model(filename: str) -> None:
793820
"""
794821
Load the model from a file
@@ -824,26 +851,24 @@ def load_model(filename: str) -> None:
824851

825852
return model
826853

827-
828-
def download_model(filename: str, repo: Union[str, None] = None) -> None:
854+
def download_model(
855+
filename: str, repo: Union[str, None] = None, load_model: bool = True
856+
) -> Union[None, Self]:
829857
"""
830858
Download model from offical repository
831859
"""
832-
if repo is None:
833-
repo = utils.OFFICIAL_REPO
834-
835-
parsed_repo = urlparse(repo)
860+
remote_path = utils.get_remote_path(repo)
861+
remote_path = os.path.join(remote_path, filename)
836862

837-
if parsed_repo.netloc == 'github.com':
838-
repo = repo.replace('github.com', 'raw.githubusercontent.com')
839-
remote_path = repo + os.path.join('refs/heads/models/models/', filename)
863+
cache_dir = utils.get_cache_directory()
840864

841-
if not os.path.exists(utils.LOCAL_DIRECTORY):
842-
os.makedirs(utils.LOCAL_DIRECTORY)
865+
if not os.path.exists(cache_dir):
866+
os.makedirs(cache_dir)
843867

844-
local_path = os.path.join(utils.LOCAL_DIRECTORY, filename)
868+
local_path = os.path.join(cache_dir, filename)
845869

846870
if not os.path.exists(local_path):
847871
urlretrieve(remote_path, local_path)
848872

849-
return EpiModel.load_model(local_path)
873+
if load_model:
874+
return EpiModel.load_model(local_path)

src/epidemik/MetaEpiModel.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import networkx as nx
77
import numpy as np
8+
import time
9+
import os
810
from numpy import linalg
911
from numpy import random
1012
import pandas as pd
@@ -14,7 +16,8 @@
1416

1517
from typing import Union
1618

17-
from .EpiModel import *
19+
from .EpiModel import EpiModel
20+
from . import utils
1821

1922
from tqdm import tqdm
2023

@@ -214,7 +217,7 @@ def simulate(
214217
**kwargs,
215218
) -> None:
216219
if seed_state is None:
217-
raise NotInitialized("You have to specify the seed_state")
220+
raise utils.NotInitialized("You have to specify the seed_state")
218221

219222
self._initialize_populations(susceptible)
220223

@@ -233,7 +236,7 @@ def simulate(
233236
self.compartments_ = self._run_travel(self.compartments_, self.travel_graph)
234237

235238
def integrate(self, **kwargs):
236-
raise NotImplementedError(
239+
raise utils.NotImplementedError(
237240
"MetaEpiModel doesn't support direct integration of the ODE"
238241
)
239242

0 commit comments

Comments
 (0)