diff --git a/.gitignore b/.gitignore index 29ab927..cf6ca89 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,6 @@ dist/ eggs/ lib/ lib64/ -lib64 parts/ sdist/ var/ @@ -29,7 +28,6 @@ venv/ *.egg-info/ .installed.cfg *.egg -pyvenv.cfg # Installer logs pip-log.txt diff --git a/Cargo.lock b/Cargo.lock index a3a00a4..f67e630 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,23 +8,23 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - [[package]] name = "indoc" -version = "2.0.5" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" +checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" [[package]] name = "libc" @@ -32,6 +32,16 @@ version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "memoffset" version = "0.9.0" @@ -48,32 +58,48 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] -name = "portable-atomic" -version = "1.10.0" +name = "parking_lot" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.23.3" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e484fd2c8b4cb67ab05a318f1fd6fa8f199fcc30819f08f07d200809dba26c15" +checksum = "e681a6cfdc4adcc93b4d3cf993749a4552018ee0a9b65fc0ccfad74352c72a38" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "once_cell", - "portable-atomic", + "parking_lot", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", @@ -82,9 +108,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.23.3" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e0469a84f208e20044b98965e1561028180219e35352a2afaf2b942beff3b" +checksum = "076c73d0bc438f7a4ef6fdd0c3bb4732149136abd952b110ac93e4edb13a6ba5" dependencies = [ "once_cell", "target-lexicon", @@ -92,9 +118,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.23.3" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1547a7f9966f6f1a0f0227564a9945fe36b90da5a93b3933fc3dc03fae372d" +checksum = "e53cee42e77ebe256066ba8aa77eff722b3bb91f3419177cf4cd0f304d3284d9" dependencies = [ "libc", "pyo3-build-config", @@ -102,9 +128,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.23.3" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdb6da8ec6fa5cedd1626c886fc8749bdcbb09424a86461eb8cdf096b7c33257" +checksum = "dfeb4c99597e136528c6dd7d5e3de5434d1ceaf487436a3f03b2d56b6fc9efd1" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -114,31 +140,50 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.23.3" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38a385202ff5a92791168b1136afae5059d3ac118457bb7bc304c197c2d33e7d" +checksum = "947dc12175c254889edc0c02e399476c2f652b4b9ebd123aa655c224de259536" dependencies = [ - "heck", "proc-macro2", - "pyo3-build-config", "quote", "syn", ] [[package]] name = "quote" -version = "1.0.37" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] [[package]] -name = "syn" -version = "2.0.90" +name = "redox_syscall" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "smallvec" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", @@ -147,9 +192,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.16" +version = "0.12.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" +checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" [[package]] name = "tictoc" @@ -166,6 +211,63 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unindent" -version = "0.2.3" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" +checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/Cargo.toml b/Cargo.toml index d03a33d..553dc4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,4 @@ name = "tictoc" crate-type = ["cdylib"] [dependencies] -pyo3 = "0.23.3" +pyo3 = "0.19.0" diff --git a/requirements.txt b/requirements.txt index a22da45..db9c234 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ charset-normalizer==3.3.2 coverage==7.3.2 idna==3.4 iniconfig==2.0.0 -maturin==1.7.8 +maturin==1.3.1 packaging==23.2 pluggy==1.3.0 pytest==7.4.3 diff --git a/src/lib.rs b/src/lib.rs index a802ae3..4974904 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,90 +1,92 @@ use pyo3::prelude::*; +use std::time::Instant; +use pyo3::exceptions::PyException; -#[pymodule] -mod tictoc { - use super::*; - use std::time::Instant; - use pyo3::exceptions::PyException; - - #[pyclass] - #[derive(Clone)] - struct Results { - #[pyo3(get)] - nanos: u128, - #[pyo3(get)] - micros: u128, - #[pyo3(get)] - millis: u128, - #[pyo3(get)] - seconds: f64, +#[pyclass] +#[derive(Clone)] +struct Results { + #[pyo3(get)] + nanos: u128, + #[pyo3(get)] + micros: u128, + #[pyo3(get)] + millis: u128, + #[pyo3(get)] + seconds: f64, +} + +#[pyclass(module = "tictoc", name = "init")] +struct Init { + time: Instant, + #[pyo3(get)] + results: Results, + status: bool, +} + +#[pymethods] +impl Init { + #[new] + fn new() -> Self { + let res = Results { + nanos: 0, + micros: 0, + millis: 0, + seconds: 0.0, + }; + Init { + time: Instant::now(), + results: res, + status: false, + } } - - #[pyclass(name = "init")] - pub struct Init { - time: Instant, - #[pyo3(get)] - results: Results, - status: bool, + + fn tic(&mut self) { + self.time = Instant::now(); + self.status = true; } - - #[pymethods] - impl Init { - #[new] - fn new() -> Self { - let res = Results { - nanos: 0, - micros: 0, - millis: 0, - seconds: 0.0, + + fn toc(&mut self) -> PyResult<()> { + if self.status == false { + Err(PyException::new_err("tic() must be called before toc()")) + } else { + let elapsed_time = self.time.elapsed(); + self.results = Results { + nanos: elapsed_time.as_nanos(), + micros: elapsed_time.as_micros(), + millis: elapsed_time.as_millis(), + seconds: elapsed_time.as_secs_f64(), }; - Init { - time: Instant::now(), - results: res, - status: false, - } + Ok(()) } - - fn tic(&mut self) { - self.time = Instant::now(); - self.status = true; - } - - fn toc(&mut self) -> PyResult<()> { - if self.status == false { - Err(PyException::new_err("tic() must be called before toc()")) - } else { - let elapsed_time = self.time.elapsed(); - self.results = Results { - nanos: elapsed_time.as_nanos(), - micros: elapsed_time.as_micros(), - millis: elapsed_time.as_millis(), - seconds: elapsed_time.as_secs_f64(), - }; - Ok(()) - } - } - } - #[test] - fn test_new() { - let init = Init::new(); - assert_eq!(init.results.nanos,0); - } - - #[test] - fn test_tic() { - let mut init = Init::new(); - let time1 = init.time; - init.tic(); - let time2 = init.time; - assert!(time2 > time1) - } - - #[test] - fn test_toc() { - let mut init = Init::new(); - init.tic(); - println!("{}","test"); - let _ = init.toc(); - assert!(init.results.nanos > 0) } } + +#[pymodule] +fn tictoc(_py: Python<'_>, m: &PyModule) -> PyResult<()> { + m.add_class::()?; + Ok(()) +} + +#[test] +fn test_new() { + let init = Init::new(); + assert_eq!(init.results.nanos,0); +} + +#[test] +fn test_tic() { + let mut init = Init::new(); + let time1 = init.time; + init.tic(); + let time2 = init.time; + assert!(time2 > time1) +} + +#[test] +fn test_toc() { + let mut init = Init::new(); + init.tic(); + println!("{}","test"); + let _ = init.toc(); + assert!(init.results.nanos > 0) +} diff --git a/tictoc/__init__.py b/tictoc/__init__.py deleted file mode 100644 index 170a70b..0000000 --- a/tictoc/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -from .tictoc import * - -__doc__ = tictoc.__doc__ -if hasattr(tictoc, "__all__"): - __all__ = tictoc.__all__ - -results = tictoc.init(); -tic = results.tic; -toc = results.toc;