diff --git a/.github/workflows/maturin_upload_pypi.yml b/.github/workflows/maturin_upload_pypi.yml index 66e2a3d..675b9c9 100644 --- a/.github/workflows/maturin_upload_pypi.yml +++ b/.github/workflows/maturin_upload_pypi.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.13' - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -46,7 +46,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.13' architecture: ${{ matrix.target }} - name: Build wheels uses: PyO3/maturin-action@v1 @@ -69,7 +69,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.13' - name: Build wheels uses: PyO3/maturin-action@v1 with: diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 90d3e15..7d0fb4c 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -10,10 +10,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python 3.9 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.9 - name: Install Dependencies run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 417a1c3..2052aa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.7.2] - 2024-12-15 + +### Added + +- Prebuilt binaries for Python 3.13. + +### Changed + +- Python 3.9 or later is now required. + - Bump from Python 3.8 to 3.9. + - Older versions can't be checked on CI anymore, so I prefer to not claim to + support something that may have broken without anybody noticing. + - Nothing really changed. Just the CI tools I was using are refusing to use + any Python version older than this. Sorry if you were affected by this. +- Use newer pyo3 version. + - From 0.20 to 0.23. + - Updated to avoid warnings with newer Rust versions. + - Fix issues introduced by updating pyo3. + ## [2.7.1] - 2024-09-25 ### Added @@ -426,6 +445,7 @@ Full changes: "] @@ -23,7 +23,7 @@ crate-type = ["cdylib", "staticlib", "rlib"] [dependencies] regex = "1.10.2" -pyo3 = { version = "0.20.0", optional = true, features = ["abi3", "abi3-py37"]} +pyo3 = { version = "0.23.2", optional = true, features = ["extension-module"]} lazy_static = "1.4.0" serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/README.md b/README.md index 1953668..a3d6ef2 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ If you use a `requirements.txt` file in your repository, then you can add this library with the following line: ```txt -mapfile_parser>=2.7.1,<3.0.0 +mapfile_parser>=2.7.2,<3.0.0 ``` #### Development version @@ -74,7 +74,7 @@ cargo add mapfile_parser Or add the following line manually to your `Cargo.toml` file: ```toml -mapfile_parser = "2.7.1" +mapfile_parser = "2.7.2" ``` ## Versioning and changelog diff --git a/mypy.ini b/mypy.ini index 3a3ba44..2145f40 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,3 +1,3 @@ [mypy] -python_version = 3.8 +python_version = 3.9 check_untyped_defs = True diff --git a/pyproject.toml b/pyproject.toml index 560a700..6ff607b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,10 +3,10 @@ [project] name = "mapfile_parser" -version = "2.7.1" +version = "2.7.2" description = "Map file parser library focusing decompilation projects" readme = "README.md" -requires-python = ">=3.8" +requires-python = ">=3.9" dependencies = [ "requests" ] diff --git a/src/mapfile_parser/__init__.py b/src/mapfile_parser/__init__.py index 22c9713..80ba531 100644 --- a/src/mapfile_parser/__init__.py +++ b/src/mapfile_parser/__init__.py @@ -5,7 +5,7 @@ from __future__ import annotations -__version_info__ = (2, 7, 1) +__version_info__ = (2, 7, 2) __version__ = ".".join(map(str, __version_info__))# + "-dev0" __author__ = "Decompollaborate" diff --git a/src/rs/file.rs b/src/rs/file.rs index f4ad780..9b9919c 100644 --- a/src/rs/file.rs +++ b/src/rs/file.rs @@ -379,7 +379,7 @@ impl Hash for File { #[cfg(feature = "python_bindings")] #[allow(non_snake_case)] pub(crate) mod python_bindings { - use pyo3::{intern, prelude::*}; + use pyo3::{intern, prelude::*, IntoPyObjectExt}; use std::path::PathBuf; @@ -390,9 +390,12 @@ pub(crate) mod python_bindings { use std::collections::hash_map::DefaultHasher; + use super::*; + #[pymethods] - impl super::File { + impl File { #[new] + #[pyo3(signature = (filepath, vram, size, section_type, vrom=None, align=None))] fn py_new( filepath: PathBuf, vram: u64, @@ -414,7 +417,7 @@ pub(crate) mod python_bindings { let pathlib_path = pathlib.getattr(intern!(py, "Path"))?; let args = (self.filepath.clone(),); - Ok(pathlib_path.call1(args)?.to_object(py)) + pathlib_path.call1(args)?.into_py_any(py) }) } diff --git a/src/rs/found_symbol_info.rs b/src/rs/found_symbol_info.rs index c67b5d2..a67ebeb 100644 --- a/src/rs/found_symbol_info.rs +++ b/src/rs/found_symbol_info.rs @@ -132,6 +132,7 @@ pub(crate) mod python_bindings { } #[pyo3(name = "getAsStrPlusOffset")] + #[pyo3(signature = (sym_name=None))] fn getAsStrPlusOffset(&self, sym_name: Option) -> String { let temp = super::FoundSymbolInfo::from(self); temp.get_as_str_plus_offset(sym_name) @@ -144,7 +145,7 @@ pub(crate) mod python_bindings { } } - impl<'a> From> for PyFoundSymbolInfo { + impl From> for PyFoundSymbolInfo { fn from(value: super::FoundSymbolInfo) -> Self { Self::new(value.file.clone(), value.symbol.clone(), value.offset) } diff --git a/src/rs/lib.rs b/src/rs/lib.rs index a3b4751..6006264 100644 --- a/src/rs/lib.rs +++ b/src/rs/lib.rs @@ -28,7 +28,7 @@ use pyo3::prelude::*; #[cfg(feature = "python_bindings")] #[pymodule] -fn mapfile_parser(_py: Python<'_>, m: &PyModule) -> PyResult<()> { +fn mapfile_parser(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; diff --git a/src/rs/maps_comparison_info.rs b/src/rs/maps_comparison_info.rs index b6ce064..914af46 100644 --- a/src/rs/maps_comparison_info.rs +++ b/src/rs/maps_comparison_info.rs @@ -14,7 +14,7 @@ pub struct MapsComparisonInfo<'a> { pub compared_list: Vec>, } -impl<'a> MapsComparisonInfo<'a> { +impl MapsComparisonInfo<'_> { pub fn new() -> Self { Self { bad_files: HashSet::new(), @@ -24,7 +24,7 @@ impl<'a> MapsComparisonInfo<'a> { } } -impl<'a> Default for MapsComparisonInfo<'a> { +impl Default for MapsComparisonInfo<'_> { fn default() -> Self { Self::new() } @@ -116,7 +116,7 @@ pub(crate) mod python_bindings { } } - impl<'a> From> for PyMapsComparisonInfo { + impl From> for PyMapsComparisonInfo { fn from(value: super::MapsComparisonInfo) -> Self { Self { bad_files: value.bad_files.into_iter().cloned().collect(), diff --git a/src/rs/segment.rs b/src/rs/segment.rs index 81bac3c..4914de3 100644 --- a/src/rs/segment.rs +++ b/src/rs/segment.rs @@ -328,6 +328,7 @@ pub(crate) mod python_bindings { #[pymethods] impl super::Segment { #[new] + #[pyo3(signature = (name, vram, size, vrom, align=None))] fn py_new(name: String, vram: u64, size: u64, vrom: u64, align: Option) -> Self { Self::new(name, vram, size, vrom, align) } diff --git a/src/rs/symbol.rs b/src/rs/symbol.rs index 39a2c1e..743c77e 100644 --- a/src/rs/symbol.rs +++ b/src/rs/symbol.rs @@ -23,11 +23,6 @@ pub struct Symbol { pub vrom: Option, pub align: Option, - - // idk if it is worth to continue maintaining this, given the complexity introduced by other features - #[cfg(feature = "python_bindings")] - #[cfg_attr(feature = "serde", serde(skip))] - chached_name: Option, } impl Symbol { @@ -44,9 +39,6 @@ impl Symbol { size, vrom, align, - - #[cfg(feature = "python_bindings")] - chached_name: None, } } @@ -57,9 +49,6 @@ impl Symbol { size: None, vrom: None, align: None, - - #[cfg(feature = "python_bindings")] - chached_name: None, } } @@ -125,8 +114,7 @@ impl Hash for Symbol { #[cfg(feature = "python_bindings")] #[allow(non_snake_case)] pub(crate) mod python_bindings { - use pyo3::prelude::*; - use pyo3::types::IntoPyDict; + use pyo3::{prelude::*, types::IntoPyDict, IntoPyObjectExt}; use std::collections::hash_map::DefaultHasher; @@ -150,14 +138,8 @@ pub(crate) mod python_bindings { /* Getters and setters */ #[getter] - fn get_name(&mut self) -> PyObject { - Python::with_gil(|py| { - if self.chached_name.is_none() { - self.chached_name = Some(self.name.to_object(py)); - } - - self.chached_name.as_ref().unwrap().to_object(py) - }) + fn get_name(&self) -> PyResult<&str> { + Ok(&self.name) } #[setter] @@ -213,58 +195,58 @@ pub(crate) mod python_bindings { /* Serializers */ #[pyo3(signature=(_humanReadable=true))] - fn serializeName(&self, _humanReadable: bool) -> PyObject { - Python::with_gil(|py| self.name.to_object(py)) + fn serializeName(&self, _humanReadable: bool) -> PyResult { + Python::with_gil(|py| self.name.clone().into_py_any(py)) } #[pyo3(signature=(humanReadable=true))] - fn serializeVram(&self, humanReadable: bool) -> PyObject { + fn serializeVram(&self, humanReadable: bool) -> PyResult { Python::with_gil(|py| { if humanReadable { - return format!("0x{:08X}", self.vram).to_object(py); + return format!("0x{:08X}", self.vram).into_py_any(py); } - self.vram.to_object(py) + self.vram.into_py_any(py) }) } #[pyo3(signature=(humanReadable=true))] - fn serializeSize(&self, humanReadable: bool) -> PyObject { + fn serializeSize(&self, humanReadable: bool) -> PyResult { Python::with_gil(|py| match self.size { - None => Python::None(py), + None => Ok(Python::None(py)), Some(size) => { if humanReadable { - return format!("0x{:X}", size).to_object(py); + return format!("0x{:X}", size).into_py_any(py); } - size.to_object(py) + size.into_py_any(py) } }) } #[pyo3(signature=(humanReadable=true))] - fn serializeVrom(&self, humanReadable: bool) -> PyObject { + fn serializeVrom(&self, humanReadable: bool) -> PyResult { Python::with_gil(|py| match self.vrom { - None => Python::None(py), + None => Ok(Python::None(py)), Some(vrom) => { if humanReadable { - return format!("0x{:06X}", vrom).to_object(py); + return format!("0x{:06X}", vrom).into_py_any(py); } - vrom.to_object(py) + vrom.into_py_any(py) } }) } #[pyo3(signature=(humanReadable=true))] - fn toJson(&self, humanReadable: bool) -> PyObject { + fn toJson(&self, humanReadable: bool) -> PyResult { Python::with_gil(|py| { [ - ("name", self.serializeName(humanReadable)), - ("vram", self.serializeVram(humanReadable)), - ("size", self.serializeSize(humanReadable)), - ("vrom", self.serializeVrom(humanReadable)), + ("name", self.serializeName(humanReadable)?), + ("vram", self.serializeVram(humanReadable)?), + ("size", self.serializeSize(humanReadable)?), + ("vrom", self.serializeVrom(humanReadable)?), ] - .into_py_dict(py) - .to_object(py) + .into_py_dict(py)? + .into_py_any(py) }) } diff --git a/src/rs/symbol_comparison_info.rs b/src/rs/symbol_comparison_info.rs index a7d502f..deee057 100644 --- a/src/rs/symbol_comparison_info.rs +++ b/src/rs/symbol_comparison_info.rs @@ -174,7 +174,7 @@ pub(crate) mod python_bindings { } } - impl<'a> From> for PySymbolComparisonInfo { + impl From> for PySymbolComparisonInfo { fn from(value: super::SymbolComparisonInfo) -> Self { Self::new( value.symbol.clone(),