Skip to content

Commit 2044f44

Browse files
committed
feat: add script which can be ran with curl to setup template in an existing directory
1 parent d64cc03 commit 2044f44

1 file changed

Lines changed: 172 additions & 0 deletions

File tree

setup-cursor-github.sh

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/bin/bash
2+
3+
# Script to pull .cursor and .github folders from python-lib-template repository
4+
# Usage: curl -sSL https://raw.githubusercontent.com/dotle-git/python-lib-template/main/setup-cursor-github.sh | bash
5+
6+
set -e
7+
8+
REPO_URL="https://github.com/dotle-git/python-lib-template"
9+
RAW_URL="https://raw.githubusercontent.com/dotle-git/python-lib-template/main"
10+
11+
echo "🚀 Setting up .cursor and .github folders from python-lib-template..."
12+
13+
# Check if we're in a git repository
14+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
15+
echo "❌ Error: Not in a git repository. Please run this script from within a git repository."
16+
exit 1
17+
fi
18+
19+
# Function to detect if this is already a Python project
20+
detect_existing_project() {
21+
local has_pyproject=false
22+
local has_setup_py=false
23+
local has_requirements=false
24+
local has_src_structure=false
25+
local has_tests=false
26+
27+
# Check for common Python project files
28+
if [[ -f "pyproject.toml" ]] || [[ -f "setup.py" ]] || [[ -f "setup.cfg" ]]; then
29+
has_pyproject=true
30+
fi
31+
32+
if [[ -f "requirements.txt" ]] || [[ -f "requirements-dev.txt" ]]; then
33+
has_requirements=true
34+
fi
35+
36+
if [[ -d "src" ]] && [[ -n "$(find src -name "*.py" 2>/dev/null)" ]]; then
37+
has_src_structure=true
38+
fi
39+
40+
if [[ -d "tests" ]] && [[ -n "$(find tests -name "*.py" 2>/dev/null)" ]]; then
41+
has_tests=true
42+
fi
43+
44+
# Consider it an existing project if it has at least 2 of these indicators
45+
local indicators=0
46+
[[ "$has_pyproject" == true ]] && ((indicators++))
47+
[[ "$has_requirements" == true ]] && ((indicators++))
48+
[[ "$has_src_structure" == true ]] && ((indicators++))
49+
[[ "$has_tests" == true ]] && ((indicators++))
50+
51+
if [[ $indicators -ge 2 ]]; then
52+
echo "true"
53+
else
54+
echo "false"
55+
fi
56+
}
57+
58+
# Detect if this is an existing project
59+
IS_EXISTING_PROJECT=$(detect_existing_project)
60+
61+
if [[ "$IS_EXISTING_PROJECT" == "true" ]]; then
62+
echo "📋 Detected existing Python project - only copying .cursor, .github, and docs/agentdocs"
63+
COPY_TEMPLATE=false
64+
else
65+
echo "🆕 No existing Python project detected - will copy full template"
66+
COPY_TEMPLATE=true
67+
fi
68+
69+
# Always create .cursor directory and download files
70+
echo "📁 Creating .cursor directory..."
71+
mkdir -p .cursor
72+
73+
# Download .cursor files
74+
echo "⬇️ Downloading .cursor files..."
75+
curl -sSL "$RAW_URL/.cursor/environment.json" -o .cursor/environment.json
76+
curl -sSL "$RAW_URL/.cursor/Dockerfile" -o .cursor/Dockerfile
77+
78+
# Create .cursor/rules directory and download rules
79+
echo "📁 Creating .cursor/rules directory..."
80+
mkdir -p .cursor/rules
81+
82+
# Download .cursor/rules files
83+
echo "⬇️ Downloading .cursor/rules files..."
84+
curl -sSL "$RAW_URL/.cursor/rules/pypi-publish-rules.mdc" -o .cursor/rules/pypi-publish-rules.mdc
85+
curl -sSL "$RAW_URL/.cursor/rules/doc-writing-rules.md" -o .cursor/rules/doc-writing-rules.md
86+
87+
# Always create .github directory structure
88+
echo "📁 Creating .github directory structure..."
89+
mkdir -p .github/workflows
90+
91+
# Download .github/workflows files
92+
echo "⬇️ Downloading GitHub Actions workflows..."
93+
curl -sSL "$RAW_URL/.github/workflows/test.yml" -o .github/workflows/test.yml
94+
curl -sSL "$RAW_URL/.github/workflows/pypi-publish.yml" -o .github/workflows/pypi-publish.yml
95+
96+
# Always create docs/agentdocs directory
97+
echo "📁 Creating docs/agentdocs directory..."
98+
mkdir -p docs/agentdocs
99+
echo "# Agent Documentation" > docs/agentdocs/.gitkeep
100+
echo "# This directory is for agent-specific documentation" >> docs/agentdocs/.gitkeep
101+
102+
# Copy template files only if no existing project
103+
if [[ "$COPY_TEMPLATE" == "true" ]]; then
104+
echo "📋 Copying Python library template files..."
105+
106+
# Download pyproject.toml
107+
echo "⬇️ Downloading pyproject.toml..."
108+
curl -sSL "$RAW_URL/pyproject.toml" -o pyproject.toml
109+
110+
# Download .gitignore
111+
echo "⬇️ Downloading .gitignore..."
112+
curl -sSL "$RAW_URL/.gitignore" -o .gitignore
113+
114+
# Download LICENSE
115+
echo "⬇️ Downloading LICENSE..."
116+
curl -sSL "$RAW_URL/LICENSE" -o LICENSE
117+
118+
# Create src directory structure
119+
echo "📁 Creating src directory structure..."
120+
mkdir -p src/python_lib_template
121+
122+
# Download __init__.py
123+
echo "⬇️ Downloading src/python_lib_template/__init__.py..."
124+
curl -sSL "$RAW_URL/src/python_lib_template/__init__.py" -o src/python_lib_template/__init__.py
125+
126+
# Create tests directory and download test file
127+
echo "📁 Creating tests directory..."
128+
mkdir -p tests
129+
130+
# Download test file
131+
echo "⬇️ Downloading tests/test_dummy.py..."
132+
curl -sSL "$RAW_URL/tests/test_dummy.py" -o tests/test_dummy.py
133+
134+
# Download README.md (only if it doesn't exist or is very basic)
135+
if [[ ! -f "README.md" ]] || [[ $(wc -l < README.md) -lt 5 ]]; then
136+
echo "⬇️ Downloading README.md..."
137+
curl -sSL "$RAW_URL/README.md" -o README.md
138+
fi
139+
140+
echo "✅ Template files copied successfully!"
141+
else
142+
echo "⏭️ Skipping template files (existing project detected)"
143+
fi
144+
145+
# Add files to git
146+
echo "📝 Adding files to git..."
147+
git add .cursor/ .github/ docs/
148+
149+
if [[ "$COPY_TEMPLATE" == "true" ]]; then
150+
git add pyproject.toml .gitignore LICENSE src/ tests/ README.md
151+
fi
152+
153+
echo ""
154+
echo "✅ Successfully set up project with .cursor, .github folders, and docs/agentdocs directory!"
155+
if [[ "$COPY_TEMPLATE" == "true" ]]; then
156+
echo "📋 Full Python library template has been applied!"
157+
fi
158+
159+
echo ""
160+
echo "📋 Next steps:"
161+
echo " 1. Review the downloaded files and customize them for your project"
162+
if [[ "$COPY_TEMPLATE" == "true" ]]; then
163+
echo " 2. Update pyproject.toml with your project details (name, description, author, etc.)"
164+
echo " 3. Rename src/python_lib_template/ to match your project name"
165+
echo " 4. Update the package name in pyproject.toml and src directory"
166+
fi
167+
echo " 5. Commit the changes: git commit -m 'Add .cursor and .github configuration from python-lib-template'"
168+
echo " 6. Push to your repository: git push"
169+
echo ""
170+
echo "🔗 Original repository: $REPO_URL"
171+
echo "📚 You may want to customize the GitHub Actions workflows and Cursor rules for your specific project needs."
172+
echo "📖 The docs/agentdocs directory is ready for your agent documentation."

0 commit comments

Comments
 (0)