diff --git a/README.md b/README.md index a38eca6..aeb9427 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,11 @@ -# cpast - Code Testing and Analysis Tool +# cpast_mono - Code Testing and Analysis Tool ![Crates.io](https://img.shields.io/crates/d/cpast) -![Crates.io](https://img.shields.io/crates/v/cpast) ![GitHub repo size](https://img.shields.io/github/repo-size/rootCircle/cpast) -![Crates.io](https://img.shields.io/crates/l/cpast) -![docs.rs](https://img.shields.io/docsrs/cpast) ![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/rootCircle/cpast/general.yml) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/rootCircle/cpast/audit.yml?label=audit) [![codecov](https://codecov.io/github/rootCircle/cpast/graph/badge.svg?token=O9UJP30T89)](https://codecov.io/github/rootCircle/cpast) -> We are working on making cpast, more accessible and simple for all. If you have experience with python and/or writing prompts, consider contributing to [cpast\_llm](https://github.com/rootCircle/cpast_llm) repo. - ## Introduction Have you ever found yourself stuck in the middle of a coding contest, frustrated by a bug or an elusive edge case that just won’t reveal itself? Or maybe you’ve spent countless hours comparing outputs manually, only to find that the real problem was a tricky test case you hadn’t considered. Well, I’ve been there, and I have good news: there’s a solution that can change the way you approach competitive programming forever. @@ -30,21 +25,21 @@ Here’s the best part: with cpast, all you need is your _solution file_ and the ## Getting Started -https://github.com/user-attachments/assets/3b7d5b88-5a2a-4d01-8d5b-31f86b9a96db - + ### Installation -For installation instructions, refer to [cpast README](./cpast/README.md#installation). +There are two ways to use cpast: -Install docker and (optionally) [mold](https://github.com/rui314/mold) linker for faster compilation times. -```bash -cargo install --version='~0.8' sqlx-cli --no-default-features --features rustls,postgres -./cpast_api/scripts/init_db.sh -./cpast_api/scripts/init_redis.sh -``` +1. **Local Installation**: Install cpast locally and get it running on your machine. +For running cpast locally, refer to [cpast README](./cpast/README.md#installation). + +2. **cpast_api**: Use cpast_api, which utilizes clex and ccode_runner in parallel for optimized performance and speed. +For running cpast API locally, refer to [cpast_api README](./cpast_api/README.md). -### Usage +For development it's recommended(optional) to install [mold](https://github.com/rui314/mold) linker for faster compilation times. + +### CLI Usage Here's a simple example of how to use `cpast`: @@ -73,6 +68,20 @@ At the heart of cpast is **clex**, a powerful custom language generator that giv For more information on the `clex` language and its usage, please refer to the [Grammar Rules for Clex Generator](./clex/docs/CLEX_LANG_SPECS.md). +## Workspace Meta + +We welcome you to the cpast mono-repo, where you can find all the tools and components that make up the cpast ecosystem. Here’s a brief overview of the different components you’ll find in this workspace: + +| Component | Description | Status | +|--------------|-------------------------------------------------------------------------------------------------------|-----------------------| +| cpast_api | Backend for cpast, handles server-side operations and API requests. | 🚧 Work in Progress | +| cpast | CLI interface for cpast, used locally to run tests and generate inputs. | ✅ Active | +| ccode_runner | Runs arbitrary program code on local devices/server side, compiles/interprets code, and sends output. | 🔄 Needs Change | +| cpastord | Integration of cpast for Discord, allowing users to run cpast commands within Discord. | ❌ Abandoned | +| clex | Parser and generator for the clex language, generates random input for programs based on clex syntax. | ✅ Active | +| cscrapper | Scrapes question descriptions from competitive programming sites like Codeforces and CodeChef. | 🔄 Needs Improvement | +| clex_llm | Generates clex language from input format, constraints, and problem descriptions using LLM. | 🤔 Under Consideration| + ## Meta * [cpast\_llm](https://github.com/rootCircle/cpast_llm) diff --git a/ccode_runner/README.md b/ccode_runner/README.md new file mode 100644 index 0000000..ee09c15 --- /dev/null +++ b/ccode_runner/README.md @@ -0,0 +1,74 @@ +# ccode_runner + +`ccode_runner` is a component designed to run arbitrary program code on local devices. It compiles or interprets code and sends the output, making it an essential part of the cpast ecosystem. + +## Features + +- **Multi-language Support**: Supports various programming languages including Rust, Python, C, C++, Java, Ruby, and JavaScript. +- **Compilation and Interpretation**: Handles both ahead-of-time compilation and just-in-time interpretation. +- **Optimized Execution**: Uses precompilation and caching to optimize execution times. + +## Getting Started + +### Prerequisites + +Ensure you have the necessary compilers and interpreters installed for the languages you intend to use. + +### Installation + +Clone the repository and navigate to the `ccode_runner` directory: + +```bash +git clone https://github.com/rootCircle/cpast.git +cd cpast/ccode_runner +``` + +### Usage + +To use `ccode_runner`, you need to integrate it within your cpast testing workflow. Below is an example of how to use it: + +```rust +use ccode_runner::lang_runner::program_store::ProgramStore; +use std::path::Path; + +fn main() { + let correct_file = Path::new("path/to/correct_file.rs"); + let test_file = Path::new("path/to/test_file.rs"); + let do_force_compile = true; + + let program_store = ProgramStore::new(correct_file, test_file, do_force_compile).unwrap(); + + let stdin_content = "input data"; + let (is_different, correct_output, test_output) = program_store + .run_codes_and_compare_output(stdin_content) + .unwrap(); + + println!("Outputs are different: {}", is_different); + println!("Correct Output: {}", correct_output); + println!("Test Output: {}", test_output); +} +``` + +### Supported Languages + +- **Rust**: `.rs` +- **Python**: `.py` +- **C**: `.c` +- **C++**: `.cpp`, `.cxx`, `.c++`, `.cc`, `.C` +- **Java**: `.java` +- **JavaScript**: `.js` +- **Ruby**: `.rb` + +### Compilation and Execution + +`ccode_runner` uses different strategies for different languages: + +- **Ahead-of-Time Compilation**: For languages like C, C++, Rust, and Java. +- **Just-in-Time Interpretation**: For languages like Python, Ruby, and JavaScript. +- **Ahead-of-Time Interpreted**: For Java, which requires converting to intermediate bytecode before execution. + +ccode_runner is well suited when repeated compilation might be required for one code like in case for cpast, it intelligently skips those cases for you, making it lot faster! + +## Contributing + +We welcome contributions! Please read our [Contributing Guidelines](../CONTRIBUTING.md) for more details. diff --git a/ccode_runner/src/lang_runner.rs b/ccode_runner/src/lang_runner.rs index b28068b..0fdf71a 100644 --- a/ccode_runner/src/lang_runner.rs +++ b/ccode_runner/src/lang_runner.rs @@ -1,3 +1,3 @@ pub mod program_store; -mod runner; +pub mod runner; pub(crate) mod runner_error_types; diff --git a/ccode_runner/src/lang_runner/runner.rs b/ccode_runner/src/lang_runner/runner.rs index 2e22b1c..25c77b8 100644 --- a/ccode_runner/src/lang_runner/runner.rs +++ b/ccode_runner/src/lang_runner/runner.rs @@ -9,7 +9,7 @@ const DEFAULT_PROGRAM_NAME: &str = "program"; const EMPTY_STRING: &str = ""; #[derive(Debug)] -pub(crate) enum LanguageName { +pub enum LanguageName { Python, Cpp, C, diff --git a/clex/README.md b/clex/README.md index 4540254..6f5963a 100644 --- a/clex/README.md +++ b/clex/README.md @@ -1,7 +1,5 @@ # clex - Custom Language Generator -## Introduction - **clex** is a powerful language generator designed specifically for creating random test cases. It allows you to automate the generation of complex input scenarios, enabling developers to stress-test their code effectively. ## Features @@ -11,14 +9,56 @@ ## Getting Started -To use clex, you can integrate it within your cpast testing workflow. For detailed instructions, please refer to the usage section of the [cpast README](../cpast/README.md). +The best way to realize clex would be to use cpast CLI, instructions to setup it up is given in [cpast README](../cpast/README.md) or you can use it as a lib as well. + +### Prerequisites + +Ensure you have Rust installed on your machine. You can install Rust using [rustup](https://rustup.rs/). + +### Installation + +To install clex, add it as a dependency in your `Cargo.toml`: + +```toml +[dependencies] +clex = "0.1" // Adjust the version as necessary +``` + +### Usage + +Here’s a complete example demonstrating how to use the functions provided by the `clex` module: -## Clex Language Specification +```rust +use clex::{get_tokens, get_ast, generator}; + +// Get tokens from custom language +let tokens = get_tokens("(N) (?:N){\\1}".to_string()).unwrap(); +println!("Tokens: {:?}", tokens); + +// Get the Abstract Syntax Tree (AST) +let ast = get_ast("(N) (?:N){\\1}".to_string()).unwrap(); +println!("AST: {:?}", ast); + +// Generate code based on the custom language specification +let generated_code = generator("(N[1,10]) (?:N){\\1}".to_string()).unwrap(); +println!("Generated Code: {}", generated_code); +``` + +### Clex Language Specification For more information on the clex language and its usage, refer to the [Clex Language Specs](./docs/CLEX_LANG_SPECS.md). +### Examples + +- `N{2}`: Generates two random integers. +- `(N) (?:N){\\1}`: Generates a random integer, then the same number of additional integers. +- `(N) (?:S[\\1,])`: Generates a random integer, then a string of that length. +- `(N) (?:S[\\1,@CH_UPPER@])`: Generates a random integer followed by a random string of uppercase letters, where the length of the string is equal to the generated integer. +- `N S C`: Generates a random integer, string, and character. +- `F[-100,100]`: Generates a random floating-point number between -100 and 100. +- `(N[1,100]) (?:N[1,1000]){\\1} N[1,10000]`: Captures a random integer between 1 and 100, then generates that many integers between 1 and 1000, followed by another integer between 1 and 10000. + ## Meta - [Language Specification](./docs/CLEX_LANG_SPECS.md) - [Clex FAQs](./docs/CLEX_LANG_FAQs.md) - diff --git a/clex_llm/README.md b/clex_llm/README.md index 80bc1f2..9ec2b26 100644 --- a/clex_llm/README.md +++ b/clex_llm/README.md @@ -1,10 +1,61 @@ # clex_llm -Use this to generate clex from input_format and constarints. +> [!NOTE] +> Builds are currently broken for android mobiles, but we have no intention as of now to support it at this moment. -## Run tests +> [!NOTE] +> See previous efforts at [cpast_llm](https://github.com/rootCircle/cpast_llm). +**clex_llm** is a tool designed to generate [Clex](../clex/README.md) language expressions from input formats and constraints using a language model. It simplifies the process of creating complex test cases by converting human-readable descriptions into formal Clex grammar representations. + +## Features + +- **Automated Clex Generation**: Automatically generate Clex expressions based on input formats and constraints. +- **Integration with Google Generative AI**: Utilizes Google Generative AI for generating accurate and efficient Clex expressions. + +## Getting Started + +### Prerequisites + +Ensure you have Rust installed on your machine. You can install Rust using [rustup](https://rustup.rs/). + +### Installation + +Clone the repository and navigate to the `clex_llm` directory: + +```bash +git clone https://github.com/rootCircle/cpast.git +cd cpast/clex_llm +``` + +### Usage + +To use `clex_llm`, you need to set up your Google Generative AI API key and run the tests: ```bash GEMINI_API_KEY="" cargo test ``` + +### + + Example + +Here’s a complete example demonstrating how to use the `clex_llm` module: + +```rust +use clex_llm::{create_generator, generate_clex_expression}; + +#[tokio::main] +async fn main() { + let api_key = "your_google_api_key"; + let generator = create_generator(api_key).unwrap(); + + let input_format = "The first line contains an integer K, followed by K lines each containing a floating-point number P."; + let constraints = "1 ≤ K ≤ 50\n0.0 ≤ P ≤ 1000.0"; + + match generate_clex_expression(&generator, input_format, constraints).await { + Ok(expression) => println!("Generated Clex Expression: {}", expression), + Err(e) => eprintln!("Error generating Clex expression: {}", e), + } +} +``` diff --git a/cpast/README.md b/cpast/README.md index e1eef49..5364b92 100644 --- a/cpast/README.md +++ b/cpast/README.md @@ -1,14 +1,16 @@ -# cpast - Code Testing and Analysis Tool +# cpast_cli - Code Testing and Analysis Tool ![Crates.io](https://img.shields.io/crates/d/cpast) ![Crates.io](https://img.shields.io/crates/v/cpast) -![GitHub repo size](https://img.shields.io/github/repo-size/rootCircle/cpast) ![Crates.io](https://img.shields.io/crates/l/cpast) ![docs.rs](https://img.shields.io/docsrs/cpast) ## Introduction -**cpast** is a game-changing tool designed specifically for competitive programmers and developers who want to enhance their coding efficiency. Written in Rust for speed and reliability, cpast simplifies the process of comparing outputs from different code files, allowing you to focus on solving problems effectively. +> [!WARNING] +> Builds are currently broken for android mobiles as we recently removed clipboard support feature! We are thinking more for the fix along the way + +**cpast_cli**(from now on cpast) is a game-changing _CLI_ tool designed specifically for competitive programmers and developers who want to enhance their coding efficiency. Written in Rust for speed and reliability, cpast simplifies the process of comparing outputs from different code files, allowing you to focus on solving problems effectively. ### Installation diff --git a/cpast_api/README.md b/cpast_api/README.md index a11acaf..701aeed 100644 --- a/cpast_api/README.md +++ b/cpast_api/README.md @@ -1,33 +1,6 @@ -# Zero To Production In Rust +# cpast_api -
- -[Zero To Production In Rust](https://zero2prod.com) is an opinionated introduction to backend development using Rust. - -This repository serves as supplementary material for [the book](https://zero2prod.com/): it hosts several snapshots of the codebase for our email newsletter project as it evolves throughout the book. - -## Chapter snapshots - -The [`main`](https://github.com/LukeMathWalker/zero-to-production) branch shows the project at the end of the book. - -You can browse the project at the end of previous chapters by switching to their dedicated branches: - -- [Chapter 3, Part 0](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-03-part0) -- [Chapter 3, Part 1](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-03-part1) -- [Chapter 4](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-04) -- [Chapter 5](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-05) -- [Chapter 6, Part 0](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-06-part0) -- [Chapter 6, Part 1](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-06-part1) -- [Chapter 7, Part 0](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-07-part0) -- [Chapter 7, Part 1](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-07-part1) -- [Chapter 7, Part 2](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-07-part2) -- [Chapter 8](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-08) -- [Chapter 9](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-09) -- [Chapter 10, Part 0](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part0) -- [Chapter 10, Part 1](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part1) -- [Chapter 10, Part 2](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part2) -- [Chapter 10, Part 3](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part3) -- [Chapter 11](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-11) +> Based on [Zero To Production In Rust](https://zero2prod.com), which is an opinionated introduction to backend development using Rust. Highly recommended. ## Pre-requisites @@ -45,8 +18,8 @@ cargo install -f cargo-binutils rustup component add llvm-tools-preview ``` -``` -cargo install --version="~0.7" sqlx-cli --no-default-features --features rustls,postgres +```bash +cargo install --version="~0.8" sqlx-cli --no-default-features --features rustls,postgres ``` ### Linux @@ -58,8 +31,8 @@ sudo apt-get install lld clang libssl-dev postgresql-client sudo pacman -S lld clang postgresql ``` -``` -cargo install --version="~0.7" sqlx-cli --no-default-features --features rustls,postgres +```bash +cargo install --version="~0.8" sqlx-cli --no-default-features --features rustls,postgres ``` ### MacOS @@ -68,8 +41,8 @@ cargo install --version="~0.7" sqlx-cli --no-default-features --features rustls, brew install michaeleisel/zld/zld ``` -``` -cargo install --version="~0.7" sqlx-cli --no-default-features --features rustls,postgres +```bash +cargo install --version="~0.8" sqlx-cli --no-default-features --features rustls,postgres ``` ## How to build @@ -92,7 +65,7 @@ Launch `cargo`: cargo build ``` -You can now try with opening a browser on http://127.0.0.1:8000/login after +You can now try with opening a browser on after having launch the web server with `cargo run`. There is a default `admin` account with password diff --git a/cpast_api/src/configuration.rs b/cpast_api/src/configuration.rs index 8752fb7..1afc1d3 100644 --- a/cpast_api/src/configuration.rs +++ b/cpast_api/src/configuration.rs @@ -81,9 +81,14 @@ impl EmailClientSettings { } pub fn get_configuration() -> Result { - let base_path = match std::env::var("CARGO_MANIFEST_DIR") { - Ok(manifest_dir) => Ok(std::path::PathBuf::from(manifest_dir)), - Err(_) => std::env::current_dir(), + // TODO: Improve the error handling for this + // Possibly add the config at compile time, using build.rs? + let base_path = match option_env!("CARGO_MANIFEST_DIR") { + Some(manifest_dir) => Ok(std::path::PathBuf::from(manifest_dir)), + None => match std::env::current_dir() { + Ok(curr_dir) => Ok(curr_dir.join("cpast_api")), + Err(e) => Err(e), + }, } .expect("Failed to determine the current directory"); diff --git a/cpastord/README.md b/cpastord/README.md index 086084e..d634ee3 100644 --- a/cpastord/README.md +++ b/cpastord/README.md @@ -1,4 +1,13 @@ -# Serenity Hello World Bot with Shuttle +# cpastcord + +**cpastcord** is a Discord bot designed to integrate with the cpast tool, providing competitive programmers with a seamless experience for running and testing their code directly within Discord. This project is currently in its early stages, with the basic framework set up. + +## Features + +- **Command Handling**: Responds to specific commands with predefined messages. +- **Integration with cpast**: Future integration with the cpast tool for enhanced debugging and testing. + +## Serenity Hello World Bot with Shuttle In this example we will deploy a Serenity bot with Shuttle that responds to the `!hello` command with `world!`. To run this bot we need a valid Discord Token. To get started log in to the [Discord developer portal](https://discord.com/developers/applications). diff --git a/cscrapper/README.md b/cscrapper/README.md new file mode 100644 index 0000000..79a998d --- /dev/null +++ b/cscrapper/README.md @@ -0,0 +1,61 @@ +# cscrapper + +**cscrapper** is a tool designed to scrape problem statements from popular competitive programming platforms like CodeChef and CodeForces. It provides a unified interface to fetch problem details, including the problem statement, input format, and constraints. + +## Features + +- **Multi-Platform Support**: Supports scraping from both CodeChef and CodeForces. +- **Unified Interface**: Provides a single function to fetch problem statements from different platforms. +- **Error Handling**: Gracefully handles errors and provides meaningful error messages. + +## Getting Started + +### Prerequisites + +Ensure you have Rust installed on your machine. You can install Rust using [rustup](https://rustup.rs/). + +### Installation + +Add `cscrapper` as a dependency in your `Cargo.toml`: + +```toml +[dependencies] +cscrapper = "0.1" // Adjust the version as necessary +``` + +### Usage + +Here’s a complete example demonstrating how to use the `cscrapper` module: + +```rust +use cscrapper::{get_problem_statement, CodePlatform}; + +fn main() { + // Fetch a problem statement from CodeChef + let result = get_problem_statement(CodePlatform::CodeChef("NONNEGPROD")); + match result { + Ok(response) => { + println!("Statement: {}", response.statement); + println!("Input Format: {}", response.input_format); + println!("Constraints: {}", response.constraints); + } + Err(e) => eprintln!("Error fetching problem statement: {:?}", e), + } + + // Fetch a problem statement from CodeForces + let result = get_problem_statement(CodePlatform::CodeForces("1331", "B")); + match result { + Ok(response) => { + println!("Statement: {}", response.statement); + println!("Input Format: {}", response.input_format); + println!("Constraints: {}", response.constraints); + } + Err(e) => eprintln!("Error fetching problem statement: {:?}", e), + } +} +``` + +### Supported Platforms + +- **CodeChef**: Fetch problem statements using the problem code. +- **CodeForces**: Fetch problem statements using the contest ID and problem code.