Skip to content

Commit 0dc6c1f

Browse files
committed
Added scripts for setup, added pytest, improved readme
1 parent 3e49f3e commit 0dc6c1f

10 files changed

Lines changed: 642 additions & 114 deletions

File tree

README.md

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -173,54 +173,99 @@ For ready-to-run scenarios—including examples using the Pythonic builder and m
173173
If you want to contribute or run the full test suite locally, follow these steps.
174174

175175
### Requirements
176+
176177
* **Python 3.12+** (tested on 3.12, 3.13)
177178
* **OS:** Linux, macOS, or Windows
178-
* **Installed with the package (runtime deps):** SimPy, NumPy, Matplotlib, Pydantic, PyYAML, pydantic-settings
179+
* **Runtime deps installed by the package:** SimPy, NumPy, Matplotlib, Pydantic, PyYAML, pydantic-settings
180+
181+
**Prerequisites:** Git, Python 3.12+ in `PATH`, `curl` (Linux/macOS/WSL), PowerShell 7+ (Windows)
179182

180-
### Install Poetry
183+
---
181184

182-
#### Linux / macOS (official installer)
185+
## Project setup
183186

184187
```bash
185-
curl -sSL https://install.python-poetry.org | python3 -
186-
# then make sure Poetry is on PATH (the installer prints the exact line)
187-
# common path:
188-
export PATH="$HOME/.local/bin:$PATH"
189-
poetry --version
188+
git clone https://github.com/AsyncFlow-Sim/AsyncFlow.git
189+
cd AsyncFlow
190190
```
191191

192-
#### Windows (PowerShell)
192+
From the repo root, run the **one-shot post-clone setup**:
193+
194+
**Linux / macOS / WSL**
195+
196+
```bash
197+
bash scripts/dev_setup.sh
198+
```
193199

194-
Open **PowerShell** *as your user* (no admin needed) and run:
200+
**Windows (PowerShell)**
195201

196202
```powershell
197-
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
198-
# Close & reopen PowerShell so PATH updates take effect
199-
poetry --version
203+
# If scripts are blocked by policy, run this in the same PowerShell session:
204+
# Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
205+
.\scripts\dev_setup.ps1
200206
```
201207

202-
### Project setup
208+
**What this does (concise):**
209+
210+
* Ensures **Poetry** is available (installs if missing).
211+
* Uses a **project-local `.venv`**.
212+
* Removes `poetry.lock` for a **clean dependency resolve** (dev policy).
213+
* Installs the project **with dev extras**.
214+
* Runs **ruff**, **mypy**, and **pytest (with coverage)**.
215+
216+
**Quick sanity check after setup:**
203217

204218
```bash
205-
git clone https://github.com/AsyncFlow-Sim/AsyncFlow.git
206-
cd AsyncFlow
219+
poetry --version
220+
poetry run python -V
207221
```
208222

209-
Create a project-local virtualenv and install dependencies (including dev tools):
223+
> **Note (lock policy):** `dev_setup` intentionally removes `poetry.lock` to avoid cross-platform conflicts during development.
224+
225+
**Scripts (for quick access):**
226+
227+
* [`scripts/dev_setup.sh`](scripts/dev_setup.sh) / [`scripts/dev_setup.ps1`](scripts/dev_setup.ps1)
228+
* [`scripts/quality_check.sh`](scripts/quality_check.sh) / [`scripts/quality_check.ps1`](scripts/quality_check.ps1)
229+
* [`scripts/run_tests.sh`](scripts/run_tests.sh) / [`scripts/run_tests.ps1`](scripts/run_tests.ps1)
230+
231+
---
232+
233+
### Handy scripts (after setup)
234+
235+
#### 1) Lint + type check
236+
237+
**Linux / macOS / WSL**
210238

211239
```bash
212-
poetry config virtualenvs.in-project true
213-
poetry install --with dev
240+
bash scripts/quality_check.sh
241+
```
242+
243+
**Windows (PowerShell)**
244+
245+
```powershell
246+
.\scripts\quality_check.ps1
214247
```
215248

216-
You can either run commands through Poetry **without activating** the venv:
249+
Runs **ruff** (lint/format check) and **mypy** on `src` and `tests`.
250+
251+
#### 2) Run tests with coverage
252+
253+
**Linux / macOS / WSL**
217254

218255
```bash
219-
poetry run ruff check src tests
220-
poetry run mypy src tests
221-
poetry run pytest
256+
bash scripts/run_tests.sh
222257
```
223258

259+
**Windows (PowerShell)**
260+
261+
```powershell
262+
.\scripts\run_tests.ps1
263+
```
264+
265+
Executes **pytest** with a terminal coverage summary (no XML, no slowest list).
266+
267+
268+
224269
## What AsyncFlow Models (v0.1)
225270

226271
AsyncFlow provides a detailed simulation of your backend system. Here is a high-level overview of the core components it models. For a deeper technical dive into the implementation and design rationale, follow the links to the internal documentation.

poetry.lock

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

scripts/dev_setup.ps1

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Post-clone developer setup for AsyncFlow (Windows / PowerShell).
2+
#
3+
# What it does:
4+
# 1) Ensures Poetry is available (official installer if missing).
5+
# 2) Configures Poetry to create an in-project virtualenv (.venv).
6+
# 3) Removes poetry.lock (fresh dependency resolution by policy).
7+
# 4) Installs the project with dev extras.
8+
# 5) Runs ruff, mypy, and pytest (with coverage if available).
9+
#
10+
# Usage:
11+
# .\scripts\dev_setup.ps1
12+
#
13+
# Notes:
14+
# - Run this from anywhere; it will cd to repo root.
15+
# - Requires Python >= 3.12 to be available (via 'py' launcher or python.exe).
16+
# - We do NOT delete an existing .venv; it will be reused if compatible.
17+
18+
# Strict error handling
19+
$ErrorActionPreference = 'Stop'
20+
Set-StrictMode -Version Latest
21+
22+
# --- helpers ------------------------------------------------------------------
23+
24+
function Write-Info { param([string]$Msg) Write-Host "==> $Msg" }
25+
function Write-Ok { param([string]$Msg) Write-Host "$Msg" -ForegroundColor Green }
26+
function Fail { param([string]$Msg) Write-Error $Msg; exit 1 }
27+
28+
# Resolve repo root (this script lives in scripts/)
29+
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
30+
$RepoRoot = Resolve-Path (Join-Path $ScriptDir '..')
31+
32+
function Require-Pyproject {
33+
if (-not (Test-Path (Join-Path $RepoRoot 'pyproject.toml'))) {
34+
Fail "pyproject.toml not found at repo root ($RepoRoot)"
35+
}
36+
}
37+
38+
function Get-PythonPath-3_12Plus {
39+
<#
40+
Try common Windows launchers/executables and return the *actual* Python
41+
interpreter path (sys.executable) for a version >= 3.12.
42+
#>
43+
$candidates = @(
44+
@('py', '-3.13'),
45+
@('py', '-3.12'),
46+
@('py', '-3'),
47+
@('python3.13'),
48+
@('python3.12'),
49+
@('python')
50+
)
51+
52+
foreach ($cand in $candidates) {
53+
$exe = $cand[0]
54+
$args = @()
55+
if ($cand.Count -gt 1) { $args = $cand[1..($cand.Count-1)] }
56+
57+
if (-not (Get-Command $exe -ErrorAction SilentlyContinue)) { continue }
58+
59+
# Check version
60+
& $exe @args -c "import sys; import sys as s; raise SystemExit(0 if sys.version_info[:2] >= (3,12) else 1)" 2>$null
61+
if ($LASTEXITCODE -ne 0) { continue }
62+
63+
# Obtain the real interpreter path
64+
$pyPath = & $exe @args -c "import sys; print(sys.executable)" 2>$null
65+
if ($LASTEXITCODE -eq 0 -and $pyPath) {
66+
return $pyPath.Trim()
67+
}
68+
}
69+
70+
return $null
71+
}
72+
73+
function Ensure-Poetry {
74+
if (Get-Command poetry -ErrorAction SilentlyContinue) {
75+
poetry --version | Out-Null
76+
return
77+
}
78+
79+
Write-Info "Poetry not found; attempting installation…"
80+
81+
# Official installer (recommended by Poetry)
82+
$installer = (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content
83+
# Pipe installer to Python (stdin)
84+
$pythonToUse = (Get-Command py -ErrorAction SilentlyContinue) ? 'py' : 'python'
85+
$installer | & $pythonToUse -
86+
87+
# Common locations (make available for current session)
88+
$poetryCandidates = @(
89+
(Join-Path $env:APPDATA 'pypoetry\venv\Scripts'),
90+
(Join-Path $env:USERPROFILE '.local\bin')
91+
)
92+
foreach ($p in $poetryCandidates) {
93+
if (Test-Path $p) { $env:Path = "$p;$env:Path" }
94+
}
95+
96+
if (-not (Get-Command poetry -ErrorAction SilentlyContinue)) {
97+
Fail "Poetry installation failed (not on PATH). Close & reopen PowerShell or add the Poetry path to PATH."
98+
}
99+
100+
poetry --version | Out-Null
101+
}
102+
103+
function Run-Tests-WithOptionalCoverage {
104+
<#
105+
Try pytest with coverage first; if the plugin is missing,
106+
fall back to plain pytest. Propagate failure if tests fail.
107+
#>
108+
$cmd = { poetry run pytest --cov=src --cov-report=term-missing:skip-covered --cov-report=xml --disable-warnings -q }
109+
try {
110+
& $cmd
111+
if ($LASTEXITCODE -eq 0) {
112+
Write-Ok "Tests (with coverage) PASSED"
113+
return
114+
}
115+
} catch {
116+
# ignore; retry without coverage below
117+
}
118+
119+
Write-Info "Coverage run failed (likely pytest-cov not installed). Falling back to plain pytest…"
120+
poetry run pytest --disable-warnings -q
121+
if ($LASTEXITCODE -ne 0) {
122+
Fail "Tests FAILED"
123+
}
124+
Write-Ok "Tests PASSED"
125+
}
126+
127+
# --- main ---------------------------------------------------------------------
128+
129+
Set-Location $RepoRoot
130+
Require-Pyproject
131+
132+
$PythonExe = Get-PythonPath-3_12Plus
133+
if (-not $PythonExe) {
134+
Fail "Python >= 3.12 not found. Install Python 3.12+ and re-run."
135+
}
136+
Write-Info ("Using Python: " + (& $PythonExe -V))
137+
138+
Ensure-Poetry
139+
140+
# Make sure Poetry venv lives inside the repo
141+
Write-Info "Configuring Poetry to use in-project virtualenv (.venv)…"
142+
poetry config virtualenvs.in-project true
143+
Write-Ok "Poetry configured to use .venv"
144+
145+
# Bind Poetry to the chosen interpreter (creates .venv if needed)
146+
poetry env use "$PythonExe" | Out-Null
147+
Write-Ok "Virtualenv ready (.venv)"
148+
149+
# Policy: always remove lock to avoid conflicts across environments
150+
$lockPath = Join-Path $RepoRoot 'poetry.lock'
151+
if (Test-Path $lockPath) {
152+
Write-Info "Removing poetry.lock for a clean resolution…"
153+
Remove-Item $lockPath -Force
154+
Write-Ok "poetry.lock removed"
155+
}
156+
157+
# Faster installs and stable headless plotting
158+
$env:PIP_DISABLE_PIP_VERSION_CHECK = '1'
159+
$env:MPLBACKEND = 'Agg'
160+
161+
Write-Info "Installing project with dev extras…"
162+
poetry install --with dev --no-interaction --no-ansi
163+
Write-Ok "Dependencies installed (dev)"
164+
165+
Write-Info "Running Ruff (lint)…"
166+
poetry run ruff check src tests
167+
Write-Ok "Ruff PASSED"
168+
169+
Write-Info "Running MyPy (type-check)…"
170+
poetry run mypy src tests
171+
Write-Ok "MyPy PASSED"
172+
173+
Write-Info "Running tests (with coverage if available)…"
174+
Run-Tests-WithOptionalCoverage
175+
176+
Write-Ok "All checks completed SUCCESSFULLY 🎉"

0 commit comments

Comments
 (0)