From 0cf900fdadda4bb146e76596abc9751d1d0dbef6 Mon Sep 17 00:00:00 2001 From: Hassan Abedi Date: Fri, 6 Mar 2026 10:52:32 +0000 Subject: [PATCH] The base commit --- .editorconfig | 22 ++++ .gitattributes | 38 ++++++ .gitignore | 82 +++++++++++++ .pre-commit-config.yaml | 43 +++++++ Cargo.toml | 73 ++++++++++++ LICENSE | 11 ++ Makefile | 140 +++++++++++++++++++++++ README.md | 50 ++++++++ assets/logos/README.md | 3 + assets/logos/corro.svg | 113 ++++++++++++++++++ assets/logos/cuddlyferris.svg | 52 +++++++++ assets/logos/rustacean-flat-gesture.svg | 58 ++++++++++ assets/logos/rustacean-flat-happy.svg | 53 +++++++++ assets/logos/rustacean-flat-noshadow.svg | 68 +++++++++++ assets/logos/rustacean-orig-noshadow.svg | 84 ++++++++++++++ assets/make_figures.sh | 12 ++ benches/project_benchmarks.rs | 8 ++ docs/README.md | 5 + examples/basic_usage.rs | 5 + pyproject.toml | 10 ++ python/.gitkeep | 0 rust-toolchain.toml | 3 + src/cli.rs | 34 ++++++ src/lib.rs | 2 + src/logging.rs | 17 +++ src/main.rs | 7 ++ tests/integration_tests.rs | 1 + tests/testdata/README.md | 22 ++++ tests/testdata/check_datasets.sql | 11 ++ tests/testdata/download_datasets.sh | 20 ++++ 30 files changed, 1047 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 assets/logos/README.md create mode 100644 assets/logos/corro.svg create mode 100644 assets/logos/cuddlyferris.svg create mode 100644 assets/logos/rustacean-flat-gesture.svg create mode 100644 assets/logos/rustacean-flat-happy.svg create mode 100644 assets/logos/rustacean-flat-noshadow.svg create mode 100644 assets/logos/rustacean-orig-noshadow.svg create mode 100644 assets/make_figures.sh create mode 100644 benches/project_benchmarks.rs create mode 100644 docs/README.md create mode 100644 examples/basic_usage.rs create mode 100644 pyproject.toml create mode 100644 python/.gitkeep create mode 100644 rust-toolchain.toml create mode 100644 src/cli.rs create mode 100644 src/lib.rs create mode 100644 src/logging.rs create mode 100644 src/main.rs create mode 100644 tests/integration_tests.rs create mode 100644 tests/testdata/README.md create mode 100644 tests/testdata/check_datasets.sql create mode 100644 tests/testdata/download_datasets.sh diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f9a21c6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.rs] +max_line_length = 100 + +[*.md] +max_line_length = 150 +trim_trailing_whitespace = false + +[*.sh] +indent_size = 2 + +[*.{yaml,yml}] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..afc5177 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,38 @@ +* text=auto eol=lf + +*.go text +*.mod text +*.sum text +*.md text +*.rst text +*.json text +*.yaml text +*.yml text +*.toml text +*.sh text eol=lf +*.html text +*.css text +*.js text +*.svg text +*.xml text + +*.png filter=lfs diff=lfs merge=lfs -text +*.jpg filter=lfs diff=lfs merge=lfs -text +*.jpeg filter=lfs diff=lfs merge=lfs -text +*.gif filter=lfs diff=lfs merge=lfs -text +*.ico filter=lfs diff=lfs merge=lfs -text +*.mp4 filter=lfs diff=lfs merge=lfs -text +*.mov filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.woff filter=lfs diff=lfs merge=lfs -text +*.woff2 filter=lfs diff=lfs merge=lfs -text +*.exe filter=lfs diff=lfs merge=lfs -text +*.dll filter=lfs diff=lfs merge=lfs -text +*.so filter=lfs diff=lfs merge=lfs -text +*.out filter=lfs diff=lfs merge=lfs -text +*.a filter=lfs diff=lfs merge=lfs -text +*.o filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6095f34 --- /dev/null +++ b/.gitignore @@ -0,0 +1,82 @@ +# Python specific +__pycache__/ +*.py[cod] +*$py.class + +# Virtual environments +.env/ +env/ +.venv/ +venv/ + +# Packaging and distribution files +.Python +build/ +dist/ +*.egg-info/ +*.egg +MANIFEST + +# Dependency directories +develop-eggs/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +.installed.cfg + +# Test and coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# IDE specific files and directories +.idea/ +*.iml +.vscode/ + +# Jupyter Notebook files +.ipynb_checkpoints + +# Temporary files created by editors and the system and folders to ignore +*.swp +*~ +*.bak +*.tmp +temp/ +tmp/ + +# Database files (SQLite, DuckDB, etc.) +*.duckdb +*.db +*.wal +*.sqlite + +# Dependency lock files (uncomment to ignore) +poetry.lock + +# Rust specific +/target/ +.cargo-ok +cobertura.xml +tarpaulin-report.html + +# Comment out the next line if you want to checkin your lock file for Cargo +Cargo.lock + +# Misc +.DS_Store +.benchmarks +.env diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..fc020bc --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,43 @@ +default_stages: [ pre-push ] +fail_fast: false +exclude: '^(benches/|tests/)' + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + args: [ --markdown-linebreak-ext=md ] + - id: end-of-file-fixer + - id: mixed-line-ending + - id: check-merge-conflict + - id: check-added-large-files + - id: detect-private-key + - id: check-yaml + - id: check-toml + - id: check-json + - id: check-docstring-first + - id: pretty-format-json + args: [ --autofix, --no-sort-keys ] + + - repo: local + hooks: + - id: format + name: Format Code + entry: make format + language: system + pass_filenames: false + stages: [ pre-commit ] + + - id: lint + name: Check Code Style + entry: make lint + language: system + pass_filenames: false + stages: [ pre-commit ] + + - id: test + name: Run Tests + entry: make nexttest + language: system + pass_filenames: false diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e9f5af3 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,73 @@ +[package] +name = "chase-rs" +version = "0.1.0-alpha.1" +description = "Implementation of chase algorithm in Rust" +repository = "https://github.com/habedi/template-rust-project" +license = "MIT OR Apache-2.0" +readme = "README.md" +keywords = ["project-template", "rust", "library", "application"] +authors = ["Hassan Abedi "] +homepage = "https://github.com/habedi/template-rust-project" +documentation = "https://docs.rs/template-rust-project" +categories = ["development-tools"] +edition = "2021" +rust-version = "1.83" + +resolver = "2" + +include = [ + "assets/**/*", + "docs/**/*", + "src/**/*", + "Cargo.toml", + "README.md", + "LICENSE-MIT", + "LICENSE-APACHE" +] + +[lib] +name = "template_rust_project" +path = "src/lib.rs" + +[[bin]] +name = "template-rust-project" +path = "src/main.rs" + +[features] +default = [] # No features enabled by default +binaries = [] + +[dependencies] +ctor = "0.6.0" +tracing = "0.1.41" +tracing-subscriber = "0.3.19" + +[dev-dependencies] +criterion = { version = "0.7.0", features = ["html_reports"] } + +[[bench]] +name = "project_benchmarks" +harness = false + +[profile.release] +strip = "debuginfo" +panic = "unwind" +codegen-units = 1 +lto = true + +[profile.bench] +debug = true + +[profile.test] +debug = true + +[profile.example] +inherits = "release" + +[package.metadata.rustfmt] +max_width = 100 +hard_tabs = false +tab_spaces = 4 + +[workspace] +members = [] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f18137a --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +Copyright (c) 2026 Obsidian Systems LLC + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a0ec859 --- /dev/null +++ b/Makefile @@ -0,0 +1,140 @@ +# Load environment variables from .env file +ifneq (,$(wildcard ./.env)) + include .env + export $(shell sed 's/=.*//' .env) +else + $(warning .env file not found. Environment variables not loaded.) +endif + +# Variables +PROJ_REPO = github.com/habedi/template-rust-project +BINARY_NAME := $(or $(PROJ_BINARY), $(notdir $(PROJ_REPO))) +BINARY := target/release/$(BINARY_NAME) +PATH := /snap/bin:$(PATH) +DEBUG_PROJ := 0 +RUST_BACKTRACE := 1 +ASSET_DIR := assets +TEST_DATA_DIR := tests/testdata +SHELL := /bin/bash + +# Default target +.DEFAULT_GOAL := help + +.PHONY: help +help: ## Show help messages for all available targets + @grep -E '^[a-zA-Z_-]+:.*## .*$$' Makefile | \ + awk 'BEGIN {FS = ":.*## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: format +format: ## Format Rust files + @echo "Formatting Rust files..." + @cargo fmt + +.PHONY: test +test: format ## Run the tests + @echo "Running tests..." + @DEBUG_PROJ=$(DEBUG_PROJ) RUST_BACKTRACE=$(RUST_BACKTRACE) cargo test --all-targets --workspace -- --nocapture + +.PHONY: coverage +coverage: format ## Generate test coverage report + @echo "Generating test coverage report..." + @DEBUG_PROJ=$(DEBUG_PROJ) cargo tarpaulin --out Xml --out Html + +.PHONY: build +build: format ## Build the binary for the current platform + @echo "Building the project..." + @DEBUG_PROJ=$(DEBUG_PROJ) cargo build --release + +.PHONY: run +run: build ## Build and run the binary + @echo "Running the $(BINARY) binary..." + @DEBUG_PROJ=$(DEBUG_PROJ) ./$(BINARY) + +.PHONY: clean +clean: ## Remove generated and temporary files + @echo "Cleaning up..." + @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 +install-deps: install-snap ## Install development dependencies + @echo "Installing dependencies..." + @rustup component add rustfmt clippy + @cargo install cargo-tarpaulin + @cargo install cargo-audit + @cargo install cargo-careful + @cargo install cargo-nextest + +.PHONY: lint +lint: format ## Run the linters + @echo "Linting Rust files..." + @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 +audit: ## Run security audit on Rust dependencies + @echo "Running security audit..." + @cargo audit + +.PHONY: rust-careful +careful: ## Run security checks on Rust code + @echo "Running security checks..." + @cargo careful + +.PHONY: docs +docs: format ## Generate the documentation + @echo "Generating documentation..." + @cargo doc --no-deps --document-private-items + +.PHONE: figs +figs: ## Generate the figures in the assets directory + @echo "Generating figures..." + @$(SHELL) $(ASSET_DIR)/make_figures.sh $(ASSET_DIR) + +.PHONY: fix-lint +fix-lint: ## Fix the 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 + +.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 +nextest: ## Run tests using nextest + @echo "Running tests using nextest..." + @DEBUG_PROJ=$(DEBUG_PROJ) RUST_BACKTRACE=$(RUST_BACKTRACE) cargo nextest run + +.PHONY: setup-hooks +setup-hooks: ## Install Git hooks (pre-commit and pre-push) + @echo "Setting up Git hooks..." + @if ! command -v pre-commit &> /dev/null; then \ + echo "pre-commit not found. Please install it using 'pip install pre-commit'"; \ + exit 1; \ + fi + @pre-commit install --hook-type pre-commit + @pre-commit install --hook-type pre-push + @pre-commit install-hooks + +.PHONY: test-hooks +test-hooks: ## Test Git hooks on all files + @echo "Testing Git hooks..." + @pre-commit run --all-files --show-diff-on-failure diff --git a/README.md b/README.md new file mode 100644 index 0000000..7605789 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +## A Template for Rust Projects + +
+ + template-rust-project logo + +
+
+ +[![Tests](https://img.shields.io/github/actions/workflow/status/habedi/template-rust-project/tests.yml?label=tests&style=flat&labelColor=282c34&color=4caf50&logo=github)](https://github.com/habedi/template-rust-project/actions/workflows/tests.yml) +[![Lints](https://img.shields.io/github/actions/workflow/status/habedi/template-rust-project/lints.yml?label=lints&style=flat&labelColor=282c34&color=4caf50&logo=github)](https://github.com/habedi/template-rust-project/actions/workflows/lints.yml) +[![Linux Build](https://img.shields.io/github/actions/workflow/status/habedi/template-rust-project/build_linux.yml?label=linux%20build&style=flat&labelColor=282c34&color=4caf50&logo=linux)](https://github.com/habedi/template-rust-project/actions/workflows/build_linux.yml) +[![Windows Build](https://img.shields.io/github/actions/workflow/status/habedi/template-rust-project/build_windows.yml?label=windows%20build&style=flat&labelColor=282c34&color=4caf50&logo=github)](https://github.com/habedi/template-rust-project/actions/workflows/build_windows.yml) +[![MacOS Build](https://img.shields.io/github/actions/workflow/status/habedi/template-rust-project/build_macos.yml?label=macos%20build&style=flat&labelColor=282c34&color=4caf50&logo=apple)](https://github.com/habedi/template-rust-project/actions/workflows/build_macos.yml) +
+[![Code Coverage](https://img.shields.io/codecov/c/github/habedi/template-rust-project?style=flat&labelColor=282c34&color=ffca28&logo=codecov)](https://codecov.io/gh/habedi/template-rust-project) +[![Code Quality](https://img.shields.io/codefactor/grade/github/habedi/template-rust-project?style=flat&labelColor=282c34&color=4caf50&logo=codefactor)](https://www.codefactor.io/repository/github/habedi/template-rust-project) +[![Crates.io](https://img.shields.io/crates/v/template-rust-project.svg?style=flat&labelColor=282c34&color=f46623&logo=rust)](https://crates.io/crates/template-rust-project) +[![Downloads](https://img.shields.io/crates/d/template-rust-project?style=flat&labelColor=282c34&color=4caf50&logo=rust)](https://crates.io/crates/template-rust-project) +[![Docs.rs](https://img.shields.io/badge/docs.rs-template--rust--project-66c2a5?style=flat&labelColor=282c34&logo=docs.rs)](https://docs.rs/template-rust-project) +
+[![Release](https://img.shields.io/github/release/habedi/template-rust-project.svg?style=flat&labelColor=282c34&color=f46623&logo=github)](https://github.com/habedi/template-rust-project/releases/latest) +[![Total Downloads](https://img.shields.io/github/downloads/habedi/template-rust-project/total.svg?style=flat&labelColor=282c34&color=8caf50&logo=github)](https://github.com/habedi/template-rust-project/releases) +[![Docs](https://img.shields.io/badge/docs-latest-007ec6?style=flat&labelColor=282c34&logo=readthedocs)](docs) +[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-007ec6?style=flat&labelColor=282c34&logo=open-source-initiative)](https://github.com/habedi/template-rust-project) +[![Status: Stable](https://img.shields.io/badge/status-stable-green.svg?style=flat&labelColor=282c34)](https://github.com/habedi/template-rust-project) + +--- + +This is a template repository with a minimalistic structure to make it easier to start a new Rust project. +I share it here in case it might be useful to others. + +### Features + +- Minimalistic project structure +- Pre-configured GitHub Actions for running tests and making releases for different platforms +- Makefile for managing common tasks such as formatting, testing, linting, and building +- Example configuration files for common tools like `rustfmt`, `clippy`, and `editorconfig` +- GitHub badges for tests, builds, code quality and coverage, documentation, etc. + +### Contributing + +See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to make a contribution. + +### License + +This project is licensed under either of these: + +* MIT License ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT) +* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0) diff --git a/assets/logos/README.md b/assets/logos/README.md new file mode 100644 index 0000000..a22f2d9 --- /dev/null +++ b/assets/logos/README.md @@ -0,0 +1,3 @@ +## Sources + +- [rustacean.net](https://rustacean.net/) diff --git a/assets/logos/corro.svg b/assets/logos/corro.svg new file mode 100644 index 0000000..c3dc6fa --- /dev/null +++ b/assets/logos/corro.svg @@ -0,0 +1,113 @@ + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/logos/cuddlyferris.svg b/assets/logos/cuddlyferris.svg new file mode 100644 index 0000000..a82119e --- /dev/null +++ b/assets/logos/cuddlyferris.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/logos/rustacean-flat-gesture.svg b/assets/logos/rustacean-flat-gesture.svg new file mode 100644 index 0000000..aa5089b --- /dev/null +++ b/assets/logos/rustacean-flat-gesture.svg @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/logos/rustacean-flat-happy.svg b/assets/logos/rustacean-flat-happy.svg new file mode 100644 index 0000000..05b07fb --- /dev/null +++ b/assets/logos/rustacean-flat-happy.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/logos/rustacean-flat-noshadow.svg b/assets/logos/rustacean-flat-noshadow.svg new file mode 100644 index 0000000..debd916 --- /dev/null +++ b/assets/logos/rustacean-flat-noshadow.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/logos/rustacean-orig-noshadow.svg b/assets/logos/rustacean-orig-noshadow.svg new file mode 100644 index 0000000..733a5ba --- /dev/null +++ b/assets/logos/rustacean-orig-noshadow.svg @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/make_figures.sh b/assets/make_figures.sh new file mode 100644 index 0000000..b6f8541 --- /dev/null +++ b/assets/make_figures.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# You need to have Graphviz installed to run this script +# On Debian-based OSes, you can install it using: sudo apt-get install graphviz + +# Directory containing .dot files (with default value) +ASSET_DIR=${1:-"."} + +# Make figures from .dot files +for f in ${ASSET_DIR}/*.dot; do + dot -Tsvg "$f" -o "${f%.dot}.svg" +done diff --git a/benches/project_benchmarks.rs b/benches/project_benchmarks.rs new file mode 100644 index 0000000..fa87d01 --- /dev/null +++ b/benches/project_benchmarks.rs @@ -0,0 +1,8 @@ +use criterion::{criterion_group, criterion_main, Criterion}; + +fn benchmark_fun(_c: &mut Criterion) { + // Your benchmarking code here +} + +criterion_group!(benches, benchmark_fun,); +criterion_main!(benches); diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..1eb76f9 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,5 @@ +# Project Documentation + +Put your project documentation here. + + diff --git a/examples/basic_usage.rs b/examples/basic_usage.rs new file mode 100644 index 0000000..7c55598 --- /dev/null +++ b/examples/basic_usage.rs @@ -0,0 +1,5 @@ +fn main() { + println!("This is a basic usage example"); +} + +// Run this example with `cargo run --example basic_usage` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d07f56d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "chase-rs" +version = "0.1.0" +description = "Python environment for the `chase-rs` project" + +requires-python = ">=3.10,<4.0" +dependencies = [ + "maturin[zig] (>=1.8.3,<2.0.0)", + "numpy (>=2.2.6,<3.0.0)", +] diff --git a/python/.gitkeep b/python/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..db8c8a6 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.92.0" +components = ["rustfmt", "clippy", "rust-analyzer"] diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..8677f5f --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,34 @@ +use std::ffi::OsString; +use tracing::error; + +pub fn run(args: impl IntoIterator) -> Result<(), i32> { + let _args: Vec = args.into_iter().collect(); + // Your implementation here + // Expecting at least 2 arguments + if _args.len() < 2 { + error!("Expecting at least 2 arguments"); + return Err(1); + } + Ok(()) +} + +// Unit tests +#[cfg(test)] +mod tests { + use super::*; + use std::ffi::OsString; + + #[test] + fn test_run_with_valid_args() { + let args = vec![OsString::from("arg1"), OsString::from("arg2")]; + let result = run(args); + assert!(result.is_ok()); + } + + #[test] + fn test_run_with_invalid_args() { + let args = vec![OsString::from("invalid_arg")]; + let result = run(args); + assert!(result.is_err()); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..2b8e049 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,2 @@ +pub mod cli; +pub mod logging; diff --git a/src/logging.rs b/src/logging.rs new file mode 100644 index 0000000..d1cfa71 --- /dev/null +++ b/src/logging.rs @@ -0,0 +1,17 @@ +use ctor::ctor; +use tracing::Level; +use tracing_subscriber; + +#[ctor] +fn set_debug_level() { + // If DEBUG_PROJ is not set or set to false, disable logging. Otherwise, enable logging + if std::env::var("DEBUG_PROJ").map_or(true, |v| v == "0" || v == "false" || v.is_empty()) { + // Disable logging + } else { + tracing_subscriber::fmt() + .with_max_level(Level::DEBUG) + .init(); + } + + //println!("DEBUG_PROJ: {:?}", std::env::var("DEBUG_PROJ")); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..50093e7 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,7 @@ +use template_rust_project::cli::run; + +fn main() { + if let Err(code) = run(std::env::args_os()) { + std::process::exit(code); + } +} diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/integration_tests.rs @@ -0,0 +1 @@ + diff --git a/tests/testdata/README.md b/tests/testdata/README.md new file mode 100644 index 0000000..8edc998 --- /dev/null +++ b/tests/testdata/README.md @@ -0,0 +1,22 @@ +## Datasets for Testing + +This directory contains the datasets used for the tests in the [`tests`](../) directory. + +### Downloading the Datasets + +Run the following command to download the datasets used for testing: + +```shell +bash download_datasets.sh +``` + +### Checking the Datasets + +To check the datasets after downloading, run the following command: + +```shell +duckdb -init check_datasets.sql -no-stdin +``` + +You need to have the `duckdb` binary installed on your system to run the above command. +Check the [DuckDB installation guide](https://duckdb.org/docs/installation) for more information. diff --git a/tests/testdata/check_datasets.sql b/tests/testdata/check_datasets.sql new file mode 100644 index 0000000..faa332f --- /dev/null +++ b/tests/testdata/check_datasets.sql @@ -0,0 +1,11 @@ +-- Description: This script is used to check the datasets that are available in the testdata directory. +-- Run using DuckDB CLI (in current directory): duckdb -init check_datasets.sql -no-stdin + +-- Query the Wine Quality CSV file using csv_scan: +SELECT * FROM read_csv('winequality-red.csv') LIMIT 5; + +-- Query the NYC Yellow Taxi Parquet file using parquet_scan: +SELECT * FROM read_parquet('yellow_tripdata_2019-01.parquet') LIMIT 5; + +-- Query the NYC Green Taxi Parquet file using parquet_scan: +SELECT * FROM read_parquet('green_tripdata_2019-01.parquet') LIMIT 5; diff --git a/tests/testdata/download_datasets.sh b/tests/testdata/download_datasets.sh new file mode 100644 index 0000000..83403a5 --- /dev/null +++ b/tests/testdata/download_datasets.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -euo pipefail + +# Directory for test data (relative to this script) +TESTDATA_DIR="$(dirname "$0")" +echo "Using test data directory: $TESTDATA_DIR" + +# Create the directory if it doesn't exist +mkdir -p "$TESTDATA_DIR" + +echo "Downloading Wine Quality Dataset (red wine)..." +wget -c -O "$TESTDATA_DIR/winequality-red.csv" "https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv" + +echo "Downloading NYC Yellow Taxi Trip Data (January 2019, Parquet)..." +wget -c -O "$TESTDATA_DIR/yellow_tripdata_2019-01.parquet" "https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2019-01.parquet" + +echo "Downloading NYC Green Taxi Trip Data (January 2019, Parquet)..." +wget -c -O "$TESTDATA_DIR/green_tripdata_2019-01.parquet" "https://d37ci6vzurychx.cloudfront.net/trip-data/green_tripdata_2019-01.parquet" + +echo "Download complete. Test data saved to $TESTDATA_DIR"