From 4df5db7c3a08824aa4a1fdc96b39467d95294df5 Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Wed, 4 Jun 2025 14:41:29 -0400 Subject: [PATCH 01/10] migrate pyo3 from 0.20 to 0.21 Followed steps listed here: https://pyo3.rs/v0.25.0/migration.html#from-020-to-021 --- bindings/python/Cargo.toml | 4 ++-- bindings/python/src/codelist.rs | 8 ++++---- bindings/python/src/lib.rs | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) mode change 100644 => 100755 bindings/python/src/codelist.rs diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index 68ddb97..99ea057 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -8,8 +8,8 @@ name = "codelists_rs" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.20.3", features = ["extension-module"] } +pyo3 = { version = "0.21", features = ["extension-module"] } chrono = { version = "0.4.39", features = ["serde"] } codelist-rs = { path = "../../rust/codelist-rs" } codelist-validator-rs = { path = "../../rust/codelist-validator-rs" } -indexmap = "2.9.0" \ No newline at end of file +indexmap = "2.9.0" diff --git a/bindings/python/src/codelist.rs b/bindings/python/src/codelist.rs old mode 100644 new mode 100755 index b6dae16..5ad4a72 --- a/bindings/python/src/codelist.rs +++ b/bindings/python/src/codelist.rs @@ -129,7 +129,7 @@ impl PyCodeList { #[getter] fn contributors(&self, py: Python) -> PyResult { - let py_set = PySet::new(py, &[] as &[String])?; + let py_set = PySet::new_bound(py, &[] as &[String])?; for contributor in &self.inner.metadata.provenance.contributors { py_set.add(contributor)?; } @@ -141,7 +141,7 @@ impl PyCodeList { let date_created = self.inner.metadata.provenance.created_date; let last_modified_date = self.inner.metadata.provenance.last_modified_date; - let dict = PyDict::new(py); + let dict = PyDict::new_bound(py); dict.set_item("date_created", date_created.to_string())?; dict.set_item("last_modified_date", last_modified_date.to_string())?; @@ -151,7 +151,7 @@ impl PyCodeList { /// Get tag information fn get_tags(&self, py: Python) -> PyResult { let tags = self.inner.metadata.categorisation_and_usage.tags.clone(); - let py_set = PySet::new(py, &[] as &[String])?; + let py_set = PySet::new_bound(py, &[] as &[String])?; for tag in tags { py_set.add(tag)?; } @@ -181,7 +181,7 @@ impl PyCodeList { /// Get usage information fn get_usage(&self, py: Python) -> PyResult { let usage = self.inner.metadata.categorisation_and_usage.usage.clone(); - let py_set = PySet::new(py, &[] as &[String])?; + let py_set = PySet::new_bound(py, &[] as &[String])?; for usage_item in usage { py_set.add(usage_item)?; } diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 31e6c10..1d90f9f 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -11,22 +11,22 @@ use factory::PyCodeListFactory; /// Top-level Python module `codelists_rs` #[pymodule] -fn codelists_rs(py: Python, m: &PyModule) -> PyResult<()> { +fn codelists_rs(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { // Add codelist submodule - let codelist_module = PyModule::new(py, "codelist")?; + let codelist_module = PyModule::new_bound(py, "codelist")?; codelist_module.add_class::()?; - m.add_submodule(codelist_module)?; + m.add_submodule(&codelist_module)?; // Register it globally under the full dotted path - py.import("sys")?.getattr("modules")?.set_item("codelists_rs.codelist", codelist_module)?; + py.import_bound("sys")?.getattr("modules")?.set_item("codelists_rs.codelist", codelist_module)?; // Add factory submodule - let factory_module = PyModule::new(py, "factory")?; + let factory_module = PyModule::new_bound(py, "factory")?; factory_module.add_class::()?; - m.add_submodule(factory_module)?; + m.add_submodule(&factory_module)?; // Register it globally under the full dotted path - py.import("sys")?.getattr("modules")?.set_item("codelists_rs.factory", factory_module)?; + py.import_bound("sys")?.getattr("modules")?.set_item("codelists_rs.factory", factory_module)?; Ok(()) } From d13aeabf2a06d686f479c7e0e2e3e79e0b4ae5af Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Wed, 4 Jun 2025 14:58:25 -0400 Subject: [PATCH 02/10] migrate pyo3 from 0.21 to 0.22 Followed the guide here: https://pyo3.rs/v0.25.0/migration.html#from-021-to-022 This allowed upgrading Python from 3.12 to 3.13 --- bindings/python/Cargo.toml | 2 +- bindings/python/src/codelist.rs | 3 ++- bindings/python/src/lib.rs | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index 99ea057..1d38f7d 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -8,7 +8,7 @@ name = "codelists_rs" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.21", features = ["extension-module"] } +pyo3 = { version = "0.22", features = ["extension-module"] } chrono = { version = "0.4.39", features = ["serde"] } codelist-rs = { path = "../../rust/codelist-rs" } codelist-validator-rs = { path = "../../rust/codelist-validator-rs" } diff --git a/bindings/python/src/codelist.rs b/bindings/python/src/codelist.rs index 5ad4a72..ed2720f 100755 --- a/bindings/python/src/codelist.rs +++ b/bindings/python/src/codelist.rs @@ -91,7 +91,7 @@ impl PyCodeList { } /// Add an entry to the codelist - #[pyo3(text_signature = "($self, code, term=None, comment=None)")] + #[pyo3(signature = (code, term=None, comment=None))] fn add_entry( &mut self, code: String, @@ -370,6 +370,7 @@ impl PyCodeList { } /// Add Validation Information to the codelist + #[pyo3(signature = (reviewer, status=None, notes=None))] fn add_validation_info( &mut self, reviewer: String, diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 1d90f9f..e5cfde8 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -18,7 +18,9 @@ fn codelists_rs(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_submodule(&codelist_module)?; // Register it globally under the full dotted path - py.import_bound("sys")?.getattr("modules")?.set_item("codelists_rs.codelist", codelist_module)?; + py.import_bound("sys")? + .getattr("modules")? + .set_item("codelists_rs.codelist", codelist_module)?; // Add factory submodule let factory_module = PyModule::new_bound(py, "factory")?; From 886e1e159a7fef9fefe59f29cf041414f1d9ba94 Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Wed, 4 Jun 2025 15:07:24 -0400 Subject: [PATCH 03/10] migrate from pyo3 0.22 to 0.23 --- bindings/python/Cargo.toml | 2 +- bindings/python/src/codelist.rs | 8 ++++---- bindings/python/src/lib.rs | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index 1d38f7d..3a66a3a 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -8,7 +8,7 @@ name = "codelists_rs" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.22", features = ["extension-module"] } +pyo3 = { version = "0.23", features = ["extension-module"] } chrono = { version = "0.4.39", features = ["serde"] } codelist-rs = { path = "../../rust/codelist-rs" } codelist-validator-rs = { path = "../../rust/codelist-validator-rs" } diff --git a/bindings/python/src/codelist.rs b/bindings/python/src/codelist.rs index ed2720f..b99441b 100755 --- a/bindings/python/src/codelist.rs +++ b/bindings/python/src/codelist.rs @@ -129,7 +129,7 @@ impl PyCodeList { #[getter] fn contributors(&self, py: Python) -> PyResult { - let py_set = PySet::new_bound(py, &[] as &[String])?; + let py_set = PySet::new(py, &[] as &[String])?; for contributor in &self.inner.metadata.provenance.contributors { py_set.add(contributor)?; } @@ -141,7 +141,7 @@ impl PyCodeList { let date_created = self.inner.metadata.provenance.created_date; let last_modified_date = self.inner.metadata.provenance.last_modified_date; - let dict = PyDict::new_bound(py); + let dict = PyDict::new(py); dict.set_item("date_created", date_created.to_string())?; dict.set_item("last_modified_date", last_modified_date.to_string())?; @@ -151,7 +151,7 @@ impl PyCodeList { /// Get tag information fn get_tags(&self, py: Python) -> PyResult { let tags = self.inner.metadata.categorisation_and_usage.tags.clone(); - let py_set = PySet::new_bound(py, &[] as &[String])?; + let py_set = PySet::new(py, &[] as &[String])?; for tag in tags { py_set.add(tag)?; } @@ -181,7 +181,7 @@ impl PyCodeList { /// Get usage information fn get_usage(&self, py: Python) -> PyResult { let usage = self.inner.metadata.categorisation_and_usage.usage.clone(); - let py_set = PySet::new_bound(py, &[] as &[String])?; + let py_set = PySet::new(py, &[] as &[String])?; for usage_item in usage { py_set.add(usage_item)?; } diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index e5cfde8..66b417b 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -13,22 +13,22 @@ use factory::PyCodeListFactory; #[pymodule] fn codelists_rs(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { // Add codelist submodule - let codelist_module = PyModule::new_bound(py, "codelist")?; + let codelist_module = PyModule::new(py, "codelist")?; codelist_module.add_class::()?; m.add_submodule(&codelist_module)?; // Register it globally under the full dotted path - py.import_bound("sys")? + py.import("sys")? .getattr("modules")? .set_item("codelists_rs.codelist", codelist_module)?; // Add factory submodule - let factory_module = PyModule::new_bound(py, "factory")?; + let factory_module = PyModule::new(py, "factory")?; factory_module.add_class::()?; m.add_submodule(&factory_module)?; // Register it globally under the full dotted path - py.import_bound("sys")?.getattr("modules")?.set_item("codelists_rs.factory", factory_module)?; + py.import("sys")?.getattr("modules")?.set_item("codelists_rs.factory", factory_module)?; Ok(()) } From 8c5f30dee4bd8122d40df23200d7cdfda8cf5d0a Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Wed, 4 Jun 2025 15:10:50 -0400 Subject: [PATCH 04/10] migrate pyo3 from 0.23 to 0.25 changed 0.23 to 0.24 with no issues changed 0.24 to 0.25 with no issues --- bindings/python/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index 3a66a3a..1166fef 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -8,7 +8,7 @@ name = "codelists_rs" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.23", features = ["extension-module"] } +pyo3 = { version = "0.25", features = ["extension-module"] } chrono = { version = "0.4.39", features = ["serde"] } codelist-rs = { path = "../../rust/codelist-rs" } codelist-validator-rs = { path = "../../rust/codelist-validator-rs" } From 8ae2271cdefe52ebdceb55a567ec9bee1f074f34 Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Wed, 4 Jun 2025 15:28:20 -0400 Subject: [PATCH 05/10] Hm. is rustfmt from my editor not the same as cargo fmt? --- bindings/python/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 66b417b..6275eb7 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -18,9 +18,7 @@ fn codelists_rs(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_submodule(&codelist_module)?; // Register it globally under the full dotted path - py.import("sys")? - .getattr("modules")? - .set_item("codelists_rs.codelist", codelist_module)?; + py.import("sys")?.getattr("modules")?.set_item("codelists_rs.codelist", codelist_module)?; // Add factory submodule let factory_module = PyModule::new(py, "factory")?; From e6ef8e22604492fee5c342505a06e9e049961622 Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Wed, 4 Jun 2025 18:30:24 -0400 Subject: [PATCH 06/10] test Python 3.13 too! --- .github/workflows/run_python_unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_python_unit_tests.yml b/.github/workflows/run_python_unit_tests.yml index 87e2809..5002baf 100644 --- a/.github/workflows/run_python_unit_tests.yml +++ b/.github/workflows/run_python_unit_tests.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.9", "3.10", "3.11", "3.12" ] + python-version: [ "3.9", "3.10", "3.11", "3.12" "3.13"] steps: - uses: actions/checkout@v3 From 0a552a8d17ef50e9e86c73a5a84334ada08dee05 Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Wed, 4 Jun 2025 18:33:29 -0400 Subject: [PATCH 07/10] whitepace, really? --- .github/workflows/run_python_unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_python_unit_tests.yml b/.github/workflows/run_python_unit_tests.yml index 5002baf..9380f93 100644 --- a/.github/workflows/run_python_unit_tests.yml +++ b/.github/workflows/run_python_unit_tests.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.9", "3.10", "3.11", "3.12" "3.13"] + python-version: [ "3.9", "3.10", "3.11", "3.12" "3.13" ] steps: - uses: actions/checkout@v3 From cf6b6d5d696ffd61f4c1b08a4be6abffc3f8bd78 Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Wed, 4 Jun 2025 18:34:15 -0400 Subject: [PATCH 08/10] no, comma...grr --- .github/workflows/run_python_unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_python_unit_tests.yml b/.github/workflows/run_python_unit_tests.yml index 9380f93..e9afc40 100644 --- a/.github/workflows/run_python_unit_tests.yml +++ b/.github/workflows/run_python_unit_tests.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.9", "3.10", "3.11", "3.12" "3.13" ] + python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ] steps: - uses: actions/checkout@v3 From d62c8842a4954de8a199a64a9fceff651dd1d8fa Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Wed, 4 Jun 2025 18:37:07 -0400 Subject: [PATCH 09/10] wot? --- .github/workflows/run_python_unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_python_unit_tests.yml b/.github/workflows/run_python_unit_tests.yml index e9afc40..87e2809 100644 --- a/.github/workflows/run_python_unit_tests.yml +++ b/.github/workflows/run_python_unit_tests.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ] + python-version: [ "3.9", "3.10", "3.11", "3.12" ] steps: - uses: actions/checkout@v3 From 5630fab56318de5ad8899ef88ec60674bf2e4028 Mon Sep 17 00:00:00 2001 From: CarolineMorton Date: Thu, 5 Jun 2025 10:07:53 +0100 Subject: [PATCH 10/10] testing if this works! --- .github/workflows/run_python_unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_python_unit_tests.yml b/.github/workflows/run_python_unit_tests.yml index 87e2809..e9afc40 100644 --- a/.github/workflows/run_python_unit_tests.yml +++ b/.github/workflows/run_python_unit_tests.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.9", "3.10", "3.11", "3.12" ] + python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ] steps: - uses: actions/checkout@v3