Skip to content

Commit 3626114

Browse files
committed
Remove persistent lockfile from R install
1 parent d663165 commit 3626114

File tree

2 files changed

+56
-52
lines changed

2 files changed

+56
-52
lines changed

template/.devcontainer/{% if r_data_science %}checkREnvironment.ps1{% endif %}.jinja

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,43 +64,48 @@ try {
6464
}
6565
}
6666

67-
# Create pak lockfile from project dependencies (only if it doesn't exist)
67+
# Create temporary pak lockfile to scan project dependencies
68+
Write-Host "🔧 Scanning project for R package dependencies..." -ForegroundColor Cyan
6869
$pkgLockPath = Join-Path $projectRoot "pkg.lock"
69-
if (-not (Test-Path $pkgLockPath)) {
70-
Write-Host "🔧 Creating pak lockfile from project dependencies..." -ForegroundColor Cyan
71-
try {
72-
Rscript -e "setwd('$projectRoot'); pak::lockfile_create()"
73-
if ($LASTEXITCODE -eq 0) {
74-
Write-Host "✅ Pak lockfile created successfully" -ForegroundColor Green
75-
} else {
76-
throw "Creation failed"
77-
}
78-
} catch {
79-
Write-Host "❌ Error: Failed to create pak lockfile" -ForegroundColor Red
80-
exit 2
81-
}
82-
} else {
83-
Write-Host "ℹ️ Pak lockfile already exists, skipping creation" -ForegroundColor Blue
84-
}
8570

86-
# Install packages from lockfile
87-
if (Test-Path $pkgLockPath) {
88-
Write-Host "📦 Installing packages from pak lockfile..." -ForegroundColor Cyan
71+
try {
72+
Rscript -e "setwd('$projectRoot'); pak::lockfile_create(lockfile = 'pkg.lock')"
73+
if ($LASTEXITCODE -eq 0) {
74+
Write-Host "✅ Project dependencies scanned successfully" -ForegroundColor Green
8975

90-
try {
91-
Rscript -e "setwd('$projectRoot'); pak::lockfile_install(lockfile = 'pkg.lock')"
92-
if ($LASTEXITCODE -eq 0) {
93-
Write-Host "✅ Packages installed successfully from pak lockfile" -ForegroundColor Green
94-
} else {
95-
throw "Installation failed"
76+
# Install packages from temporary lockfile
77+
Write-Host "📦 Installing packages from scanned dependencies..." -ForegroundColor Cyan
78+
try {
79+
Rscript -e "setwd('$projectRoot'); pak::lockfile_install(lockfile = 'pkg.lock')"
80+
if ($LASTEXITCODE -eq 0) {
81+
Write-Host "✅ Packages installed successfully" -ForegroundColor Green
82+
} else {
83+
throw "Installation failed"
84+
}
85+
} catch {
86+
Write-Host "❌ Error: Failed to install packages" -ForegroundColor Red
87+
# Clean up lockfile even on failure
88+
if (Test-Path $pkgLockPath) {
89+
Remove-Item $pkgLockPath -Force
90+
}
91+
exit 2
9692
}
97-
} catch {
98-
Write-Host "❌ Error: Failed to install packages from pak lockfile" -ForegroundColor Red
99-
Write-Host "Please check the pkg.lock file and try again" -ForegroundColor Yellow
100-
exit 2
93+
94+
# Clean up temporary lockfile
95+
Write-Host "🧹 Cleaning up temporary lockfile..." -ForegroundColor Cyan
96+
if (Test-Path $pkgLockPath) {
97+
Remove-Item $pkgLockPath -Force
98+
Write-Host "✅ Temporary lockfile removed" -ForegroundColor Green
99+
}
100+
} else {
101+
throw "Scan failed"
102+
}
103+
} catch {
104+
Write-Host "❌ Error: Failed to scan project dependencies" -ForegroundColor Red
105+
# Clean up lockfile if it was partially created
106+
if (Test-Path $pkgLockPath) {
107+
Remove-Item $pkgLockPath -Force
101108
}
102-
} else {
103-
Write-Host "❌ Error: Pak lockfile was not created" -ForegroundColor Red
104109
exit 2
105110
}
106111

template/.devcontainer/{% if r_data_science %}checkREnvironment.sh{% endif %}.jinja

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,31 @@ else
5151
echo "✅ pak is already installed"
5252
fi
5353

54-
# Create pak lockfile from project dependencies (only if it doesn't exist)
55-
if [[ ! -f "$PROJECT_ROOT/pkg.lock" ]]; then
56-
echo "🔧 Creating pak lockfile from project dependencies..."
57-
if Rscript -e "setwd('$PROJECT_ROOT'); pak::lockfile_create()"; then
58-
echo "✅ Pak lockfile created successfully"
59-
else
60-
echo "❌ Error: Failed to create pak lockfile"
61-
exit 2
62-
fi
63-
else
64-
echo "ℹ️ Pak lockfile already exists, skipping creation"
65-
fi
66-
67-
# Install packages from lockfile
68-
if [[ -f "$PROJECT_ROOT/pkg.lock" ]]; then
69-
echo "📦 Installing packages from pak lockfile..."
54+
# Create temporary pak lockfile to scan project dependencies
55+
echo "🔧 Scanning project for R package dependencies..."
56+
LOCKFILE="$PROJECT_ROOT/pkg.lock"
57+
if Rscript -e "setwd('$PROJECT_ROOT'); pak::lockfile_create(lockfile = 'pkg.lock')"; then
58+
echo "✅ Project dependencies scanned successfully"
7059

60+
# Install packages from temporary lockfile
61+
echo "📦 Installing packages from scanned dependencies..."
7162
if Rscript -e "setwd('$PROJECT_ROOT'); pak::lockfile_install(lockfile = 'pkg.lock')"; then
72-
echo "✅ Packages installed successfully from pak lockfile"
63+
echo "✅ Packages installed successfully"
7364
else
74-
echo "❌ Error: Failed to install packages from pak lockfile"
75-
echo "Please check the pkg.lock file and try again"
65+
echo "❌ Error: Failed to install packages"
66+
# Clean up lockfile even on failure
67+
rm -f "$LOCKFILE"
7668
exit 2
7769
fi
70+
71+
# Clean up temporary lockfile
72+
echo "🧹 Cleaning up temporary lockfile..."
73+
rm -f "$LOCKFILE"
74+
echo "✅ Temporary lockfile removed"
7875
else
79-
echo "❌ Error: Pak lockfile was not created"
76+
echo "❌ Error: Failed to scan project dependencies"
77+
# Clean up lockfile if it was partially created
78+
rm -f "$LOCKFILE"
8079
exit 2
8180
fi
8281

0 commit comments

Comments
 (0)