Skip to content

Commit a2d0502

Browse files
authored
🔥 refactor: cleanup unused pyo3 APIs (#327)
1 parent 690a34c commit a2d0502

File tree

6 files changed

+3
-196
lines changed

6 files changed

+3
-196
lines changed

packages/biliass/rust/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,16 @@ fn biliass_pyo3(m: &Bound<'_, PyModule>) -> PyResult<()> {
2222
m.add_class::<python::PyDmSegMobileReply>()?;
2323
m.add_class::<python::PyDanmakuElem>()?;
2424
m.add_class::<python::PyComment>()?;
25-
m.add_class::<python::PyOptionComment>()?;
2625
m.add_class::<python::PyCommentPosition>()?;
26+
m.add_class::<python::PyRows>()?;
2727
m.add_function(wrap_pyfunction!(python::py_read_comments_from_xml, m)?)?;
2828
m.add_function(wrap_pyfunction!(python::py_read_comments_from_protobuf, m)?)?;
2929
m.add_function(wrap_pyfunction!(python::py_convert_timestamp, m)?)?;
3030
m.add_function(wrap_pyfunction!(python::py_ass_escape, m)?)?;
3131
m.add_function(wrap_pyfunction!(python::py_convert_color, m)?)?;
3232
m.add_function(wrap_pyfunction!(python::py_get_zoom_factor, m)?)?;
3333
m.add_function(wrap_pyfunction!(python::py_convert_flash_rotation, m)?)?;
34-
m.add_function(wrap_pyfunction!(python::py_test_free_rows, m)?)?;
35-
m.add_class::<python::PyRows>()?;
36-
m.add_function(wrap_pyfunction!(python::py_find_alternative_row, m)?)?;
37-
m.add_function(wrap_pyfunction!(python::py_mark_comment_row, m)?)?;
3834
m.add_function(wrap_pyfunction!(python::py_write_head, m)?)?;
39-
m.add_function(wrap_pyfunction!(python::py_write_comment, m)?)?;
4035
m.add_function(wrap_pyfunction!(python::py_write_normal_comment, m)?)?;
4136
Ok(())
4237
}

packages/biliass/rust/src/python/comment.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -93,45 +93,3 @@ impl PyComment {
9393
format!("Comment({:?})", self.inner)
9494
}
9595
}
96-
97-
#[pyclass(name = "OptionComment", frozen)]
98-
pub struct PyOptionComment {
99-
pub inner: Option<comment::Comment>,
100-
}
101-
102-
impl PyOptionComment {
103-
pub fn new(inner: Option<comment::Comment>) -> Self {
104-
PyOptionComment { inner }
105-
}
106-
}
107-
108-
#[pymethods]
109-
impl PyOptionComment {
110-
pub fn is_none(&self) -> bool {
111-
self.inner.is_none()
112-
}
113-
114-
pub fn is_some(&self) -> bool {
115-
self.inner.is_some()
116-
}
117-
118-
pub fn unwrap(&self) -> PyComment {
119-
PyComment::new(self.inner.clone().unwrap())
120-
}
121-
122-
#[staticmethod]
123-
pub fn from_comment(comment: &PyComment) -> Self {
124-
PyOptionComment {
125-
inner: Some(comment.inner.clone()),
126-
}
127-
}
128-
129-
#[staticmethod]
130-
pub fn none() -> Self {
131-
PyOptionComment { inner: None }
132-
}
133-
134-
fn __eq__(&self, other: &PyOptionComment) -> bool {
135-
self.inner == other.inner
136-
}
137-
}

packages/biliass/rust/src/python/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ mod proto;
33
mod reader;
44
mod writer;
55

6-
pub use comment::{PyComment, PyCommentPosition, PyOptionComment};
6+
pub use comment::{PyComment, PyCommentPosition};
77
pub use proto::{PyDanmakuElem, PyDmSegMobileReply};
88
pub use reader::{py_read_comments_from_protobuf, py_read_comments_from_xml};
99
pub use writer::{
1010
py_ass_escape, py_convert_color, py_convert_flash_rotation, py_convert_timestamp,
11-
py_find_alternative_row, py_get_zoom_factor, py_mark_comment_row, py_test_free_rows,
12-
py_write_comment, py_write_head, py_write_normal_comment, PyRows,
11+
py_get_zoom_factor, py_write_head, py_write_normal_comment, PyRows,
1312
};

packages/biliass/rust/src/python/writer.rs

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use crate::writer::{self, rows};
33

44
use pyo3::prelude::*;
55

6-
use super::PyOptionComment;
7-
86
#[pyfunction(name = "convert_timestamp")]
97
pub fn py_convert_timestamp(timestamp: f64) -> PyResult<String> {
108
Ok(writer::utils::convert_timestamp(timestamp))
@@ -62,63 +60,6 @@ impl PyRows {
6260
}
6361
PyRows { inner: rows }
6462
}
65-
66-
fn get(&self, row: usize, col: usize) -> PyOptionComment {
67-
PyOptionComment::new(self.inner[row][col].clone())
68-
}
69-
70-
fn set(&mut self, row: usize, col: usize, value: PyRef<PyOptionComment>) {
71-
self.inner[row][col] = value.inner.clone();
72-
}
73-
}
74-
75-
#[allow(clippy::too_many_arguments)]
76-
#[pyfunction(name = "test_free_rows")]
77-
pub fn py_test_free_rows(
78-
rows: &python::writer::PyRows,
79-
comment: &crate::python::PyComment,
80-
row: usize,
81-
width: u32,
82-
height: u32,
83-
bottom_reserved: u32,
84-
duration_marquee: f64,
85-
duration_still: f64,
86-
) -> PyResult<usize> {
87-
Ok(writer::rows::test_free_rows(
88-
&rows.inner,
89-
&comment.inner,
90-
row,
91-
width,
92-
height,
93-
bottom_reserved,
94-
duration_marquee,
95-
duration_still,
96-
))
97-
}
98-
99-
#[pyfunction(name = "find_alternative_row")]
100-
pub fn py_find_alternative_row(
101-
rows: &python::writer::PyRows,
102-
comment: &crate::python::PyComment,
103-
height: u32,
104-
bottom_reserved: u32,
105-
) -> PyResult<usize> {
106-
Ok(writer::rows::find_alternative_row(
107-
&rows.inner,
108-
&comment.inner,
109-
height,
110-
bottom_reserved,
111-
))
112-
}
113-
114-
#[pyfunction(name = "mark_comment_row")]
115-
pub fn py_mark_comment_row(
116-
rows: &mut python::writer::PyRows,
117-
comment: &crate::python::PyComment,
118-
row: usize,
119-
) -> PyResult<()> {
120-
writer::rows::mark_comment_row(&mut rows.inner, &comment.inner, row);
121-
Ok(())
12263
}
12364

12465
#[pyfunction(name = "write_head")]
@@ -135,32 +76,6 @@ pub fn py_write_head(
13576
))
13677
}
13778

138-
#[allow(clippy::too_many_arguments)]
139-
#[pyfunction(name = "write_comment")]
140-
pub fn py_write_comment(
141-
comment: &crate::python::PyComment,
142-
row: usize,
143-
width: u32,
144-
height: u32,
145-
bottom_reserved: u32,
146-
fontsize: f32,
147-
duration_marquee: f64,
148-
duration_still: f64,
149-
styleid: &str,
150-
) -> PyResult<String> {
151-
Ok(writer::ass::write_comment(
152-
&comment.inner,
153-
row,
154-
width,
155-
height,
156-
bottom_reserved,
157-
fontsize,
158-
duration_marquee,
159-
duration_still,
160-
styleid,
161-
))
162-
}
163-
16479
#[allow(clippy::too_many_arguments)]
16580
#[pyfunction(name = "write_normal_comment")]
16681
pub fn py_write_normal_comment(

packages/biliass/src/biliass/_core.pyi

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ class Comment:
5555
height: float
5656
width: float
5757

58-
class OptionComment:
59-
def is_none(self) -> bool: ...
60-
def is_some(self) -> bool: ...
61-
def unwrap(self) -> Comment: ...
62-
@staticmethod
63-
def from_comment(comment: Comment) -> OptionComment: ...
64-
@staticmethod
65-
def none() -> OptionComment: ...
66-
6758
def read_comments_from_xml(text: str, fontsize: float) -> list[Comment]: ...
6859
def read_comments_from_protobuf(data: bytes, fontsize: float) -> list[Comment]: ...
6960
def convert_timestamp(timestamp: float) -> float: ...
@@ -73,36 +64,11 @@ def get_zoom_factor(source_size: tuple[int, int], target_size: tuple[int, int])
7364
def convert_flash_rotation(
7465
rot_y: float, rot_z: float, x: float, y: float, width: float, height: float
7566
) -> tuple[float, float, float, float, float, float, float]: ...
76-
def test_free_rows(
77-
rows: Rows,
78-
comment: Comment,
79-
row: int,
80-
width: int,
81-
height: int,
82-
bottom_reserved: int,
83-
duration_marquee: float,
84-
duration_still: float,
85-
) -> int: ...
8667

8768
class Rows:
8869
def __init__(self, num_types: int, capacity: int) -> None: ...
89-
def get(self, row: int, col: int) -> OptionComment: ...
90-
def set(self, row: int, col: int, value: OptionComment) -> None: ...
9170

92-
def find_alternative_row(rows: Rows, comment: Comment, height: int, bottom_reserved: int) -> int: ...
93-
def mark_comment_row(rows: Rows, comment: Comment, row: int) -> None: ...
9471
def write_head(width: int, height: int, fontface: str, fontsize: float, alpha: float, styleid: str) -> str: ...
95-
def write_comment(
96-
comment: Comment,
97-
row: int,
98-
width: int,
99-
height: int,
100-
bottom_reserved: int,
101-
fontsize: float,
102-
duration_marquee: float,
103-
duration_still: float,
104-
styleid: str,
105-
) -> str: ...
10672
def write_normal_comment(
10773
rows: Rows,
10874
comment: Comment,

packages/biliass/src/biliass/biliass.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import json
66
import logging
7-
import math
87
import random
98
import re
109
from typing import TYPE_CHECKING, TypeVar
@@ -20,7 +19,6 @@
2019
get_zoom_factor,
2120
read_comments_from_protobuf,
2221
read_comments_from_xml,
23-
write_comment,
2422
write_head,
2523
write_normal_comment,
2624
)
@@ -147,30 +145,6 @@ def get_position(InputPos, isHeight):
147145
def write_head(self, width: int, height: int, fontface: str, fontsize: float, alpha: float, styleid: str) -> None:
148146
self._text += write_head(width, height, fontface, fontsize, alpha, styleid)
149147

150-
def write_comment(
151-
self,
152-
comment: Comment,
153-
row: int,
154-
width: int,
155-
height: int,
156-
bottom_reserved: int,
157-
fontsize: float,
158-
duration_marquee: float,
159-
duration_still: float,
160-
styleid: str,
161-
):
162-
self._text += write_comment(
163-
comment,
164-
row,
165-
width,
166-
height,
167-
bottom_reserved,
168-
fontsize,
169-
duration_marquee,
170-
duration_still,
171-
styleid,
172-
)
173-
174148
def write_normal_comment(
175149
self,
176150
rows: Rows,

0 commit comments

Comments
 (0)