Automating Python Project Setup with Raycast Extension

Automating Python Project Setup with Raycast Extension

In an earlier post, I shared a shell script to quickly set up new Python projects. Now, I’ve taken it a step further by creating a Raycast extension, making it even easier to start a new Python project with just a few keystrokes (I wrote about another Raycast extension to display Spotify song info here).

Here's what this script does:

  • Prompts for a project name as a command-line argument.
  • Creates a new project directory with the specified name.
  • Sets up a virtual environment within the project directory.
  • Installs required Python dependencies.
  • Creates sub-directories for source code, tests, and documentation.
  • Generates essential files like, requirements.txt, and
  • Initializes a Git repository for version control.
  • Opens the file in Visual Studio Code.

I wanted to create a Raycast extension for this script so that I could start new Python projects without even opening the terminal. This makes the process much quicker and more streamlined.

Creating the Raycast Extension

  1. Set Up the Raycast Script:
    • Open Raycast and go to the Extensions tab.
    • Click on "Create Script Command" and select "New Script Command."
  2. Add the Following Script:
    • Replace <YOUR_GITHUB_USERNAME> with your GitHub username.
    • Use the actual path to your project directory in the cd command.

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title New Python Project
# @raycast.mode compact

# Optional parameters:
# @raycast.icon 🤖
# @raycast.packageName Python Projects
# @raycast.argument1 { "type": "text", "placeholder": "Project name" }

# Documentation:
# Amit Jotwani
# @raycast.authorURL

# Replace <YOUR_GITHUB_USERNAME> with your actual GitHub username

# Get project name from the argument

# Check if project name is provided
if [ -z "$project_name" ]; then
  echo "Error: Please provide a project name."
  exit 1

# Create project directory
cd "$HOME/Dropbox/dev_projects/python_projects" || { echo "Error: Directory $HOME/Dropbox/dev_projects/python_projects does not exist."; exit 1; }
mkdir "$project_name"
cd "$project_name" || { echo "Error: Failed to navigate to project directory."; exit 1; }

# Initialize virtual environment
virtualenv -p python3 venv
source venv/bin/activate

# Install dependencies (e.g., requests and numpy)
# pip install numpy

# Create project structure
mkdir src tests docs

# Create main script
touch src/

# Create requirements.txt file
touch requirements.txt

# Create file

# Initialize version control (Git)
git init

# Create a new repository on GitHub
gh repo create "$project_name" --private

# Set up the remote repository
git remote add origin "$GITHUB_USERNAME/$project_name.git"

echo "Current working directory: $(pwd)"
echo "Git repository initialized and remote repository set up."

echo "Project setup complete. Happy coding!"

# Open in Visual Studio Code in a new window, and bring to focus
code --new-window . --goto src/

Setting Up the Extension

  • Save the script and make it executable by running chmod +x <script_name>.sh.
  • Open Raycast, go to "Extensions" and click "Import".
  • Select your script file and import it into Raycast.

Using the Extension

Now, whenever you need to start a new Python project, just use this Raycast command, enter the project name, and the automation will handle the rest.