mirror of
https://github.com/dwinkler1/np.git
synced 2026-02-19 22:40:57 -05:00
Refactor template: extract scripts, overlays, and hosts into separate modules
Co-authored-by: dwinkler1 <22460147+dwinkler1@users.noreply.github.com>
This commit is contained in:
parent
5e8f07c560
commit
3398a72241
17 changed files with 1185 additions and 422 deletions
10
templates/rde/scripts/activateDevenv.sh
Normal file
10
templates/rde/scripts/activateDevenv.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
if [[ -f "devenv.nix" ]]; then
|
||||
echo "🚀 Activating devenv environment..."
|
||||
exec @defaultPackageName@-devenv shell
|
||||
else
|
||||
echo "❌ No devenv.nix file found in the current directory."
|
||||
echo "To create one, run '@defaultPackageName@-initDevenv'"
|
||||
exit 1
|
||||
fi
|
||||
104
templates/rde/scripts/initProject.sh
Normal file
104
templates/rde/scripts/initProject.sh
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
PROJECT_NAME="${1:-@defaultPackageName@}"
|
||||
|
||||
echo "🚀 Setting up project: $PROJECT_NAME"
|
||||
|
||||
# Create directory structure
|
||||
directories=(
|
||||
"data/raw"
|
||||
"data/processed"
|
||||
"data/interim"
|
||||
"docs"
|
||||
"figures"
|
||||
"tables"
|
||||
"src/analysis"
|
||||
"src/data_prep"
|
||||
"src/explore"
|
||||
"src/utils"
|
||||
)
|
||||
|
||||
for dir in "${directories[@]}"; do
|
||||
if [[ ! -d "$dir" ]]; then
|
||||
mkdir -p "$dir"
|
||||
echo "✓ Created $dir/"
|
||||
fi
|
||||
done
|
||||
|
||||
# Create essential files
|
||||
if [[ ! -f "README.md" ]]; then
|
||||
cat > README.md << 'EOF'
|
||||
# RDE
|
||||
|
||||
## Project Structure
|
||||
- `data/`: Data files (gitignored)
|
||||
- `docs/`: Documentation
|
||||
- `figures/`: Output figures
|
||||
- `tables/`: Output tables
|
||||
- `src/`: Source code
|
||||
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Initialize git
|
||||
if [[ ! -d ".git" ]]; then
|
||||
git init
|
||||
echo "✓ Initialized Git repository and added: flake.nix, flake.lock"
|
||||
fi
|
||||
# Check if files are already staged/tracked before adding
|
||||
if ! git diff --cached --name-only | grep -q "flake.nix\|flake.lock" &&
|
||||
! git ls-files --error-unmatch flake.nix flake.lock >/dev/null 2>&1; then
|
||||
echo "✓ Adding flake.nix, flake.lock to Git repository"
|
||||
git add flake.nix flake.lock
|
||||
else
|
||||
echo "✓ flake.nix, flake.lock already tracked/staged in Git"
|
||||
fi
|
||||
# Create .gitignore
|
||||
if [[ ! -f ".gitignore" ]]; then
|
||||
cat > .gitignore << 'EOF'
|
||||
# Data files
|
||||
data/
|
||||
*.csv
|
||||
*.docx
|
||||
*.xlsx
|
||||
*.parquet
|
||||
|
||||
# R specific
|
||||
.Rproj.user/
|
||||
.Rhistory
|
||||
.RData
|
||||
.Ruserdata
|
||||
*.Rproj
|
||||
.Rlibs/
|
||||
|
||||
# Python specific
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.pytest_cache/
|
||||
.venv/
|
||||
|
||||
# Jupyter
|
||||
.ipynb_checkpoints/
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Devenv
|
||||
.devenv*
|
||||
devenv.local.nix
|
||||
|
||||
# direnv
|
||||
.direnv
|
||||
|
||||
# pre-commit
|
||||
.pre-commit-config.yaml
|
||||
EOF
|
||||
fi
|
||||
|
||||
echo "✅ Project setup completed successfully!"
|
||||
21
templates/rde/scripts/initPython.sh
Normal file
21
templates/rde/scripts/initPython.sh
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
if [[ ! -f "pyproject.toml" ]]; then
|
||||
echo "🐍 Initializing UV project..."
|
||||
uv init
|
||||
echo "📦 Adding IPython and Marimo..."
|
||||
uv add ipython
|
||||
uv add marimo
|
||||
echo "--------------------------------------------------------------------------"
|
||||
echo "✅ Python project initialized!"
|
||||
echo "run 'uv add PACKAGE' to add more python packages."
|
||||
echo "--------------------------------------------------------------------------"
|
||||
else
|
||||
echo "--------------------------------------------------------------------------"
|
||||
echo "🔄 Existing Python project detected."
|
||||
echo "📦 Ensuring IPython and Marimo are installed..."
|
||||
uv add ipython
|
||||
uv add marimo
|
||||
echo "Run '@defaultPackageName@-updateDeps' to update dependencies."
|
||||
echo "--------------------------------------------------------------------------"
|
||||
fi
|
||||
29
templates/rde/scripts/updateDeps.sh
Normal file
29
templates/rde/scripts/updateDeps.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "🔄 Updating project dependencies..."
|
||||
|
||||
RVER=$( wget -qO- 'https://raw.githubusercontent.com/ropensci/rix/refs/heads/main/inst/extdata/available_df.csv' | tail -n 1 | head -n 1 | cut -d',' -f4 | tr -d '"' ) &&\
|
||||
|
||||
sed -i "s|rixpkgs.url = \"github:rstats-on-nix/nixpkgs/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\";|rixpkgs.url = \"github:rstats-on-nix/nixpkgs/$RVER\";|" flake.nix
|
||||
echo "✅ R date is $RVER"
|
||||
|
||||
nix flake update
|
||||
echo "✅ Flake inputs updated"
|
||||
|
||||
if [[ -f "pyproject.toml" ]]; then
|
||||
uv sync --upgrade
|
||||
echo "✅ Python dependencies updated"
|
||||
fi
|
||||
|
||||
if [[ -f "Project.toml" ]]; then
|
||||
@defaultPackageName@-jl -e "using Pkg; Pkg.update()"
|
||||
echo "✅ Julia dependencies updated"
|
||||
fi
|
||||
|
||||
if [[ -f "devenv.nix" ]]; then
|
||||
devenv update
|
||||
echo "✅ Devenv dependencies updated"
|
||||
fi
|
||||
|
||||
echo "🎉 All dependencies updated!"
|
||||
Loading…
Add table
Add a link
Reference in a new issue