Skip to content

Commit

Permalink
improve import scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Nov 14, 2023
1 parent a3b509b commit 0569d94
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 45 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Build
on:
workflow_dispatch:
push:
branches:
- main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy docs to GitHub Pages
name: Update docs

on:
workflow_dispatch:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

name: Lint and Test
name: Tests

on:
workflow_dispatch:
workflow_call:
push:
branches: [ main ]
pull_request:
Expand Down
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion js/src/nanopub.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use nanopub::nanopub::Nanopub;
use nanopub::Nanopub;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(js_name = Nanopub)]
Expand Down
2 changes: 1 addition & 1 deletion lib/docs/src/01_getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

```rust
use std::fs;
use nanopub::nanopub::Nanopub;
use nanopub::Nanopub;
let public_key = r#"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo2NYLBcZmpOkjgqLiT7hMxzRaK5KhYYHxxN2gCAMfmOaulAxAzPUNBJLIXjX3yQeIj6rAH4haWNAEUGPdiua/D+Pm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zqb8GLrmflCK4lKPDSTdwyvd+2SSmOXySw94zr1Pvc7sHdmMRyA7mH3m+zSOOgyCTTKyhDRCNcRIkysoL+DecDhNo4Fumf71tsqDYogfxpAQhn0re8wKBgQDXhMmmT2oXiMnYHhi2k7CJe3HUqkZgmW4W44SWqKHp0V6sjcHm0N0RT5Hz1BFFUd5Y0ZB3JLcah19myD1kKYCj7xz6oVLb8O7LeAZNlb0FsrtD7NU+Hciywo8qESiA7UYDkU6+hsmxaI01DsttMIdG4lSBbEjA7t4IQC5lyr7xiQKBgQCN87YGJ40Y5ZXCSgOZDepz9hqX2KGOIfnUv2HvXsIfiUwqTXs6HbD18xg3KL4myIBOvywSM+4ABYp+foY+Cpcq2btLIeZhiWjsKIrw71+Q/vIe0YDb1PGf6DsoYhmWBpdHzR9HN+hGjvwlsYny2L9Qbfhgxxmsuf7zeFLpQLijjwKBgH7TD28k8IOk5VKec2CNjKd600OYaA3UfCpP/OhDl/RmVtYoHWDcrBrRvkvEEd2/DZ8qw165Zl7gJs3vK+FTYvYVcfIzGPWA1KU7nkntwewmf3i7V8lT8ZTwVRsmObWU60ySJ8qKuwoBQodki2VX12NpMN1wgWe3qUUlr6gLJU4xAoGAet6nD3QKwk6TTmcGVfSWOzvpaDEzGkXjCLaxLKh9GreM/OE+h5aN2gUoFeQapG5rUwI/7Qq0xiLbRXw+OmfAoV2XKv7iI8DjdIh0F06mlEAwQ/B0CpbqkuuxphIbchtdcz/5ra233r3BMNIqBl3VDDVoJlgHPg9msOTRy13lFqc="#;

Expand Down
14 changes: 7 additions & 7 deletions lib/src/constants.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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#";
4 changes: 3 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/xThMLAgMBAAECggEAECuG0GZA3HF8OaqFgMG+W+agOvH04h4Pqv4cHjYNxnxpFcNV9nEssTKWSOvCwYy7hrwZBGV3PQz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iI8DjdIh0F06mlEAwQ/B0CpbqkuuxphIbchtdcz/5ra233r3BMNIqBl3VDDVoJlgHPg9msOTRy13lFqc=";
/// let np_rdf = fs::read_to_string("./tests/resources/simple1-rsa.trig").unwrap();
/// let np = Nanopub::new(
Expand All @@ -28,3 +28,5 @@ mod namespaces;
/// );
/// ```
pub mod nanopub;

pub use nanopub::Nanopub;
2 changes: 1 addition & 1 deletion lib/src/nanopub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/nanopub_test.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion python/src/nanopub.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use nanopub::nanopub::Nanopub;
use nanopub::Nanopub;
use pyo3::prelude::*;

#[pyclass(name = "Nanopub", module = "nanopub_rs")]
Expand Down
11 changes: 6 additions & 5 deletions scripts/docs-serve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ 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

# cargo doc --no-deps --open
# # 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/

0 comments on commit 0569d94

Please sign in to comment.