Clean up the project

This commit is contained in:
Hassan Abedi 2026-03-09 11:22:38 +01:00
parent 1355e40b50
commit a80e760b71
9 changed files with 41 additions and 69 deletions

View File

@ -1,12 +1,8 @@
# Variables # Variables
BINARY_NAME := "chase-cli" BINARY_NAME := chase-rs
BINARY := target/release/$(BINARY_NAME) BINARY := target/release/$(BINARY_NAME)
PATH := /snap/bin:$(PATH)
DEBUG_PROJ := 0 DEBUG_PROJ := 0
RUST_BACKTRACE := 1 RUST_BACKTRACE := 1
ASSET_DIR := assets
TEST_DATA_DIR := tests/testdata
SHELL := /bin/bash
# Default target # Default target
.DEFAULT_GOAL := help .DEFAULT_GOAL := help
@ -45,23 +41,13 @@ run: build ## Build and run the binary
clean: ## Remove generated and temporary files clean: ## Remove generated and temporary files
@echo "Cleaning up..." @echo "Cleaning up..."
@cargo clean @cargo clean
@rm -f $(ASSET_DIR)/*.svg && echo "Removed SVG files; might want to run 'make figs' to regenerate them."
.PHONY: install-snap
install-snap: ## Install a few dependencies using Snapcraft
@echo "Installing the snap package..."
@sudo apt-get update
@sudo apt-get install -y snapd graphviz wget
@sudo snap refresh
@sudo snap install rustup --classic
.PHONY: install-deps .PHONY: install-deps
install-deps: install-snap ## Install development dependencies install-deps: ## Install development dependencies
@echo "Installing dependencies..." @echo "Installing dependencies..."
@rustup component add rustfmt clippy @rustup component add rustfmt clippy
@cargo install cargo-tarpaulin @cargo install cargo-tarpaulin
@cargo install cargo-audit @cargo install cargo-audit
@cargo install cargo-careful
@cargo install cargo-nextest @cargo install cargo-nextest
.PHONY: lint .PHONY: lint
@ -69,26 +55,11 @@ lint: format ## Run the linters
@echo "Linting Rust files..." @echo "Linting Rust files..."
@DEBUG_PROJ=$(DEBUG_PROJ) cargo clippy -- -D warnings -D clippy::unwrap_used -D clippy::expect_used @DEBUG_PROJ=$(DEBUG_PROJ) cargo clippy -- -D warnings -D clippy::unwrap_used -D clippy::expect_used
.PHONY: publish
publish: ## Publish the package to crates.io (requires CARGO_REGISTRY_TOKEN to be set)
@echo "Publishing the package to Cargo registry..."
@cargo publish --token $(CARGO_REGISTRY_TOKEN)
.PHONY: bench
bench: ## Run the benchmarks
@echo "Running benchmarks..."
@DEBUG_PROJ=$(DEBUG_PROJ) cargo bench
.PHONY: audit .PHONY: audit
audit: ## Run security audit on Rust dependencies audit: ## Run security audit on Rust dependencies
@echo "Running security audit..." @echo "Running security audit..."
@cargo audit @cargo audit
.PHONY: rust-careful
careful: ## Run security checks on Rust code
@echo "Running security checks..."
@cargo careful
.PHONY: docs .PHONY: docs
docs: format ## Generate the documentation docs: format ## Generate the documentation
@echo "Generating documentation..." @echo "Generating documentation..."
@ -97,12 +68,7 @@ docs: format ## Generate the documentation
.PHONY: fix-lint .PHONY: fix-lint
fix-lint: ## Fix the linter warnings fix-lint: ## Fix the linter warnings
@echo "Fixing linter warnings..." @echo "Fixing linter warnings..."
@cargo clippy --fix --allow-dirty --allow-staged --all-targets --workspace --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used @cargo clippy --fix --allow-dirty --allow-staged --all-targets --workspace
.PHONY: testdata
testdata: ## Download the datasets used in tests
@echo "Downloading test data..."
@$(SHELL) $(TEST_DATA_DIR)/download_datasets.sh $(TEST_DATA_DIR)
.PHONY: nextest .PHONY: nextest
nextest: ## Run tests using nextest nextest: ## Run tests using nextest
@ -110,7 +76,7 @@ nextest: ## Run tests using nextest
@DEBUG_PROJ=$(DEBUG_PROJ) RUST_BACKTRACE=$(RUST_BACKTRACE) cargo nextest run @DEBUG_PROJ=$(DEBUG_PROJ) RUST_BACKTRACE=$(RUST_BACKTRACE) cargo nextest run
.PHONY: setup-hooks .PHONY: setup-hooks
setup-hooks: ## Install Git hooks (pre-commit and pre-push) setup-hooks: ## Install Git hooks (pre-commit)
@echo "Setting up Git hooks..." @echo "Setting up Git hooks..."
@if ! command -v pre-commit &> /dev/null; then \ @if ! command -v pre-commit &> /dev/null; then \
echo "pre-commit not found. Please install it using 'pip install pre-commit'"; \ echo "pre-commit not found. Please install it using 'pip install pre-commit'"; \
@ -124,3 +90,7 @@ setup-hooks: ## Install Git hooks (pre-commit and pre-push)
test-hooks: ## Test Git hooks on all files test-hooks: ## Test Git hooks on all files
@echo "Testing Git hooks..." @echo "Testing Git hooks..."
@pre-commit run --all-files --show-diff-on-failure @pre-commit run --all-files --show-diff-on-failure
.PHONY: check
check: format lint test ## Run format, lint, and test
@echo "All checks passed."

View File

@ -5,7 +5,7 @@ use std::collections::{HashMap, HashSet};
use super::atom::Atom; use super::atom::Atom;
use super::instance::Instance; use super::instance::Instance;
use super::rule::Rule; use super::rule::Rule;
use super::substitution::{unify_atom, Substitution}; use super::substitution::{Substitution, unify_atom};
use super::term::Term; use super::term::Term;
/// Result of running the chase algorithm. /// Result of running the chase algorithm.

View File

@ -41,7 +41,7 @@ impl Instance {
} }
/// Iterate over all facts. /// Iterate over all facts.
pub fn iter(&self) -> impl Iterator<Item=&Atom> { pub fn iter(&self) -> impl Iterator<Item = &Atom> {
self.facts.iter() self.facts.iter()
} }
@ -65,7 +65,7 @@ impl fmt::Display for Instance {
} }
impl FromIterator<Atom> for Instance { impl FromIterator<Atom> for Instance {
fn from_iter<T: IntoIterator<Item=Atom>>(iter: T) -> Self { fn from_iter<T: IntoIterator<Item = Atom>>(iter: T) -> Self {
let mut instance = Instance::new(); let mut instance = Instance::new();
for atom in iter { for atom in iter {
instance.add(atom); instance.add(atom);
@ -107,10 +107,7 @@ mod tests {
"Parent", "Parent",
vec![Term::constant("alice"), Term::constant("bob")], vec![Term::constant("alice"), Term::constant("bob")],
), ),
Atom::new( Atom::new("Person", vec![Term::constant("alice")]),
"Person",
vec![Term::constant("alice")],
),
] ]
.into_iter() .into_iter()
.collect(); .collect();

View File

@ -9,7 +9,7 @@ pub mod term;
mod engine; mod engine;
pub use atom::Atom; pub use atom::Atom;
pub use engine::{chase, ChaseResult}; pub use engine::{ChaseResult, chase};
pub use instance::Instance; pub use instance::Instance;
pub use rule::Rule; pub use rule::Rule;
pub use substitution::Substitution; pub use substitution::Substitution;

View File

@ -56,7 +56,7 @@ impl Substitution {
} }
/// Iterate over all bindings. /// Iterate over all bindings.
pub fn iter(&self) -> impl Iterator<Item=(&String, &Term)> { pub fn iter(&self) -> impl Iterator<Item = (&String, &Term)> {
self.mapping.iter() self.mapping.iter()
} }
} }

View File

@ -1,4 +1,4 @@
pub mod chase; pub mod chase;
// Re-export main types for convenience // Re-export main types for convenience
pub use chase::{chase, Atom, ChaseResult, Instance, Rule, Substitution, Term}; pub use chase::{Atom, ChaseResult, Instance, Rule, Substitution, Term, chase};

View File

@ -1,7 +1,7 @@
//! Integration tests for the chase algorithm. //! Integration tests for the chase algorithm.
use chase_rs::chase::rule::RuleBuilder; use chase_rs::chase::rule::RuleBuilder;
use chase_rs::{chase, Atom, Instance, Term}; use chase_rs::{Atom, Instance, Term, chase};
#[test] #[test]
fn test_transitive_closure() { fn test_transitive_closure() {
@ -100,18 +100,21 @@ fn test_multiple_head_atoms() {
#[test] #[test]
fn test_chase_with_constants_in_rules() { fn test_chase_with_constants_in_rules() {
let instance: Instance = vec![ let instance: Instance = vec![
Atom::new("Status", vec![Term::constant("alice"), Term::constant("active")]), Atom::new(
Atom::new("Status", vec![Term::constant("bob"), Term::constant("inactive")]), "Status",
vec![Term::constant("alice"), Term::constant("active")],
),
Atom::new(
"Status",
vec![Term::constant("bob"), Term::constant("inactive")],
),
] ]
.into_iter() .into_iter()
.collect(); .collect();
// Only active users get access: Status(X, "active") -> HasAccess(X) // Only active users get access: Status(X, "active") -> HasAccess(X)
let rule = RuleBuilder::new() let rule = RuleBuilder::new()
.when( .when("Status", vec![Term::var("X"), Term::constant("active")])
"Status",
vec![Term::var("X"), Term::constant("active")],
)
.then("HasAccess", vec![Term::var("X")]) .then("HasAccess", vec![Term::var("X")])
.build(); .build();

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@