This guide documents the general process for analyzing Python repositories, setting up test environments, and constructing Docker containers for testing. We'll use examples from various repositories to illustrate the process.
- Python environment with
uvinstalled - Git for version control
- Docker for container management
The repository analysis process involves:
- Setting up the repository and test directories
- Configuring the analysis system
- Collecting and parsing commit history
- Analyzing commits for test-related changes
- Validating test environments using Docker
Before analyzing a new repository, you need to modify two configuration files:
Add your repository name to the list of supported repositories:
repo_str_names = [
"sympy",
"pandas",
# ... other repositories ...
"your_repo_name", # Add your repository here
]This automatically sets up necessary directory structures and paths.
Add your repository to the RepoName enum and configure test command:
class RepoName(str, Enum):
sympy = "sympy"
pandas = "pandas"
# ... other repositories ...
your_repo_name = "your_repo_name" # Add your repository here
class RepoAnalysisArgs(BaseModel):
# ... other code ...
@property
def tests_cmd(self):
# ... other conditions ...
if self.repo_name == RepoName.your_repo_name:
return "PYTHONWARNINGS='ignore::UserWarning,ignore::SyntaxWarning' .venv/bin/python -W ignore -m pytest -rA r2e_tests"First, add the target repository as a git submodule and create the necessary data directories:
# Create data directories for the target repository
mkdir -p commit_data/{repo_name} test_data/{repo_name}
# Add the repository as a submodule
git submodule add https://github.com/{org}/{repo_name}.git {repo_name}For example, with the bokeh repository:
mkdir -p commit_data/bokeh test_data/bokeh
git submodule add https://github.com/bokeh/bokeh.git bokehThe process involves two main steps:
Process and store the repository's commit history:
uv run python r2egym/repo_analysis/store_repo_commits.py \
--repo_name {repo_name} \
--n_cpus 60This step:
- Processes all commits in the repository
- Parses diffs and commit messages
- Stores commit data for analysis
- Uses parallel processing for efficiency
Filter and analyze commits to identify test-related changes:
uv run python r2egym/repo_analysis/analyze_testable_commits.py \
--repo_name {repo_name} \
--use_local_commit_data \
--n_cpus 50 \
--N 5000 \
--keep_only_bug_edit_commits \
--keep_only_testmatch_commits \
--keep_only_test_entity_edit_commitsThe analysis applies several filters:
- Commit size (files/lines changed)
- File types (Python files)
- Commit purpose (bug fixes)
- Test-related changes
- Test entity modifications
Test the installation process and validate the test environment:
uv run python r2egym/repo_analysis/repo_testextract.py \
--repo_name {repo_name} \
--use_local_commit_data \
--n_cpus 50 \
--N 500 \
--keep_only_bug_edit_commits \
--keep_only_testmatch_commits \
--keep_only_test_entity_edit_commits \
--model_name o1-mini \
--max_tokens 12000This step:
- Creates isolated Docker environments
- Validates installation scripts
- Tests commit changes
- Verifies test execution
- Use
--N 500for initial testing and validation - Adjust
--n_cpusbased on available system resources - Enable Docker cleanup to manage disk space
- Store results in organized directories:
- Commit data:
commit_data/{repo_name}/ - Test results:
test_data/{repo_name}/
- Commit data: