Git Product home page Git Product logo

osh-dir-std-rs's Introduction

OSH directory standard - Rust library

License: AGPL-3.0-or-later REUSE status Repo Package Releases Documentation Releases Dependency Status Build Status

In cooperation with FabCity Hamburg In cooperation with Open Source Ecology Germany

  • OSH: Open Source Hardware

Code that helps humans and machines deal with the OSH directory standard.

This consists of two parts:

  1. osh_dir_std - a (Rust) library to parse the specification(s) into easily usable structures & accompanying utilities
  2. osh-dir-std - a CLI tool that helps checking a given projects file listing against one or multiple specifications.

NOTE
This only checks the paths of files and directories against a set of presets (aka "standards"). It does not check the content of any files in any way.

Example Usage

CLI

Installation

From Source
Fetch & Compile
cargo install osh-dir-std
Local Sources
cargo install --path bin

Usage

The tool expects a new-line separated listing of files (and optionally directories) of the project, either on stdin, or in a file given as the first argument. This list might come from git (or any other version control system (VCS) used), the file-system directly, a ZIP file or even a web-site that lists the files.

A few examples of how to list files in different scenarios, to rate the project against the known directory standards:

git:

git ls-files --recurse-submodules | sed -e 's/^"\(.*\)"$/\1/' | osh-dir-std rate

SVN:

svn ls | osh-dir-std rate

Mercurial (hg):

hg status --all | osh-dir-std rate

pijul:

pijul list | osh-dir-std rate

file-system:

ls -r1 | osh-dir-std rate

sample output:

[
  {
    "name": "unixish",
    "factor": 0.62724684
  },
]

A factor of 1.0 would mean that the projects file- and directory structure adheres 100% to the respective standard. unixish is the name of the default directory standard.

Library

Setup

Cargo.toml:

[dependencies]
osh_dir_std = "0.7.2"

Code

use osh_dir_std::{self, format::Rec};

fn find_rec(std: &str, record_path: &str) -> Result<&'static Rec<'static>, String> {
    for rec in &osh_dir_std::data::STDS.get(std).unwrap().records {
        if rec.path == record_path {
            return Ok(rec);
        }
    }
    Err(format!(
        "Failed to find record with path '{record_path}' in the '{std}' dir standard"
    ))
}

/// Checks whether the dir std "unixish" contains the record "res/",
/// and whether that record is a _fixed_ one. See [the definition](
/// https://github.com/hoijui/osh-dir-std/blob/main/definition_format.csv)
/// for an explanation of what _fixed_ means.
#[test]
fn unixish_res_fixed() -> Result<(), Error> {
    let rec = find_rec("unixish", "res/")?;
    assert!(rec.fixed);
    Ok(())
}

Related Projects

  • osh-tool - Checks an OSH project against a set of predefined checks, to try to assess its overall machine-readability and openness.
    (also uses this tool internally)

Funding

This project was funded by the European Regional Development Fund (ERDF) in the context of the INTERFACER Project, from November 2022 (project start) until March 2023.

Logo of the EU ERDF program

osh-dir-std-rs's People

Contributors

hoijui avatar

Stargazers

 avatar

Watchers

 avatar  avatar

osh-dir-std-rs's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.