Skip to content

Commit 0d9f1a6

Browse files
committed
improve legibility
1 parent 1c42428 commit 0d9f1a6

File tree

1 file changed

+51
-53
lines changed

1 file changed

+51
-53
lines changed

diff_production_configs.py

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#!/usr/bin/env python3
21
"""
3-
Script to compare configs from SANDAG/ABM release with configs from ActivitySim/sandag-abm3-example repo
2+
Script to compare configs from SANDAG/ABM release or branch with configs from ActivitySim/sandag-abm3-example repo
43
"""
54

65
import os
@@ -45,7 +44,7 @@ def run_command(cmd, cwd=None):
4544

4645

4746
def download_archive(url, dest_dir):
48-
"""Download the archive from GitHub (release or branch)"""
47+
"""Download the archive from GitHub releases"""
4948
print(f"Downloading archive from {url}...")
5049
response = requests.get(url, stream=True)
5150
response.raise_for_status()
@@ -59,13 +58,13 @@ def download_archive(url, dest_dir):
5958
return zip_path
6059

6160

62-
def clone_source_repo(repo_url, dest_dir, branch):
63-
"""Clone the source repository at a specific branch"""
64-
clone_cmd = f"git clone {repo_url} --branch {branch} source_repo"
61+
def clone_production_repo(repo_url, dest_dir, branch):
62+
"""Clone the production repository at a specific branch"""
63+
clone_cmd = f"git clone {repo_url} --branch {branch} production_repo"
6564

66-
print(f"Cloning source repo {repo_url} (branch: {branch})...")
65+
print(f"Cloning production repo {repo_url} (branch: {branch})...")
6766
run_command(clone_cmd, cwd=dest_dir)
68-
return dest_dir / "source_repo"
67+
return dest_dir / "production_repo"
6968

7069

7170
def extract_configs(zip_path, extract_dir):
@@ -108,79 +107,79 @@ def extract_configs(zip_path, extract_dir):
108107
return configs_path
109108

110109

111-
def clone_comparison_repo(repo_url, dest_dir, branch=None):
112-
"""Clone the comparison repository"""
113-
clone_cmd = f"git clone {repo_url} comparison_repo"
110+
def clone_example_repo(repo_url, dest_dir, branch=None):
111+
"""Clone the example repository"""
112+
clone_cmd = f"git clone {repo_url} example_repo"
114113
if branch:
115114
clone_cmd += f" --branch {branch}"
116-
117-
print(f"Cloning comparison repo {repo_url}" + (f" (branch: {branch})" if branch else " (default branch)") + "...")
115+
116+
print(f"Cloning example repo {repo_url}" + (f" (branch: {branch})" if branch else " (default branch)") + "...")
118117
run_command(clone_cmd, cwd=dest_dir)
119-
return dest_dir / "comparison_repo"
118+
return dest_dir / "example_repo"
120119

121120

122-
def perform_diff(source_dir, target_repo_dir, summary_only=True, subdir=None):
121+
def perform_diff(production_dir, example_dir, summary_only=True, subdir=None):
123122
"""Perform git diff between the two directories"""
124123
print("\n" + "="*80)
125124
print("PERFORMING DIFF")
126125
print("="*80 + "\n")
127126

128-
# Copy source configs to target repo for comparison
129-
# Find a suitable subdirectory in target repo to compare against
130-
target_configs = target_repo_dir / "configs"
131-
132-
if not target_configs.exists():
133-
print(f"Warning: {target_configs} does not exist in comparison repo")
127+
# Copy production configs to example repo for comparison
128+
# Find a suitable subdirectory in example repo to compare against
129+
example_configs = example_dir / "configs"
130+
131+
if not example_configs.exists():
132+
print(f"Warning: {example_configs} does not exist in example repo")
134133
print("Available directories:")
135-
for item in target_repo_dir.iterdir():
134+
for item in example_dir.iterdir():
136135
if item.is_dir():
137136
print(f" {item.name}")
138137
return
139138

140139
# If subdirectory specified, navigate to it
141140
if subdir:
142-
source_dir = source_dir / subdir
143-
target_configs = target_configs / subdir
144-
145-
if not source_dir.exists():
146-
print(f"Error: Subdirectory '{subdir}' not found in source configs at {source_dir}")
147-
print(f"Available subdirectories in source:")
148-
parent = source_dir.parent
141+
production_dir = production_dir / subdir
142+
example_configs = example_configs / subdir
143+
144+
if not production_dir.exists():
145+
print(f"Error: Subdirectory '{subdir}' not found in production configs at {production_dir}")
146+
print(f"Available subdirectories in production:")
147+
parent = production_dir.parent
149148
for item in parent.iterdir():
150149
if item.is_dir():
151150
print(f" {item.name}")
152151
return
153-
154-
if not target_configs.exists():
155-
print(f"Error: Subdirectory '{subdir}' not found in target configs at {target_configs}")
156-
print(f"Available subdirectories in target:")
157-
parent = target_configs.parent
152+
153+
if not example_configs.exists():
154+
print(f"Error: Subdirectory '{subdir}' not found in example configs at {example_configs}")
155+
print(f"Available subdirectories in example:")
156+
parent = example_configs.parent
158157
for item in parent.iterdir():
159158
if item.is_dir():
160159
print(f" {item.name}")
161160
return
162161

163162
# Use git diff to compare
164163
print(f"Comparing:")
165-
print(f" Source: {source_dir}")
166-
print(f" Target: {target_configs}")
164+
print(f" Production: {production_dir}")
165+
print(f" Example: {example_configs}")
167166
print("\n" + "-"*80 + "\n")
168167

169168
# Perform diff using git directly on both directories
170169
try:
171170
if summary_only:
172171
# Show only file names and status
173172
result = subprocess.run(
174-
['git', 'diff', '--no-index', '--name-status', str(target_configs), str(source_dir)],
175-
cwd=target_repo_dir,
173+
['git', 'diff', '--no-index', '--name-status', str(example_configs), str(production_dir)],
174+
cwd=example_dir,
176175
capture_output=True,
177176
text=True
178177
)
179178
else:
180179
# Show full diff
181180
result = subprocess.run(
182-
['git', 'diff', '--no-index', str(target_configs), str(source_dir)],
183-
cwd=target_repo_dir,
181+
['git', 'diff', '--no-index', str(example_configs), str(production_dir)],
182+
cwd=example_dir,
184183
capture_output=True,
185184
text=True
186185
)
@@ -242,10 +241,10 @@ def main():
242241
# Configuration
243242
REPO_OWNER = "SANDAG"
244243
REPO_NAME = "ABM"
245-
SOURCE_REPO_URL = f"https://github.com/{REPO_OWNER}/{REPO_NAME}.git"
246-
COMPARISON_REPO = "https://github.com/ActivitySim/sandag-abm3-example.git"
244+
PRODUCTION_REPO_URL = f"https://github.com/{REPO_OWNER}/{REPO_NAME}.git"
245+
EXAMPLE_REPO_URL = "https://github.com/ActivitySim/sandag-abm3-example.git"
247246

248-
# Determine source: release or branch
247+
# Determine production: release or branch
249248
# Check if it's a release tag (starts with 'v') or a branch name
250249
if args.production:
251250
source_ref = args.production
@@ -279,22 +278,21 @@ def main():
279278
# Step 2: Extract configs
280279
configs_dir = extract_configs(zip_path, temp_path)
281280
else:
282-
# Step 1: Clone source repo at specific branch
283-
source_repo = clone_source_repo(SOURCE_REPO_URL, temp_path, source_ref)
284-
281+
# Step 1: Clone production repo at specific branch
282+
production_repo = clone_production_repo(PRODUCTION_REPO_URL, temp_path, source_ref)
283+
285284
# Step 2: Find configs directory
286-
configs_dir = source_repo / "src" / "asim" / "configs"
285+
configs_dir = production_repo / "src" / "asim" / "configs"
287286
if not configs_dir.exists():
288287
print(f"Error: Could not find configs at {configs_dir}")
289288
sys.exit(1)
290289
print(f"Using configs from {configs_dir}")
291-
292-
# Step 3: Clone comparison repo
293-
comparison_repo = clone_comparison_repo(COMPARISON_REPO, temp_path, args.example)
294-
290+
291+
# Step 3: Clone example repo
292+
example_repo = clone_example_repo(EXAMPLE_REPO_URL, temp_path, args.example)
295293
# Step 4: Perform diff
296-
perform_diff(configs_dir, comparison_repo, summary_only=not args.full, subdir=args.subdir)
297-
294+
perform_diff(configs_dir, example_repo, summary_only=not args.full, subdir=args.subdir)
295+
298296
print("\n" + "="*80)
299297
print("DIFF COMPLETE")
300298
print("="*80)

0 commit comments

Comments
 (0)