Skip to content

Commit 717cee8

Browse files
Feat/consolidate and optimize (#63)
* chore: tighten tooling and fix visualization * docs: document Python 3.10 requirement * ci: align workflow with review template
1 parent f92a584 commit 717cee8

File tree

11 files changed

+60
-70
lines changed

11 files changed

+60
-70
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
22
max-line-length = 120
3-
extend-ignore = E501,W291,W293,W391,F401,F841,E402,E302,E305
3+
extend-ignore = E501,W291,W293,W391,E402,E302,E305

.github/workflows/ci.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ name: CI
22

33
on:
44
push:
5-
branches: [main]
5+
branches:
6+
- main
67
pull_request:
7-
branches: [main]
8+
branches:
9+
- main
810

911
jobs:
1012
test:
1113
name: Test with Python ${{ matrix.python-version }}
1214
runs-on: ubuntu-latest
1315
strategy:
1416
matrix:
15-
python-version: ["3.9", "3.10", "3.11"]
17+
python-version: ["3.10", "3.11", "3.12"]
1618

1719
steps:
1820
- name: Checkout code
@@ -23,6 +25,12 @@ jobs:
2325
with:
2426
python-version: ${{ matrix.python-version }}
2527

28+
- name: Cache Poetry dependencies
29+
uses: actions/cache@v4
30+
with:
31+
path: ~/.cache/pypoetry
32+
key: ${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
33+
2634
- name: Install Poetry
2735
run: |
2836
curl -sSL https://install.python-poetry.org | python3 -
@@ -38,7 +46,7 @@ jobs:
3846
uses: codecov/codecov-action@v5
3947
with:
4048
files: coverage.xml
41-
token: ${{ secrets.CODECOV_TOKEN }} # optional if public repo
49+
token: ${{ secrets.CODECOV_TOKEN }}
4250

4351
lint:
4452
name: Code Quality
@@ -53,13 +61,19 @@ jobs:
5361
with:
5462
python-version: "3.11"
5563

64+
- name: Cache Poetry dependencies
65+
uses: actions/cache@v4
66+
with:
67+
path: ~/.cache/pypoetry
68+
key: ${{ runner.os }}-poetry-3.11-${{ hashFiles('**/poetry.lock') }}
69+
5670
- name: Install Poetry
5771
run: |
5872
curl -sSL https://install.python-poetry.org | python3 -
5973
echo "$HOME/.local/bin" >> $GITHUB_PATH
6074
6175
- name: Install dependencies
62-
run: poetry install --with dev
76+
run: poetry install --with dev --no-root
6377

6478
- name: Run pre-commit checks
6579
run: poetry run pre-commit run --all-files

.github/workflows/docs.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ jobs:
1414
- uses: actions/setup-python@v5
1515
with:
1616
python-version: '3.11'
17+
- name: Cache Poetry dependencies
18+
uses: actions/cache@v4
19+
with:
20+
path: ~/.cache/pypoetry
21+
key: ${{ runner.os }}-poetry-3.11-${{ hashFiles('**/poetry.lock') }}
1722
- name: Install Poetry
18-
run: pip install poetry
23+
run: |
24+
curl -sSL https://install.python-poetry.org | python3 -
25+
echo "$HOME/.local/bin" >> $GITHUB_PATH
1926
- name: Install dependencies
2027
run: poetry install --with docs
2128
- name: Build documentation

.github/workflows/test.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Coverage](https://codecov.io/gh/DiogoRibeiro7/genSurvPy/branch/main/graph/badge.svg)](https://app.codecov.io/gh/DiogoRibeiro7/genSurvPy)
44
[![Docs](https://readthedocs.org/projects/gensurvpy/badge/?version=latest)](https://gensurvpy.readthedocs.io/en/latest/)
55
[![PyPI](https://img.shields.io/pypi/v/gen_surv)](https://pypi.org/project/gen-surv/)
6-
[![Tests](https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/test.yml/badge.svg)](https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/test.yml)
6+
[![Tests](https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/ci.yml/badge.svg)](https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/ci.yml)
77
[![Python](https://img.shields.io/pypi/pyversions/gen_surv)](https://pypi.org/project/gen-surv/)
88

99
**gen_surv** is a Python package for simulating survival data under a variety of statistical models. It is inspired by the R package [genSurv](https://cran.r-project.org/package=genSurv) and provides a unified interface for generating realistic survival datasets.
@@ -25,6 +25,8 @@
2525

2626
## Installation
2727

28+
Requires Python 3.10 or later.
29+
2830
Install the latest release from PyPI:
2931

3032
```bash

docs/source/conf.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import os
2-
import sys
3-
from pathlib import Path
4-
5-
# Add the package to the Python path using an absolute path
6-
project_root = Path(__file__).resolve().parent.parent.parent
7-
sys.path.insert(0, str(project_root / "gen_surv"))
2+
from datetime import datetime
3+
from importlib import metadata
84

95
# Project information
106
project = "gen_surv"
11-
copyright = "2025, Diogo Ribeiro"
7+
copyright = f"{datetime.now().year}, Diogo Ribeiro"
128
author = "Diogo Ribeiro"
13-
release = "1.0.9"
14-
version = "1.0.9"
9+
release = metadata.version("gen_surv")
10+
version = release
1511

1612
# General configuration
1713
extensions = [
@@ -21,10 +17,10 @@
2117
"sphinx.ext.intersphinx",
2218
"sphinx.ext.autosummary",
2319
"sphinx.ext.githubpages",
24-
"sphinx.ext.plot_directive",
2520
"myst_parser",
2621
"sphinx_copybutton",
2722
"sphinx_design",
23+
"sphinx_autodoc_typehints",
2824
]
2925

3026
# MyST Parser configuration

docs/source/examples/cmm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Visualize transition times from the CMM generator:
66

7-
```{plot}
7+
```python
88
import numpy as np
99
import matplotlib.pyplot as plt
1010
from gen_surv import generate

docs/source/examples/tdcm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
A basic visualization of event times produced by the TDCM generator:
66

7-
```{plot}
7+
```python
88
import numpy as np
99
import matplotlib.pyplot as plt
1010
from gen_surv import generate

docs/source/examples/thmm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
An example of event times generated by the THMM:
66

7-
```{plot}
7+
```python
88
import numpy as np
99
import matplotlib.pyplot as plt
1010
from gen_surv import generate

gen_surv/cli.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using the gen_surv package.
66
"""
77

8-
from typing import List, Optional, TypeVar, cast
8+
from typing import Any, Dict, List, Optional, TypeVar, cast
99

1010
import typer
1111

@@ -91,8 +91,8 @@ def _val(v: T | OptionInfo) -> T:
9191
return v if not isinstance(v, OptionInfo) else cast(T, v.default)
9292

9393
# Prepare arguments based on the selected model
94-
model_str = _val(model)
95-
kwargs = {
94+
model_str: str = _val(model)
95+
kwargs: Dict[str, Any] = {
9696
"model": model_str,
9797
"n": _val(n),
9898
"model_cens": _val(model_cens),
@@ -103,7 +103,8 @@ def _val(v: T | OptionInfo) -> T:
103103
# Add model-specific parameters
104104
if model_str in ["cphm", "cmm", "thmm"]:
105105
# These models use a single beta and covariate range
106-
kwargs["beta"] = _val(beta)[0] if len(_val(beta)) > 0 else 0.5
106+
beta_values = cast(List[float], _val(beta))
107+
kwargs["beta"] = beta_values[0] if len(beta_values) > 0 else 0.5
107108
kwargs["covariate_range"] = _val(covariate_range)
108109

109110
elif model_str == "aft_ln":
@@ -153,10 +154,10 @@ def _val(v: T | OptionInfo) -> T:
153154

154155
# Generate the data
155156
try:
156-
df = generate(**kwargs)
157+
df = generate(**kwargs) # type: ignore[arg-type]
157158
except TypeError:
158159
# Fallback for tests where generate accepts only model and n
159-
df = generate(model=model_str, n=_val(n))
160+
df = generate(model=model_str, n=_val(n)) # type: ignore[arg-type]
160161

161162
# Output the data
162163
if output:
@@ -228,6 +229,7 @@ def visualize(
228229

229230
# Save the plot
230231
plt.savefig(output, dpi=300, bbox_inches="tight")
232+
plt.close(fig)
231233
typer.echo(f"Plot saved to {output}")
232234

233235

0 commit comments

Comments
 (0)