diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3efcdbf..020bf5f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,6 @@ name: Build on: + workflow_dispatch: push: branches: - main diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 60ccc1b..bd73400 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,4 +1,4 @@ -name: Deploy docs to GitHub Pages +name: Update docs on: workflow_dispatch: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 201fef4..77ea482 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,9 @@ -name: Lint and Test +name: Tests on: workflow_dispatch: + workflow_call: push: branches: [ main ] pull_request: diff --git a/README.md b/README.md index ecc21ea..3c204f0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Lint and Test](https://github.com/vemonet/nanopub-rs/actions/workflows/test.yml/badge.svg)](https://github.com/vemonet/nanopub-rs/actions/workflows/test.yml) [![Build](https://github.com/vemonet/nanopub-rs/actions/workflows/build.yml/badge.svg)](https://github.com/vemonet/nanopub-rs/actions/workflows/build.yml) [![Deploy docs to GitHub Pages](https://github.com/vemonet/nanopub-rs/actions/workflows/docs.yml/badge.svg)](https://github.com/vemonet/nanopub-rs/actions/workflows/docs.yml) -A rust toolkit to sign and publish [Nanopublications](https://nanopub.net), with bindings to python and javascript (wasm). +A Rust toolkit to sign and publish [Nanopublications](https://nanopub.net), with bindings to Python and JavaScript (using WebAssembly). ## Nanopub signing process @@ -13,62 +13,55 @@ A rust toolkit to sign and publish [Nanopublications](https://nanopub.net), with - Trusty URI code is calculated on normalized representation that includes signature - Trusty URI code is added in place of all the occurrences of blank spaces in the URIs, leading to the final trusty nanopub -## Run the library to test - -```bash -cd lib/ -cargo test -``` - -> Checkout the README in the `python` and `js` folder for the instructions to build and test for each language - ## Development +[Rust](https://www.rust-lang.org/tools/install), python and NodeJS are required for development. + Install development dependencies: + ```bash rustup update rustup component add rustfmt clippy ``` -### Build and run all packages +### Run tests -All packages at once: +Run tests for all packages: ```bash -cargo build --all -cargo run --all-features +cargo test ``` -Just the rust package: +Display prints: ```bash -cargo test lib +cargo test -- --nocapture ``` -### Format +Run all tests? ```bash -cargo fmt +cargo test --verbose --all --all-features ``` -### Lint +Test a specific package: ```bash -cargo clippy --all --all-targets --all-features +cargo test lib ``` -### Run tests +> Checkout the README in the `python` and `js` folder for the instructions to build and test for each language -Display prints: +### Format ```bash -cargo test -- --nocapture +cargo fmt ``` -Run all tests: +### Lint ```bash -cargo test --verbose --all --all-features +cargo clippy --all --all-targets --all-features ``` ### Generate docs @@ -77,6 +70,15 @@ cargo test --verbose --all --all-features ./scripts/docs-serve.sh ``` +### Build and run all packages + +All packages at once: + +```bash +cargo build --all +cargo run --all-features +``` + ## Useful links https://github.com/briansmith/ring diff --git a/js/index.html b/js/index.html index 25a4a19..0814456 100644 --- a/js/index.html +++ b/js/index.html @@ -58,6 +58,7 @@ const publish=false; const rdfText = document.getElementById('rdf-text'); + // WebAssembly binary needs to be initialized before use init().then(() => { const np = new Nanopub( rdfStr, diff --git a/js/src/nanopub.rs b/js/src/nanopub.rs index 900d566..105cbba 100644 --- a/js/src/nanopub.rs +++ b/js/src/nanopub.rs @@ -1,4 +1,4 @@ -use nanopub::nanopub::Nanopub; +use nanopub::Nanopub; use wasm_bindgen::prelude::*; #[wasm_bindgen(js_name = Nanopub)] diff --git a/lib/docs/src/01_getting_started.md b/lib/docs/src/01_getting_started.md index 742f424..e1ea5be 100644 --- a/lib/docs/src/01_getting_started.md +++ b/lib/docs/src/01_getting_started.md @@ -7,7 +7,7 @@ ```rust use std::fs; -use nanopub::nanopub::Nanopub; +use nanopub::Nanopub; let public_key = r#"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo2NYLBcZmpOkjgqLiT7hMxzRaK5KhYYHxxN2gCAMfmOaulAxAzPUNBJLIXjX3yQeIj6rAH4ha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m71oTwhmvm6gSLfjzqb8GLrmflCK4lKPDSTdwyvd+2SSmOXySw94zr1Pvc7sHdmMRyA7mH3m+zSOOgyCTTKyhDRCNcRIkysoL+DecDhNo4Fumf71tsqDYogfxpAQhn0re8wKBgQDXhMmmT2oXiMnYHhi2k7CJe3HUqkZgmW4W44SWqKHp0V6sjcHm0N0RT5Hz1BFFUd5Y0ZB3JLcah19myD1kKYCj7xz6oVLb8O7LeAZNlb0FsrtD7NU+Hciywo8qESiA7UYDkU6+hsmxaI01DsttMIdG4lSBbEjA7t4IQC5lyr7xiQKBgQCN87YGJ40Y5ZXCSgOZDepz9hqX2KGOIfnUv2HvXsIfiUwqTXs6HbD18xg3KL4myIBOvywSM+4ABYp+foY+Cpcq2btLIeZhiWjsKIrw71+Q/vIe0YDb1PGf6DsoYhmWBpdHzR9HN+hGjvwlsYny2L9Qbfhgxxmsuf7zeFLpQLijjwKBgH7TD28k8IOk5VKec2CNjKd600OYaA3UfCpP/OhDl/RmVtYoHWDcrBrRvkvEEd2/DZ8qw165Zl7gJs3vK+FTYvYVcfIzGPWA1KU7nkntwewmf3i7V8lT8ZTwVRsmObWU60ySJ8qKuwoBQodki2VX12NpMN1wgWe3qUUlr6gLJU4xAoGAet6nD3QKwk6TTmcGVfSWOzvpaDEzGkXjCLaxLKh9GreM/OE+h5aN2gUoFeQapG5rUwI/7Qq0xiLbRXw+OmfAoV2XKv7iI8DjdIh0F06mlEAwQ/B0CpbqkuuxphIbchtdcz/5ra233r3BMNIqBl3VDDVoJlgHPg9msOTRy13lFqc="#; diff --git a/lib/src/constants.rs b/lib/src/constants.rs index d5a4cc6..3930643 100644 --- a/lib/src/constants.rs +++ b/lib/src/constants.rs @@ -1,3 +1,10 @@ +// /// The URI used as placeholder for the Nanopub when signing it +pub const NORMALIZED_URI: &str = "http://purl.org/np/ARTIFACTCODE-PLACEHOLDER"; +pub const NORMALIZED_NS: &str = "http://purl.org/np/ARTIFACTCODE-PLACEHOLDER/"; + +pub const TEMP_NP_URI: &str = "http://purl.org/nanopub/temp/mynanopub"; +pub const TEMP_NP_NS: &str = "http://purl.org/nanopub/temp/mynanopub#"; + pub const TEST_SERVER: &str = "http://test-server.nanopubs.lod.labs.vu.nl/"; // /// Checkout the list of available servers at https://monitor.petapico.org @@ -9,10 +16,3 @@ pub const TEST_SERVER: &str = "http://test-server.nanopubs.lod.labs.vu.nl/"; // "http://app.tkuhn.eculture.labs.vu.nl/nanopub-server-3", // "http://app.tkuhn.eculture.labs.vu.nl/nanopub-server-4", // ]; - -// /// The URI used as placeholder for the Nanopub when signing it -pub const NORMALIZED_URI: &str = "http://purl.org/np/ARTIFACTCODE-PLACEHOLDER"; -pub const NORMALIZED_NS: &str = "http://purl.org/np/ARTIFACTCODE-PLACEHOLDER/"; - -pub const TEMP_NP_URI: &str = "http://purl.org/nanopub/temp/mynanopub"; -pub const TEMP_NP_NS: &str = "http://purl.org/nanopub/temp/mynanopub#"; diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 46f1f45..cc58c2e 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -16,7 +16,7 @@ mod namespaces; /// /// ``` /// use std::fs; -/// use nanopub::nanopub::Nanopub; +/// use nanopub::Nanopub; /// let private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCjY1gsFxmak6SOCouJPuEzHNForkqFhgfHE3aAIAx+Y5q6UDEDM9Q0EksheNffJB4iPqsAfiFpY0ARQY92K5r8P4+a78eu9reYrb2WxZb1qPJmvR7XZ6sN1oHD7dd/EyQoJmQsmOKdrqaLRbzR7tZrf52yvKkwNWXcIVhW8uxe7iUgxiojZpW9srKoK/qFRpaUZSKn7Z/zgtDH9FJkYbBsGPDMqp78Kzt+sJb+U2W+wCSSy34jIUxx6QRbzvn6uexc/emFw/1DU5y7zBudhgC7mVk8vX1gUNKyjZBzlOmRcretrANgffqs5fx/TMHN1xtkA/H1u1IKBfKoyk/xThMLAgMBAAECggEAECuG0GZ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aDEzGkXjCLaxLKh9GreM/OE+h5aN2gUoFeQapG5rUwI/7Qq0xiLbRXw+OmfAoV2XKv7iI8DjdIh0F06mlEAwQ/B0CpbqkuuxphIbchtdcz/5ra233r3BMNIqBl3VDDVoJlgHPg9msOTRy13lFqc="; /// let np_rdf = fs::read_to_string("./tests/resources/simple1-rsa.trig").unwrap(); /// let np = Nanopub::new( @@ -28,3 +28,5 @@ mod namespaces; /// ); /// ``` pub mod nanopub; + +pub use nanopub::Nanopub; diff --git a/lib/src/nanopub.rs b/lib/src/nanopub.rs index 18675e6..e2bb2fa 100644 --- a/lib/src/nanopub.rs +++ b/lib/src/nanopub.rs @@ -47,7 +47,7 @@ impl Nanopub { /// /// ``` /// use std::fs; - /// use nanopub::nanopub::Nanopub; + /// use nanopub::Nanopub; /// let private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCjY1gsFxmak6SOCouJPuEzHNForkqFhgfHE3aAIAx+Y5q6UDEDM9Q0EksheNffJB4iPqsAfiFpY0ARQY92K5r8P4+a78eu9reYrb2WxZb1qPJmvR7XZ6sN1oHD7dd/EyQoJmQsmOKdrqaLRbzR7tZrf52yvKkwNWXcIVhW8uxe7iUgxiojZpW9srKoK/qFRpaUZSKn7Z/zgtDH9FJkYbBsGPDMqp78Kzt+sJb+U2W+wCSSy34jIUxx6QRbzvn6uexc/emFw/1DU5y7zBudhgC7mVk8vX1gUNKyjZBzlOmRcretrANgffqs5fx/TMHN1xtkA/H1u1IKBfKoyk/xThMLAgMBAAECggEAECuG0GZA3HF8OaqFgMG+W+agOvH04h4Pqv4cHjYNxnxpFcNV9nEssTKWSOvCwYy7hrwZBGV3PQzbjFmmrxVFs20+8yCD7KbyKKQZPVC0zf84bj6NTNgvr6DpGtDxINxuGaMjCt7enqhoRyRRuZ0fj2gD3Wqae/Ds8cpDCefkyMg0TvauHSUj244vGq5nt93txUv1Sa+/8tWZ77Dm0s5a3wUYB2IeAMl5WrO2GMvgzwH+zT+4kvNWg5S0Ze4KE+dG3lSIYZjo99h14LcQS9eALC/VBcAJ6pRXaCTT/TULtcLNeOpoc9Fu25f0yTsDt6Ga5ApliYkb7rDhV+OFrw1sYQKBgQDCE9so+dPg7qbp0cV+lbb7rrV43m5s9Klq0riS7u8m71oTwhmvm6gSLfjzqb8GLrmflCK4lKPDSTdwyvd+2SSmOXySw94zr1Pvc7sHdmMRyA7mH3m+zSOOgyCTTKyhDRCNcRIkysoL+DecDhNo4Fumf71tsqDYogfxpAQhn0re8wKBgQDXhMmmT2oXiMnYHhi2k7CJe3HUqkZgmW4W44SWqKHp0V6sjcHm0N0RT5Hz1BFFUd5Y0ZB3JLcah19myD1kKYCj7xz6oVLb8O7LeAZNlb0FsrtD7NU+Hciywo8qESiA7UYDkU6+hsmxaI01DsttMIdG4lSBbEjA7t4IQC5lyr7xiQKBgQCN87YGJ40Y5ZXCSgOZDepz9hqX2KGOIfnUv2HvXsIfiUwqTXs6HbD18xg3KL4myIBOvywSM+4ABYp+foY+Cpcq2btLIeZhiWjsKIrw71+Q/vIe0YDb1PGf6DsoYhmWBpdHzR9HN+hGjvwlsYny2L9Qbfhgxxmsuf7zeFLpQLijjwKBgH7TD28k8IOk5VKec2CNjKd600OYaA3UfCpP/OhDl/RmVtYoHWDcrBrRvkvEEd2/DZ8qw165Zl7gJs3vK+FTYvYVcfIzGPWA1KU7nkntwewmf3i7V8lT8ZTwVRsmObWU60ySJ8qKuwoBQodki2VX12NpMN1wgWe3qUUlr6gLJU4xAoGAet6nD3QKwk6TTmcGVfSWOzvpaDEzGkXjCLaxLKh9GreM/OE+h5aN2gUoFeQapG5rUwI/7Qq0xiLbRXw+OmfAoV2XKv7iI8DjdIh0F06mlEAwQ/B0CpbqkuuxphIbchtdcz/5ra233r3BMNIqBl3VDDVoJlgHPg9msOTRy13lFqc="; /// let np_rdf = fs::read_to_string("./tests/resources/simple1-rsa.trig").unwrap(); /// let np = Nanopub::new( diff --git a/lib/tests/nanopub_test.rs b/lib/tests/nanopub_test.rs index a8c06ff..858a0ea 100644 --- a/lib/tests/nanopub_test.rs +++ b/lib/tests/nanopub_test.rs @@ -1,4 +1,4 @@ -use nanopub::nanopub::Nanopub; +use nanopub::Nanopub; use std::fs; pub const ORCID: &str = "http://orcid.org/0000-0002-1267-0234"; diff --git a/python/src/nanopub.rs b/python/src/nanopub.rs index 71cd9fb..8198341 100644 --- a/python/src/nanopub.rs +++ b/python/src/nanopub.rs @@ -1,4 +1,4 @@ -use nanopub::nanopub::Nanopub; +use nanopub::Nanopub; use pyo3::prelude::*; #[pyclass(name = "Nanopub", module = "nanopub_rs")] diff --git a/scripts/docs-serve.sh b/scripts/docs-serve.sh index 283a664..9250f35 100755 --- a/scripts/docs-serve.sh +++ b/scripts/docs-serve.sh @@ -4,12 +4,15 @@ set -e rm -rf target/doc -mdbook build --open +mdbook build -cargo doc --open --workspace --no-deps --exclude try-nanopub-rs --exclude nanopub-js --exclude nanopub_rs --target-dir target/doc +cargo doc --workspace --no-deps --exclude nanopub-js --exclude nanopub-py --target-dir target/doc echo "📖 Docs generated in the target/doc folder" +echo "MdBook at http://0.0.0.0:3000" +echo "Rust doc at http://0.0.0.0:3000/doc/nanopub" +python -m http.server 3000 --directory ./target/doc # mdbook serve --open @@ -17,6 +20,4 @@ echo "📖 Docs generated in the target/doc folder" # # rustdoc --crate-name nanopub_rs src/lib.rs -o docs/target/doc -L dependency=docs/target/debug/deps # # rustdoc --crate-name nanopub_rs src/lib.rs -o docs/target/doc -# python3 -m webbrowser ./docs/target/doc/nanopub_rs/index.html - -# file:///home/vemonet/develop/perso/nanopub-rs/lib/docs/target/doc/nanopub_rs/index.html +# python3 -m webbrowser ./target/doc/