Skip to content

Commit 07f6e54

Browse files
committed
publish: v1.1.0 - Refactors: More native (Rust)
- from wrapper to direct use of rust native module. - Changed: `Calculator`, `DifficultyPoint`, `TimingPoint`, `Pos2`, `HitObjectKind`, `HitObject`. - Refactor some functions. - The rust logger is no longer included by default, unless the `rust_logger` feature is manually enabled for compilation. - Smaller compiled `.pyd' or `.so'.
1 parent b954f3a commit 07f6e54

31 files changed

+401
-358
lines changed

Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "peace-performance-python"
3-
version = "1.0.4"
3+
version = "1.1.0"
44
authors = ["Pure-Peace <940857703@qq.com>"]
55
edition = "2018"
66

@@ -44,13 +44,18 @@ async_std = [
4444
"pyo3-asyncio/async-std-runtime",
4545
]
4646

47+
# Irrelevant Features
48+
rust_logger = ["log", "timed", "pretty_env_logger"]
49+
4750

4851
[dependencies]
4952
pyo3 = { version = "0.14", features = ["extension-module"] }
50-
log = "0.4"
51-
timed = "0.2.1"
52-
pretty_env_logger = "0.4.0"
53+
paste = "1.0"
5354

55+
# Rust logger optional
56+
log = { version = "0.4", optional = true }
57+
timed = { version = "0.2.1", optional = true }
58+
pretty_env_logger = { version = "0.4.0", optional = true }
5459

5560
# Async optional
5661
pyo3-asyncio = { version = "0.14", optional = true }

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ from peace_performance_python.prelude import *
6060

6161
from tests import async_run, join_beatmap, HITORIGOTO, UNFORGIVING
6262

63-
63+
# *No longer available by default (compile without `rust_logger` features enabled)*
6464
# Initialize Rust logger (optional)
65+
'''
6566
set_log_level('trace')
6667
init_logger()
68+
'''
6769

6870

6971
# Choose a style you like

beatmap_parse_examples.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from peace_performance_python.prelude import *
22
from tests import join_beatmap, HITORIGOTO
33

4+
5+
# *No longer available by default (compile without `rust_logger` features enabled)*
46
# Initialize Rust logger (optional)
7+
'''
58
set_log_level('trace')
69
init_logger()
10+
'''
711

812

913
def main():

examples.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
from tests import async_run, join_beatmap, HITORIGOTO, UNFORGIVING
77

8-
8+
# *No longer available by default (compile without `rust_logger` features enabled)*
99
# Initialize Rust logger (optional)
10+
'''
1011
set_log_level('trace')
1112
init_logger()
13+
'''
1214

1315

1416
# Choose a style you like

peace_performance_python/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
__author__ = 'Pure-Peace'
88
__license__ = 'MIT'
99
__copyright__ = 'Copyright 2021 Pure-Peace'
10-
__version__ = '1.0.1'
10+
__version__ = '1.1.0'
1111

1212
from .objects import *
13-
from . import types
1413
from . import functions

peace_performance_python/_peace_performance/beatmap.pyi

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from pathlib import Path
2-
from . import BaseGetter
32
from typing import Dict, List, Optional, Tuple
43

4+
from .types import BaseGetter
5+
56

67
class DifficultyPoint(BaseGetter):
78
'''
8-
DifficultyPoint object
9+
DifficultyPoint object (`Rust`)
910
1011
`time`: `float`
1112
@@ -23,7 +24,7 @@ class DifficultyPoint(BaseGetter):
2324

2425
class TimingPoint(BaseGetter):
2526
'''
26-
TimingPoint object
27+
TimingPoint object (`Rust`)
2728
2829
`time`: `float`
2930
@@ -41,7 +42,7 @@ class TimingPoint(BaseGetter):
4142

4243
class Pos2(BaseGetter):
4344
'''
44-
Pos2 object
45+
Pos2 object (`Rust`)
4546
4647
`x`: `float`
4748
@@ -81,7 +82,7 @@ class Pos2(BaseGetter):
8182

8283
class HitObjectKind(BaseGetter):
8384
'''
84-
HitObjectKind object
85+
HitObjectKind object (`Rust`)
8586
8687
`kind`: `str`
8788
@@ -111,7 +112,7 @@ class HitObjectKind(BaseGetter):
111112

112113
class HitObject(BaseGetter):
113114
'''
114-
HitObject object
115+
HitObject object (`Rust`)
115116
116117
`start_time`: `float`
117118
@@ -150,13 +151,13 @@ class HitObject(BaseGetter):
150151

151152
class Beatmap(BaseGetter):
152153
'''
153-
The Beatmap used to calculate the pp, it contains the parsed .osu beatmap.
154+
The Beatmap (`Rust`) used to calculate the pp, it contains the parsed .osu beatmap.
154155
155156
`path`: `Optional[Path]`
156157
157158
`mode`: `int`
158159
159-
`mode_str`: `str`
160+
`mode_str`: `Optional[str]`
160161
161162
`version`: `int`
162163
@@ -185,51 +186,9 @@ class Beatmap(BaseGetter):
185186
`timing_points`: `Optional[List[TimingPoint]]`
186187
187188
`difficulty_points`: `Optional[List[DifficultyPoint]]`
188-
189-
190-
# Examples:
191-
```
192-
# Read and parse .osu files from local
193-
beatmap = Beatmap('path_to_osu_file')
194-
# Same as
195-
beatmap = Beatmap.create('path_to_osu_file')
196-
197-
# Async Rust
198-
beatmap = await Beatmap.create_async_rs('path_to_osu_file')
199-
# Async Python (wrapper)
200-
beatmap = await Beatmap.create_async_py('path_to_osu_file')
201-
202-
203-
204-
# We can reload this .osu files as:
205-
beatmap.reload()
206-
207-
# Async Rust
208-
await beatmap.reload_async_rs()
209-
# Async Python (wrapper)
210-
await beatmap.reload_async_py()
211-
212-
# We can load another .osu files as:
213-
beatmap.init('path_to_another_osu_file')
214-
215-
# Async Rust
216-
await beatmap.init_rs('path_to_another_osu_file')
217-
# Async Python (wrapper)
218-
await beatmap.init_py('path_to_another_osu_file')
219-
220-
# Calculate PP
221-
c = Calculator()
222-
c.set_acc(98.8)
223-
c.set_combo(727)
224-
# or
225-
c = Calculator({'acc': 98.8, 'combo': 727})
226-
# then
227-
result = c.calculate(beatmap)
228-
229-
```
230189
'''
231190
mode: int
232-
mode_str: str
191+
mode_str: Optional[str]
233192
version: int
234193

235194
n_circles: int
@@ -244,6 +203,11 @@ class Beatmap(BaseGetter):
244203
tick_rate: float
245204
stack_leniency: Optional[float]
246205

206+
@property
207+
def as_dict(self) -> Dict[str, float, str, None]: ...
208+
@property
209+
def attrs_dict(self) -> Dict[str, float, str, None]: ...
210+
247211
@property
248212
def hit_objects(self) -> List[HitObject]: ...
249213
@property
@@ -252,5 +216,11 @@ class Beatmap(BaseGetter):
252216
def difficulty_points(self) -> List[DifficultyPoint]: ...
253217

254218

255-
async def read_beatmap_async(path: Path) -> Beatmap: ...
256-
def read_beatmap_sync(path: Path) -> Beatmap: ...
219+
async def read_beatmap_async(path: Path) -> Beatmap:
220+
'''Read a beatmap async, returns Beatmap object (`Rust`)'''
221+
...
222+
223+
224+
def read_beatmap_sync(path: Path) -> Beatmap:
225+
'''Read a beatmap, returns Beatmap object (`Rust`)'''
226+
...
Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
1-
def set_log_level(log_level: str) -> None: ...
2-
def init_logger() -> None: ...
3-
async def rust_sleep(secs: int) -> None: ...
1+
from typing import Optional
2+
3+
4+
from .types import (
5+
OsuModeInt,
6+
OsuModeStr,
7+
)
8+
9+
10+
def set_log_level(log_level: str) -> None:
11+
'''
12+
Sets the internal log level.
13+
14+
### Available only when feature `rust_logger` is enabled. (Default disabled)
15+
16+
Levels: `['error', 'warning', 'info', 'debug', 'trace']`
17+
18+
trace levels log all internal timings.
19+
'''
20+
...
21+
22+
23+
def init_logger() -> None:
24+
'''
25+
Initialises the logger for the rust lib, this can only be called once.
26+
27+
### Available only when feature `rust_logger` is enabled. (Default disabled)
28+
29+
No logs will be displayed without calling this first however once called
30+
the level can no-longer be adjusted.
31+
'''
32+
...
33+
34+
35+
async def rust_sleep(secs: int) -> None:
36+
'''
37+
Async sleep (rust).
38+
39+
### Available only when feature `async_tokio` / `async_std` is enabled. (Default enabled)
40+
'''
41+
...
42+
43+
44+
def osu_mode_str(mode: OsuModeInt) -> Optional[OsuModeStr]:
45+
'''Get osu! Mode str with mode int'''
46+
...
47+
48+
49+
def osu_mode_int(mode: OsuModeStr) -> Optional[OsuModeInt]:
50+
'''Get osu! Mode int with mode str'''
51+
...

0 commit comments

Comments
 (0)