Metadata-Version: 2.4
Name: repositorytest
Version: 0.5.0
Summary: A tool for cloning and testing repositories (docker or local, interface is the same).
Author-email: Pavel Adamenko <padamenko@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/MERA-Evaluation/repotest
Project-URL: Bug Tracker, https://github.com/MERA-Evaluation/repotest/issues
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: docker
Requires-Dist: gitpython
Requires-Dist: tenacity>=9.0.0
Requires-Dist: python-dotenv
Requires-Dist: colorama==0.4.6
Requires-Dist: tqdm==4.67.1
Requires-Dist: psutil
Requires-Dist: fire>=0.6.0
Requires-Dist: ipython==8.12.2
Requires-Dist: coverage>=7.7.0
Provides-Extra: dev
Requires-Dist: setuptools; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: pandas>=2.0.0; extra == "dev"
Requires-Dist: pytest-json-report>=1.5.0; extra == "dev"
Requires-Dist: python-dotenv; extra == "dev"
Dynamic: license-file

# repotest


A library for automating test execution and repository operations.

It simplifies working with Docker and local repositories and provides utilities for managing patches and tests.

Originally built to facilitate LLM generation testing at the repository level, aimed at easing workflows for data scientists.

---

# Installation

1. Install the latest version using pip:

```bash
pip install repositorytest
```


2. To run the project in debug mode, add the current folder to the Python path:

```python
import sys
sys.path.append("/path/to/repotest")
```

3. Check which modes work on your current machine:

```python
from repotest.scripts import check_perfomance
```

---

# Design

The following diagram shows the architecture of the project and how different components interact:

---

# How to Clean All Caches

```python
from repotest.utils.clean import remove_all_containers, remove_all_images, clean_all, ...
```

---

# Example Usage

The project supports two execution modes: Docker-based and local.

**Using Docker:**

```python
from repotest.core.docker.java import JavaDockerRepo 

repo = JavaDockerRepo(
    repo="Osiris-Team/SPPU",
    base_commit="1a86a84e3c2dd7446b4778db8bb5dbaf44944f1c",
    image_name="maven:3.9.9-eclipse-temurin-23-alpine"
)

repo.clean()  # Reset the repo folder to the base commit state
# repo.build_env("", timeout=60*5)  # Set up the environment
# repo.apply_patch(patch)  # Apply a patch to the repo
repo.run_test("mvn test", timeout=60*5)  # Run tests with a 5-min timeout
```

**Using Local Filesystem:**

```python
from repotest.core.local.java import JavaLocalRepo

repo = JavaLocalRepo(
    repo="Osiris-Team/SPPU",
    base_commit="1a86a84e3c2dd7446b4778db8bb5dbaf44944f1c",
)

repo.clean()  # Reset the repo folder to the base commit state
# repo.build_env("", timeout=60*5)
# repo.apply_patch(patch)
repo.run_test("mvn test", timeout=60*5)
```

The interface for `*Repo` classes is the same across modes.

The only difference is that `JavaDockerRepo` allows specifying an image and cache volumes.
By default, Maven cache is stored in a Docker volume.

---

# Creating Git Patches for Java Projects

The following code generates a git patch from changes in the repository:

```python
from repotest.utils.git.git_diff_wrapper import GitDiffWrapper

changer = GitDiffWrapper(
    repo=task['repo_name'], 
    base_commit=task['base_commit']
)

changer.change_test(
    fn_test=task['test_file'], 
    str_test=task['output'], 
    str_source=task['source_code']
)

changer.fix_pom_file()
patch = changer.git_diff()
```

---

## Logs

All logs are saved to: `repotest/logs/%Y-%m-%d.log`
Only `critical` logs are printed to stdout by default.

To increase verbosity and print logs to stdout:

```python
from repotest.logger import change_console_logger_level
from logging import DEBUG

change_console_logger_level(DEBUG)
```

---

# Build the Package from Source

To build the package from source:

```bash
python -m build
```

---

# Run Tests

Tests follow the same file structure as the main library.
To run them (takes \~1–2 minutes):

```bash
pytest tests
```

---

# Dataset Overview

All datasets used for testing the library are stored in `../datasets/*.json`.
Example of how to load one:

```python
from datasets import load_dataset
ds = load_dataset('json', data_files="../datasets/java_from_1_2k_from_parser.jsonl")
```

---

# Enable/Disable Stdout Logs

By default, logs are stored in `~/.cache/repotest/logs/{date}.log`.

To toggle stdout logging:

```python
from repotest.constants import enable_stdout_logs, disable_stdout_logs

enable_stdout_logs()
disable_stdout_logs()
```
