Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bsdz/yabte
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdz committed May 31, 2023
2 parents 7d163d6 + 075bc2a commit c965544
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 83 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
poetry-version: ["1.3.1"]
os: [ubuntu-latest]
include:
- os: ubuntu-latest
python-version: "3.10"
poetry-version: "1.3.1"
use-mypyc: true
- os: ubuntu-latest
python-version: "3.10"
poetry-version: "1.3.1"
use-mypyc: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand All @@ -20,6 +26,9 @@ jobs:
cache: "poetry"
- name: Install dependencies
run: poetry install --with dev
- if: ${{ matrix.use-mypyc }}
name: Build mypyc modules
run: poetry run python build.py --inplace
- name: Run tests with coverage
run: poetry run coverage run -m unittest
- name: Show coverage report
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
poetry-version: ["1.3.1"]
os: [ubuntu-latest]
include:
- os: ubuntu-latest
python-version: "3.10"
poetry-version: "1.3.1"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry==${{ matrix.poetry-version }}
run: |
pipx install poetry==${{ matrix.poetry-version }}
poetry self add poetry-plugin-ignore-build-script
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -25,5 +28,7 @@ jobs:
env:
PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry build
poetry build ----ignore-build-script
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
poetry publish
63 changes: 63 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sys

mypyc_modules = [
"yabte/backtest/__init__.py",
"yabte/backtest/_helpers.py",
"yabte/backtest/asset.py",
"yabte/backtest/book.py",
"yabte/backtest/order.py",
"yabte/backtest/strategy.py",
"yabte/backtest/transaction.py",
]


def build(setup_kwargs):
"""Imported by poetry generated setup.py during build."""
try:
from mypyc.build import mypycify

setup_kwargs.update(
{
"ext_modules": mypycify(mypyc_modules),
}
)
except:
pass


def build_inplace():
"""Build modules inplace for running tests."""
import os
import subprocess

# mypyc generates a setup.py and calls build_ext --inplace
env = os.environ.copy()
cmd = subprocess.run([sys.executable, "-m", "mypyc"] + mypyc_modules, env=env)
return cmd.returncode


def cleanup():
from pathlib import Path

this_dir = Path(__file__).parent

# rm module shared objs
for mod in mypyc_modules:
fp = this_dir / mod
for gfp in fp.parent.glob(fp.with_suffix("").name + "*.so"):
gfp.unlink(missing_ok=True)

for gfp in this_dir.glob("*__mypyc.*.so"):
gfp.unlink(missing_ok=True)

return 0


if __name__ == "__main__":
if len(sys.argv) == 2:
if "clean" in sys.argv[1]:
sys.exit(cleanup())
elif "inplace" in sys.argv[1]:
sys.exit(build_inplace())

sys.exit("Unknown option, use '--clean' or '--inplace'")
113 changes: 71 additions & 42 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ license = "MIT"
readme = "README.md"
repository = "https://github.com/bsdz/yabte"

[tool.poetry.build]
script = "build.py"
generate-setup-file = true

[tool.poetry.dependencies]
python = "^3.10,<3.12"
pandas = "^1.5.2"
scipy = "^1.10.0"
pandas-stubs = "^2.0.0.230412"
mypy = "^1.3.0"

[tool.poetry.group.dev]
optional = true

[tool.poetry.group.dev.dependencies]
mypy = "^0.991"
isort = "^5.11.4"
black = {extras = ["jupyter"], version = "^23.1.0"}
docformatter = "^1.5.1"
Expand All @@ -42,5 +47,5 @@ nbconvert = "^7.2.9"
profile = "black"

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["poetry-core>=1.0.0", "setuptools==67.8.0", "mypy==1.3.0", "pandas-stubs==2.0.0.230412"]
build-backend = "poetry.core.masonry.api"
12 changes: 7 additions & 5 deletions yabte/backtest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from .asset import Asset, AssetName
from .book import Book, BookMandate, BookName
from .order import (
# TODO: use absolute imports until mypyc fixes relative imports in __init__.py
# (https://github.com/mypyc/mypyc/issues/996)
from yabte.backtest.asset import Asset, AssetName
from yabte.backtest.book import Book, BookMandate, BookName
from yabte.backtest.order import (
BasketOrder,
Order,
OrderSizeType,
Expand All @@ -9,8 +11,8 @@
PositionalOrder,
PositionalOrderCheckType,
)
from .strategy import Strategy, StrategyRunner
from .transaction import CashTransaction, Trade
from yabte.backtest.strategy import Strategy, StrategyRunner
from yabte.backtest.transaction import CashTransaction, Trade

__all__ = [
"Asset",
Expand Down
Loading

0 comments on commit c965544

Please sign in to comment.