Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
max-line-length = 120
extend-ignore = W605
exclude = .venv,build
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
* text=auto eol=lf

*.py text eol=lf
*.md text eol=lf
*.toml text eol=lf
*.cfg text eol=lf
*.txt text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
*.ipynb text eol=lf

*.png binary
*.jpg binary
*.gz binary
123 changes: 107 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,113 @@
name: ci
on: [push, pull_request]

on:
push:
branches: [main]
pull_request:
schedule:
- cron: "23 4 * * 1" # раз в неделю: ловим поломки от новых версий зависимостей
workflow_dispatch:

concurrency:
group: ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
build:
test:
name: tests (py${{ matrix.python-version }})
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: python -m pip install -r requirements.txt
- run: python -m pip install -e .
- run: python -m pip install flake8
- run: python -m flake8 src tests
- run: python examples/run_synthetic_experiment.py --n_users 1000 --seed 0 --policyA epsilon_greedy --policyB softmax --horizon 30 --weight_clip 10 --artifacts_dir synthetic_artifacts
- uses: actions/upload-artifact@v3
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install
run: python -m pip install -e ".[dev]"
- name: Lint
run: python -m flake8 src tests examples
- name: Fast tests
run: python -m pytest -m "not slow" --cov=policyscope --cov-report=term-missing

min-deps:
name: tests (minimum dependency versions)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install declared lower bounds
run: |
python -m pip install numpy==1.23.5 pandas==1.5.3 scikit-learn==1.2.2 scipy==1.9.3 \
joblib==1.2.0 threadpoolctl==3.5.0 pytest
python -m pip install --no-deps -e .
python -m pip check
- name: Fast tests
run: python -m pytest -m "not slow"

package:
name: build and test the wheel
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build
run: |
python -m pip install build twine
python -m build
python -m twine check --strict dist/*
- name: Wheel contents
run: |
python - <<'EOF'
import glob, zipfile
names = zipfile.ZipFile(glob.glob("dist/*.whl")[0]).namelist()
assert "policyscope/py.typed" in names, "py.typed missing"
top = {n.split("/")[0] for n in names}
extra = {t for t in top if t != "policyscope" and not t.endswith(".dist-info")}
assert not extra, f"unexpected top-level entries: {extra}"
EOF
- name: Test against the installed wheel
run: |
python -m venv /tmp/wheelenv
/tmp/wheelenv/bin/python -m pip install dist/*.whl pytest
/tmp/wheelenv/bin/python -m pip check
/tmp/wheelenv/bin/python -c "import importlib.metadata as m, policyscope as p; assert p.__version__ == m.version('policyscope'), p.__file__"
/tmp/wheelenv/bin/python -m pytest -o pythonpath= -m "not slow"
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

statistical:
name: statistical validation (slow)
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install
run: python -m pip install -e ".[dev]"
- name: Slow statistical tests
run: python -m pytest -m slow --durations=10
- name: Validation scenarios
run: python examples/validate.py --runs 30 --clients 2000 --n-boot 60 --output validation.md --strict
- name: Tutorial executes
run: python -m jupyter nbconvert --to notebook --execute --output /tmp/tutorial.ipynb examples/tutorial.ipynb
- uses: actions/upload-artifact@v4
if: always()
with:
name: synthetic-experiment
path: synthetic_artifacts
- run: pytest
- run: python -m pip -V
- run: python -c "import sys; print('OK', sys.version)"
name: validation-report
path: validation.md
107 changes: 107 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: release

# Публикация по тегу вида v0.3.0: сборка → TestPyPI → PyPI → GitHub Release.
# Публикация через Trusted Publishing (без токенов); разовая настройка — в RELEASING.md.

on:
push:
tags: ["v*"]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Tag matches the package version
env:
TAG: ${{ github.ref_name }}
run: |
python - <<'EOF'
import os, pathlib, re, sys
text = pathlib.Path("src/policyscope/__init__.py").read_text(encoding="utf-8")
version = re.search(r'__version__ = "([^"]+)"', text).group(1)
tag = os.environ["TAG"].removeprefix("v")
sys.exit(0 if version == tag else f"tag v{tag} does not match __version__ {version}")
EOF
- name: Build
run: |
python -m pip install build twine
python -m build
python -m twine check --strict dist/*
- name: Smoke test of the wheel
run: |
python -m venv /tmp/smoke
/tmp/smoke/bin/python -m pip install dist/*.whl
cd /tmp && /tmp/smoke/bin/python - <<'EOF'
import policyscope as ps
sim = ps.synthetic.OfferSimulator(seed=0)
logs = sim.simulate(sim.sample_clients(2000), sim.policy("epsilon_greedy", epsilon=0.2, seed=1))
report = ps.evaluate(logs, sim.policy("softmax", seed=2), action="offer",
reward="accepted", propensity="propensity")
print(repr(report))
EOF
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

publish-testpypi:
needs: build
runs-on: ubuntu-latest
environment: testpypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

publish-pypi:
needs: publish-testpypi
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1

github-release:
needs: publish-pypi
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Release notes from CHANGELOG
env:
TAG: ${{ github.ref_name }}
run: |
python - <<'EOF'
import os, pathlib, re
version = os.environ["TAG"].removeprefix("v")
text = pathlib.Path("CHANGELOG.md").read_text(encoding="utf-8")
match = re.search(rf"^## {re.escape(version)}\b.*?$(.*?)(?=^## |\Z)", text, re.M | re.S)
pathlib.Path("notes.md").write_text(match.group(1).strip() if match else "", encoding="utf-8")
EOF
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "${{ github.ref_name }}" dist/* --title "policyscope ${{ github.ref_name }}" --notes-file notes.md
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Python
__pycache__/
*.py[cod]
*.egg-info/
*.egg
*.so
build/
dist/
.eggs/

# Virtualenvs
.venv/
venv/
env/
ENV/
.env

# Tooling caches
.pytest_cache/
.mypy_cache/
.ruff_cache/
.tox/
.hypothesis/
.coverage
coverage.xml
htmlcov/

# IDE and editors
.idea/
.vscode/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db
desktop.ini

# Experiment artifacts
artifacts/
synthetic_artifacts/
validation_artifacts/

# Notebook checkpoints
.ipynb_checkpoints/
51 changes: 0 additions & 51 deletions AGENTS.md

This file was deleted.

Loading
Loading