Skip to content

Commit

Permalink
Add from_extended_prefix_map and get_bioregistry_converter from JSON …
Browse files Browse the repository at this point in the history
…file. Add support for optional pattern on Record. Add support for delimiter on Converter

Fix linux wheel workflows (add openssl-dev dependency for linux wheel builds)
Move converter and record out of lib.rs, in a new api.rs file
Create fetch.rs file for PrefixMapSources traits and functions to fetch data (from URL, file)
Improved tests
  • Loading branch information
vemonet committed Dec 17, 2023
1 parent 7b06126 commit 5b2ea76
Show file tree
Hide file tree
Showing 26 changed files with 764 additions and 420 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/manylinux_build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cd /workdir
yum -y install centos-release-scl-rh
yum -y install centos-release-scl-rh openssl-devel
yum -y install llvm-toolset-7.0
source scl_source enable llvm-toolset-7.0
curl https://static.rust-lang.org/rustup/dist/%arch%-unknown-linux-gnu/rustup-init --output rustup-init
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/musllinux_build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cd /workdir
apk add clang-dev
apk add clang-dev openssl-dev
curl https://static.rust-lang.org/rustup/dist/%arch%-unknown-linux-musl/rustup-init --output rustup-init
chmod +x rustup-init
./rustup-init -y --profile minimal
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Generate code coverage
run: |
cargo tarpaulin -p curies --out xml --verbose --timeout 120
run: bash ./scripts/cov.sh

- name: Upload to codecov.io
uses: codecov/codecov-action@v2
Expand Down
13 changes: 10 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Rust
/target/
Cargo.lock

# Tests
tarpaulin-report.html
cobertura.xml
benchmark.md
hyperfine_*.deb

# Python
.venv

# JS
Expand All @@ -10,11 +18,10 @@ package-lock.json
*.lock
js/LICENSE

# HTML docs generated by mdbook
lib/docs/docs
# Docs
/theme/
mdbook-admonish.css

# Build scripts
# Build process
.github/workflows/manylinux_build_script.sh
.github/workflows/musllinux_build_script.sh
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@
<img src="https://codecov.io/gh/biopragmatics/curies.rs/branch/main/graph/badge.svg" alt="Codecov status" />
</a>
</p>

Idiomatic conversion between URIs and compact URIs (CURIEs) in Rust.

## 📥 Install dependencies
## 📖 Documentation

Checkout the **[biopragmatics.github.io/curies.rs](https://biopragmatics.github.io/curies.rs)** for more details on how to install and use it.


## 🧑‍💻 Development

### 📥 Install dependencies

[Rust](https://www.rust-lang.org/tools/install), python 3.8+ and npm are required for development.

Expand All @@ -35,8 +41,6 @@ cargo install wasm-pack cargo-tarpaulin mdbook mdbook-admonish
> If you are using VSCode we strongly recommend to install the `rust-lang.rust-analyzer` extension.

## Development

### 🧪 Run tests

Run tests and display prints:
Expand All @@ -56,3 +60,4 @@ cargo fmt
```shell
cargo doc --open
```

5 changes: 3 additions & 2 deletions js/src/curies.rs → js/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl RecordJs {
uri_prefix,
prefix_synonyms: prefix_synonyms_set,
uri_prefix_synonyms: uri_prefix_synonyms_set,
pattern: None,
},
})
}
Expand Down Expand Up @@ -59,15 +60,15 @@ impl ConverterJs {
#[wasm_bindgen(constructor)]
pub fn new() -> Result<ConverterJs, JsValue> {
Ok(Self {
converter: Converter::new(),
converter: Converter::default(),
})
}

#[wasm_bindgen(js_name = addRecord)]
pub fn add_record(&mut self, record: RecordJs) -> Result<(), JsValue> {
self.converter
.add_record(record.record)
.map(|_| ())
.map(|_| self.converter.build())
.map_err(|e| JsValue::from_str(&e.to_string()))
}

Expand Down
2 changes: 1 addition & 1 deletion js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use js_sys::Error;
// #![allow(clippy::unused_unit)]
use wasm_bindgen::prelude::*;

mod curies;
mod api;

#[wasm_bindgen(start)]
pub fn startup() {
Expand Down
1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", features = ["blocking", "json"] }
async-trait = "0.1"
regex = "1.10"

[dev-dependencies]
tokio = { version = "1.34", features = ["rt-multi-thread", "macros"] }
Expand Down
6 changes: 3 additions & 3 deletions lib/docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ cargo install cargo-outdated
cargo outdated
```

2. Bump the version in the `Cargo.toml` file in folders `lib/`, `python`, `js`
2. Bump the version in the `Cargo.toml` file in folders `lib`, `python`, and `js`:

```bash
./scripts/bump.sh 0.0.2
```

3. Commit, push, and create a new release on GitHub
3. Commit, push, and **create a new release on GitHub**.

4. The `build.yml` workflow will automatically build artifacts (binary, pip wheel, npm package), and add them to the new release.
4. The `build.yml` workflow will automatically build artifacts (pip wheel, npm package), add them to the new release, and publish to public registries (crates.io, PyPI, NPM).
6 changes: 3 additions & 3 deletions lib/docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Whether you're a developer looking to work with CURIEs (e.g. expand or compress)
### ✨ CURIEs management

- 🛠️ **Create** your custom converter
- 📥 **Import** converters from JSON or JSON-LD context, with helper functions for popular converters, such as `get_obo_converter()`.
- 🔗 **Expand** CURIEs from their compressed form to URIs.
- 🗜️ **Compress** URIs to CURIEs.
- 📥 **Import converters** from JSON or JSON-LD context, with helper functions for popular converters, such as `get_obo_converter()`.
- 🔗 **Expand CURIEs** from their compressed form to URIs.
- 🗜️ **Compress URIs** to CURIEs.

### 📦️ Packaged for multiple interfaces

Expand Down
15 changes: 7 additions & 8 deletions lib/docs/use_javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

You can easily work with CURIEs from JavaScript, or TypeScript with the [`@biopragmatics/curies`](https://www.npmjs.com/package/@biopragmatics/curies) NPM package.

## 📥️ Install

Install the `npm` package (use `yarn` or `pnpm` if you prefer) to use it from your favorite framework:

```bash
npm install @biopragmatics/curies
```

## 🚀 Use it in bare HTML files

Expand Down Expand Up @@ -56,14 +63,6 @@ npx http-server
python -m http.server
```

## 📥️ Install

Install the `npm` package (use `yarn` or `pnpm` if you prefer) to use it from your favorite framework:

```bash
npm install @biopragmatics/curies
```

## ⚛️ Use from any JavaScript framework

It can be used from any JavaScript framework, or NodeJS.
Expand Down
4 changes: 3 additions & 1 deletion lib/docs/use_rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ use curies::{Converter, Record};
use std::collections::HashSet;

fn example() -> Result<(), Box<dyn std::error::Error>> {
let mut converter = Converter::new();
let mut converter = Converter::default();

let record1 = Record {
prefix: "doid".to_string(),
uri_prefix: "http://purl.obolibrary.org/obo/DOID_".to_string(),
prefix_synonyms: HashSet::from(["DOID".to_string()]),
uri_prefix_synonyms: HashSet::from(["https://identifiers.org/DOID/"].map(String::from)),
pattern: None,
};
let record2 = Record::new("obo", "http://purl.obolibrary.org/obo/");
converter.add_record(record1)?;
converter.add_record(record2)?;
converter.build();

let uri = converter.expand("doid:1234")?;
println!("Expanded CURIE: {}", uri);
Expand Down
Loading

0 comments on commit 5b2ea76

Please sign in to comment.