diff --git a/.gitignore b/.gitignore index cf6ca89..29ab927 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ dist/ eggs/ lib/ lib64/ +lib64 parts/ sdist/ var/ @@ -28,6 +29,7 @@ venv/ *.egg-info/ .installed.cfg *.egg +pyvenv.cfg # Installer logs pip-log.txt diff --git a/Cargo.lock b/Cargo.lock index f67e630..a3a00a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,12 +8,6 @@ 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" @@ -21,10 +15,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "indoc" -version = "1.0.9" +name = "heck" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "indoc" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "libc" @@ -32,16 +32,6 @@ 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" @@ -58,48 +48,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] -name = "parking_lot" -version = "0.12.1" +name = "portable-atomic" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -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", -] +checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.19.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e681a6cfdc4adcc93b4d3cf993749a4552018ee0a9b65fc0ccfad74352c72a38" +checksum = "e484fd2c8b4cb67ab05a318f1fd6fa8f199fcc30819f08f07d200809dba26c15" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", + "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", @@ -108,9 +82,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.19.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076c73d0bc438f7a4ef6fdd0c3bb4732149136abd952b110ac93e4edb13a6ba5" +checksum = "dc0e0469a84f208e20044b98965e1561028180219e35352a2afaf2b942beff3b" dependencies = [ "once_cell", "target-lexicon", @@ -118,9 +92,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.19.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53cee42e77ebe256066ba8aa77eff722b3bb91f3419177cf4cd0f304d3284d9" +checksum = "eb1547a7f9966f6f1a0f0227564a9945fe36b90da5a93b3933fc3dc03fae372d" dependencies = [ "libc", "pyo3-build-config", @@ -128,9 +102,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.19.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfeb4c99597e136528c6dd7d5e3de5434d1ceaf487436a3f03b2d56b6fc9efd1" +checksum = "fdb6da8ec6fa5cedd1626c886fc8749bdcbb09424a86461eb8cdf096b7c33257" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -140,50 +114,31 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.19.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "947dc12175c254889edc0c02e399476c2f652b4b9ebd123aa655c224de259536" +checksum = "38a385202ff5a92791168b1136afae5059d3ac118457bb7bc304c197c2d33e7d" dependencies = [ + "heck", "proc-macro2", + "pyo3-build-config", "quote", "syn", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -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" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -192,9 +147,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.12" +version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tictoc" @@ -211,63 +166,6 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unindent" -version = "0.1.11" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -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" +checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" diff --git a/Cargo.toml b/Cargo.toml index 553dc4a..d03a33d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,4 @@ name = "tictoc" crate-type = ["cdylib"] [dependencies] -pyo3 = "0.19.0" +pyo3 = "0.23.3" diff --git a/requirements.txt b/requirements.txt index db9c234..a22da45 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.3.1 +maturin==1.7.8 packaging==23.2 pluggy==1.3.0 pytest==7.4.3 diff --git a/src/lib.rs b/src/lib.rs index 4974904..a802ae3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,92 +1,90 @@ use pyo3::prelude::*; -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(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, - } - } - - 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(()) - } - } -} #[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) +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(name = "init")] + pub 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, + } + } + + 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) + } } diff --git a/tictoc/__init__.py b/tictoc/__init__.py new file mode 100644 index 0000000..170a70b --- /dev/null +++ b/tictoc/__init__.py @@ -0,0 +1,9 @@ +from .tictoc import * + +__doc__ = tictoc.__doc__ +if hasattr(tictoc, "__all__"): + __all__ = tictoc.__all__ + +results = tictoc.init(); +tic = results.tic; +toc = results.toc;