Created
February 3, 2026 01:39
-
-
Save devinci-it/792ad92d7d4ef7e5db6424ef98b645c7 to your computer and use it in GitHub Desktop.
This setup script automates the initialization of a Python project using pipenv. It installs and upgrades the pipenv environment, adds essential development dependencies like build and wheel, and creates a Makefile with convenient targets to build source and wheel distributions. The script also initializes a git repository, also adding, .gitigno…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -e | |
| # ========================= | |
| # Colors | |
| # ========================= | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| NC='\033[0m' | |
| # ========================= | |
| # Helpers | |
| # ========================= | |
| create_gitignore() { | |
| URL="https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore" | |
| echo -e "${YELLOW}Fetching Python .gitignore from github/gitignore...${NC}" | |
| if [ ! -f .gitignore ]; then | |
| curl -fsSL "$URL" -o .gitignore | |
| else | |
| echo -e "${GREEN}.gitignore already exists, skipping download.${NC}" | |
| fi | |
| # Append .vscode/ if not already present | |
| if ! grep -qxF '.vscode/' .gitignore; then | |
| echo -e "${YELLOW}Appending '.vscode/' to .gitignore${NC}" | |
| echo -e "\n# VSCode folder\n.vscode/" >> .gitignore | |
| else | |
| echo -e "${GREEN}'.vscode/' already in .gitignore, skipping append.${NC}" | |
| fi | |
| } | |
| # ========================= | |
| # Pipenv setup | |
| # ========================= | |
| echo -e "${YELLOW}Installing pipenv environment...${NC}" | |
| pipenv install | |
| echo -e "${YELLOW}Upgrading pip inside virtualenv...${NC}" | |
| pipenv run pip install --upgrade pip | |
| echo -e "${YELLOW}Installing dev dependencies (build, wheel)...${NC}" | |
| pipenv install --dev picassocli build wheel | |
| # ========================= | |
| # Makefile | |
| # ========================= | |
| if [ ! -f Makefile ]; then | |
| echo -e "${YELLOW}Creating Makefile...${NC}" | |
| cat << 'EOF' > Makefile | |
| PIPENV := pipenv | |
| PYTHON := $(PIPENV) run python | |
| PACKAGE := your_package_name | |
| .DEFAULT_GOAL := help | |
| help: | |
| @echo "Targets:" | |
| @echo " make sdist Build source distribution" | |
| @echo " make wheel Build wheel only" | |
| @echo " make build Build sdist + wheel" | |
| @echo " make clean Remove build artifacts" | |
| @echo " make uninstall Uninstall package" | |
| clean: | |
| rm -rf build dist *.egg-info __pycache__ .pytest_cache | |
| uninstall: | |
| $(PIPENV) run pip uninstall -y $(PACKAGE) || true | |
| sdist: | |
| $(PYTHON) -m build --sdist | |
| wheel: | |
| $(PYTHON) -m build --wheel | |
| build: | |
| $(PYTHON) -m build | |
| EOF | |
| else | |
| echo -e "${GREEN}Makefile already exists, skipping.${NC}" | |
| fi | |
| # ========================= | |
| # Git init | |
| # ========================= | |
| if [ ! -d .git ]; then | |
| echo -e "${YELLOW}Initializing git repository...${NC}" | |
| git init | |
| create_gitignore | |
| git add . | |
| git commit -m "Initial project setup" | |
| else | |
| echo -e "${GREEN}Git already initialized, skipping.${NC}" | |
| fi | |
| # ========================= | |
| # Done | |
| # ========================= | |
| echo -e "${GREEN}Setup complete!${NC}" | |
| echo -e "${YELLOW}Starting pipenv shell (interactive)...${NC}" | |
| pipenv shell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment