Skip to content

Commit 27d79e8

Browse files
authored
Merge pull request #17 from Medical-Event-Data-Standard/dev
Release Candidate 0.1
2 parents 5e78a59 + f63dbf7 commit 27d79e8

13 files changed

Lines changed: 1887 additions & 299 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ jobs:
3131
run: |
3232
pytest -v --cov=src
3333
34-
- name: Check README code snippets
35-
run: |
36-
python -m doctest README.md
37-
3834
- name: Upload coverage to Codecov
3935
uses: codecov/codecov-action@v4.0.1
4036
with:

README.md

Lines changed: 367 additions & 25 deletions
Large diffs are not rendered by default.

conftest.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Test set-up and fixtures code."""
2+
3+
import json
4+
import tempfile
5+
from contextlib import contextmanager
6+
from datetime import datetime
7+
from functools import partial
8+
from typing import Any
9+
from unittest.mock import MagicMock, patch
10+
11+
import pytest
12+
13+
14+
@contextmanager
15+
def print_warnings(caplog: pytest.LogCaptureFixture):
16+
"""Captures all logged warnings within this context block and prints them upon exit.
17+
18+
This is useful in doctests, where you want to show printed outputs for documentation and testing purposes.
19+
"""
20+
21+
n_current_records = len(caplog.records)
22+
23+
with caplog.at_level("WARNING"):
24+
yield
25+
# Print all captured warnings upon exit
26+
for record in caplog.records[n_current_records:]:
27+
print(f"Warning: {record.getMessage()}")
28+
29+
30+
@pytest.fixture(autouse=True)
31+
def _setup_doctest_namespace(
32+
doctest_namespace: dict[str, Any],
33+
caplog: pytest.LogCaptureFixture,
34+
) -> None:
35+
doctest_namespace.update(
36+
{
37+
"MagicMock": MagicMock,
38+
"patch": patch,
39+
"print_warnings": partial(print_warnings, caplog),
40+
"json": json,
41+
"datetime": datetime,
42+
"tempfile": tempfile,
43+
}
44+
)

docs/copy_README.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Generate the code reference pages."""
2+
3+
import re
4+
from pathlib import Path
5+
6+
import mkdocs_gen_files
7+
8+
root = Path(__file__).parent.parent
9+
readme = root / "README.md"
10+
11+
# Src links are of the form `(src/.../*.py)`.
12+
SRC_LINK_RE = re.compile(r"\(src/[^)]+\.py\)")
13+
14+
if not readme.is_file():
15+
raise FileNotFoundError(f"{readme} not found")
16+
17+
readme_lines = readme.read_text().splitlines()
18+
19+
remapped_lines = []
20+
for line in readme_lines:
21+
if SRC_LINK_RE.search(line):
22+
# Replace src/.../*.py with the corresponding markdown file
23+
line = SRC_LINK_RE.sub(lambda m: f"(api/{m.group(0)[5:-4]})", line)
24+
remapped_lines.append(line)
25+
26+
home_path = "index.md"
27+
with mkdocs_gen_files.open(home_path, "w") as fd:
28+
fd.write("\n".join(remapped_lines))

mkdocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ markdown_extensions:
2424
- pymdownx.tabbed:
2525
alternate_style: true
2626
- pymdownx.superfences
27+
- github-callouts
2728

2829
extra_javascript:
2930
- javascripts/mathjax.js
@@ -34,9 +35,12 @@ plugins:
3435
- gen-files:
3536
scripts:
3637
- docs/gen_ref_pages.py
38+
- docs/copy_README.py
3739
- literate-nav:
3840
nav_file: SUMMARY.md
3941
- section-index
4042
- mkdocstrings
4143
- git-authors
4244
- git-revision-date-localized
45+
46+
watch: [src, README.md]

pyproject.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,24 @@ tests = ["pytest", "pytest-cov[toml]"]
3030
docs = [
3131
"mkdocs==1.6.1", "mkdocs-material==9.6.7", "mkdocstrings[python,shell]==0.28.2", "mkdocs-gen-files==0.5.0",
3232
"mkdocs-literate-nav==0.6.1", "mkdocs-section-index==0.3.9", "mkdocs-git-authors-plugin==0.9.2",
33-
"mkdocs-git-revision-date-localized-plugin==1.3.0"
33+
"mkdocs-git-revision-date-localized-plugin==1.3.0", "markdown-callouts",
3434
]
3535

36+
[project.urls]
37+
Homepage = "https://github.com/mmcdermott/flexible_schema"
38+
Issues = "https://github.com/mmcdermott/flexible_schema/issues"
39+
3640
[tool.pytest.ini_options]
3741
addopts = [
3842
"--color=yes",
3943
"--doctest-modules",
4044
"--ignore=docs",
45+
"--doctest-glob=README.md",
4146
]
47+
doctest_optionflags = ["NORMALIZE_WHITESPACE", "ELLIPSIS"]
4248

43-
[project.urls]
44-
Homepage = "https://github.com/mmcdermott/flexible_schema"
45-
Issues = "https://github.com/mmcdermott/flexible_schema/issues"
49+
[tool.coverage.report]
50+
exclude_also = ["@(abc\\.)?abstractmethod"]
4651

4752
[tool.ruff]
4853
target-version = "py310"

src/flexible_schema/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .base import Optional, Schema, SchemaValidationError
1+
from .base import Schema
2+
from .columns import Column, Nullability, Optional, Required
3+
from .exceptions import SchemaValidationError, TableValidationError
24
from .json import JSONSchema
35
from .pyarrow import PyArrowSchema
4-
5-
__all__ = ["JSONSchema", "Optional", "PyArrowSchema", "Schema", "SchemaValidationError"]

0 commit comments

Comments
 (0)