Skip to content

Commit 289ae5b

Browse files
committed
chore(rust): modify live feature support in Python to be an optional feature, as it is currently incompatible with auditwheel builds.
1 parent 60a1218 commit 289ae5b

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

.github/workflows/release-python.yml

+1-12
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,12 @@ jobs:
4242
- uses: actions/setup-python@v5
4343
with:
4444
python-version: ${{ env.PYTHON_VERSION }}
45-
- name: Install dependencies
46-
run: |
47-
python3 -m ensurepip
48-
sudo apt-get update
49-
sudo apt-get install -y pkg-config openssl libssl-dev
5045
- name: Build wheels
5146
uses: PyO3/maturin-action@v1
5247
with:
5348
target: ${{ matrix.platform.target }}
5449
rust-toolchain: ${{ env.RUST_VERSION }}
5550
args: --manifest-path=py-hftbacktest/Cargo.toml --release --out dist --find-interpreter
56-
# sccache: 'true'
5751
manylinux: 2_24
5852
- name: Upload wheels
5953
uses: actions/upload-artifact@v4
@@ -79,17 +73,12 @@ jobs:
7973
- uses: actions/setup-python@v5
8074
with:
8175
python-version: ${{ env.PYTHON_VERSION }}
82-
- name: Install dependencies
83-
run: |
84-
sudo apt-get update
85-
sudo apt-get install -y pkg-config openssl libssl-dev
8676
- name: Build wheels
8777
uses: PyO3/maturin-action@v1
8878
with:
8979
target: ${{ matrix.platform.target }}
9080
rust-toolchain: ${{ env.RUST_VERSION }}
9181
args: --manifest-path=py-hftbacktest/Cargo.toml --release --out dist --find-interpreter
92-
sccache: 'true'
9382
manylinux: musllinux_1_2
9483
- name: Upload wheels
9584
uses: actions/upload-artifact@v4
@@ -191,4 +180,4 @@ jobs:
191180
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
192181
with:
193182
command: upload
194-
args: --non-interactive --skip-existing wheels-*/*
183+
args: --non-interactive --skip-existing wheels-*/*

py-hftbacktest/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ edition = "2021"
77
name = "hftbacktest"
88
crate-type = ["cdylib"]
99

10+
[features]
11+
default = []
12+
live = ["hftbacktest/live"]
13+
1014
[dependencies]
1115
pyo3 = { version = "0.23.1", features = ["extension-module"] }
12-
hftbacktest = { path = "../hftbacktest", features = ["backtest"] }
16+
hftbacktest = { path = "../hftbacktest", default-features = false, features = ["backtest"] }
1317
hftbacktest-derive = { path = "../hftbacktest-derive" }

py-hftbacktest/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::{ffi::c_void, mem::size_of, ptr::slice_from_raw_parts_mut};
22

33
pub use backtest::*;
44
pub use depth::*;
5+
#[cfg(feature = "live")]
6+
use hftbacktest::live::{Instrument, LiveBotBuilder};
57
use hftbacktest::{
68
backtest::{
79
assettype::{InverseAsset, LinearAsset},
@@ -38,17 +40,18 @@ use hftbacktest::{
3840
Backtest,
3941
DataSource,
4042
},
41-
live::{Instrument, LiveBotBuilder},
4243
prelude::{ApplySnapshot, Event, HashMapMarketDepth, ROIVectorMarketDepth},
4344
};
4445
use hftbacktest_derive::build_asset;
4546
pub use order::*;
4647
use pyo3::{exceptions::PyValueError, prelude::*};
4748

49+
#[cfg(feature = "live")]
4850
use crate::live::{HashMapMarketDepthLiveBot, ROIVectorMarketDepthLiveBot};
4951

5052
mod backtest;
5153
mod depth;
54+
#[cfg(feature = "live")]
5255
mod live;
5356
mod order;
5457

@@ -454,7 +457,9 @@ impl BacktestAsset {
454457
fn _hftbacktest(m: &Bound<'_, PyModule>) -> PyResult<()> {
455458
m.add_function(wrap_pyfunction!(build_hashmap_backtest, m)?)?;
456459
m.add_function(wrap_pyfunction!(build_roivec_backtest, m)?)?;
460+
#[cfg(feature = "live")]
457461
m.add_function(wrap_pyfunction!(build_hashmap_livebot, m)?)?;
462+
#[cfg(feature = "live")]
458463
m.add_function(wrap_pyfunction!(build_roivec_livebot, m)?)?;
459464
m.add_class::<BacktestAsset>()?;
460465
m.add_class::<LiveInstrument>()?;
@@ -658,6 +663,7 @@ impl LiveInstrument {
658663
}
659664
}
660665

666+
#[cfg(feature = "live")]
661667
#[pyfunction]
662668
pub fn build_hashmap_livebot(instruments: Vec<PyRefMut<LiveInstrument>>) -> PyResult<usize> {
663669
let mut builder = LiveBotBuilder::new();
@@ -680,6 +686,7 @@ pub fn build_hashmap_livebot(instruments: Vec<PyRefMut<LiveInstrument>>) -> PyRe
680686
Ok(Box::into_raw(Box::new(hbt)) as *mut c_void as usize)
681687
}
682688

689+
#[cfg(feature = "live")]
683690
#[pyfunction]
684691
pub fn build_roivec_livebot(instruments: Vec<PyRefMut<LiveInstrument>>) -> PyResult<usize> {
685692
let mut builder = LiveBotBuilder::new();

0 commit comments

Comments
 (0)