Add Band Name Generator project with CLI, tests, and documentation
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
|||||||
|
# Byte-compiled / cache
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# Virtual environments
|
||||||
|
.venv/
|
||||||
|
venv/
|
||||||
|
env/
|
||||||
|
ENV/
|
||||||
|
|
||||||
|
# Environment files
|
||||||
|
.env
|
||||||
|
|
||||||
|
# Packaging / build
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
*.egg-info/
|
||||||
|
.eggs/
|
||||||
|
|
||||||
|
# Test / coverage
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.mypy_cache/
|
||||||
|
.ruff_cache/
|
||||||
|
|
||||||
|
# IDEs / OS
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
# 🚀 Band Name Generator
|
||||||
|
|
||||||
|
A beginner-friendly Python program that suggests a band name using the user's hometown and pet's name.
|
||||||
|
|
||||||
|
## 📚 Table of Contents
|
||||||
|
|
||||||
|
- [Overview](#-overview)
|
||||||
|
- [Requirements](#-requirements)
|
||||||
|
- [Setup](#-setup)
|
||||||
|
- [Run](#-run)
|
||||||
|
- [Tests](#-tests)
|
||||||
|
- [License](#-license)
|
||||||
|
- [Links](#-links)
|
||||||
|
|
||||||
|
## 🧭 Overview
|
||||||
|
|
||||||
|
This is the Day 1 project from Udemy's [100 Days of Code™: The Complete Python Pro Bootcamp](https://www.udemy.com/course/100-days-of-code/). The program asks for the city you grew up in and the name of a pet, then combines them into your band name.
|
||||||
|
|
||||||
|
```text
|
||||||
|
Welcome to the Band Name Generator.
|
||||||
|
What's the name of the city you grew up in?
|
||||||
|
Paris
|
||||||
|
What's the name of a pet?
|
||||||
|
Rex
|
||||||
|
Your band name could be: Paris Rex
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📋 Requirements
|
||||||
|
|
||||||
|
- Python 3.13 or newer
|
||||||
|
- No runtime dependencies (the tests use Python's built-in `unittest`)
|
||||||
|
|
||||||
|
## 🛠️ Setup
|
||||||
|
|
||||||
|
Create a local virtual environment named `.venv` in the project root and activate it.
|
||||||
|
|
||||||
|
Windows (PowerShell):
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
python -m venv .venv
|
||||||
|
.venv\Scripts\Activate.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
Windows (Command Prompt):
|
||||||
|
|
||||||
|
```bat
|
||||||
|
python -m venv .venv
|
||||||
|
.venv\Scripts\activate.bat
|
||||||
|
```
|
||||||
|
|
||||||
|
macOS / Linux:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -m venv .venv
|
||||||
|
source .venv/bin/activate
|
||||||
|
```
|
||||||
|
|
||||||
|
Then install the project in editable mode:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -m pip install -e .
|
||||||
|
```
|
||||||
|
|
||||||
|
Run `deactivate` to leave the virtual environment. The `.venv` folder is ignored by Git.
|
||||||
|
|
||||||
|
## ▶️ Run
|
||||||
|
|
||||||
|
With `.venv` active:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -m band_name_generator
|
||||||
|
```
|
||||||
|
|
||||||
|
Or use the installed command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
band-name-generator
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🧪 Tests
|
||||||
|
|
||||||
|
With `.venv` active:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -m unittest discover -s tests
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📄 License
|
||||||
|
|
||||||
|
No license has been chosen yet. Add a `LICENSE` file and name it here once one is picked.
|
||||||
|
|
||||||
|
## 🔗 Links
|
||||||
|
|
||||||
|
- [Repository](https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code)
|
||||||
|
- [Documentation](https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code#readme)
|
||||||
|
- [Issue tracker](https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code/issues)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=68"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "band-name-generator"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Day 1 of 100 Days of Code: suggest a band name from a hometown and a pet's name."
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.13"
|
||||||
|
dependencies = []
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
band-name-generator = "band_name_generator.cli:main"
|
||||||
|
|
||||||
|
[tool.setuptools.packages.find]
|
||||||
|
where = ["src"]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
"""Band Name Generator: combine a hometown and a pet's name into a band name."""
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from band_name_generator.cli import main
|
||||||
|
|
||||||
|
main()
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
"""Command-line interface for the Band Name Generator."""
|
||||||
|
|
||||||
|
from band_name_generator.generator import generate_band_name
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
print("Welcome to the Band Name Generator.")
|
||||||
|
city = input("What's the name of the city you grew up in?\n")
|
||||||
|
pet = input("What's the name of a pet?\n")
|
||||||
|
try:
|
||||||
|
band_name = generate_band_name(city, pet)
|
||||||
|
except ValueError as error:
|
||||||
|
print(error)
|
||||||
|
raise SystemExit(1)
|
||||||
|
print(f"Your band name could be: {band_name}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
"""Core logic for building a band name."""
|
||||||
|
|
||||||
|
|
||||||
|
def generate_band_name(city: str, pet: str) -> str:
|
||||||
|
"""Combine a city and a pet's name into a band name.
|
||||||
|
|
||||||
|
Raises ValueError if either value is empty or only whitespace.
|
||||||
|
"""
|
||||||
|
city = city.strip()
|
||||||
|
pet = pet.strip()
|
||||||
|
if not city or not pet:
|
||||||
|
raise ValueError("Both the city and the pet's name are required.")
|
||||||
|
return f"{city} {pet}"
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from band_name_generator.generator import generate_band_name
|
||||||
|
|
||||||
|
|
||||||
|
class GenerateBandNameTests(unittest.TestCase):
|
||||||
|
def test_combines_city_and_pet(self):
|
||||||
|
self.assertEqual(generate_band_name("Paris", "Rex"), "Paris Rex")
|
||||||
|
|
||||||
|
def test_strips_whitespace(self):
|
||||||
|
self.assertEqual(generate_band_name(" Paris ", " Rex\n"), "Paris Rex")
|
||||||
|
|
||||||
|
def test_empty_city_raises(self):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
generate_band_name("", "Rex")
|
||||||
|
|
||||||
|
def test_blank_pet_raises(self):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
generate_band_name("Paris", " ")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user