חלקPart 6: Python בעידן ה-AI וקריירהPython in the AI era & career
כ-3 שעות (כולל הפסקה)About 3 hours (with a break)
פרויקט גמר והצגהFinal project & demo
תכנון, בנייה, בדיקות, פרסום והצגה.
Planning, building, testing, publishing and presenting.
הנקודות החשובותKey points
- שכבות: models → storage → service → cli/apiLayers: models → storage → service → cli/api
- כל מה שבניתם לאורך הקורסEverything you built through the course
- תיקיית
shelf/עם__init__.pyAshelf/folder with__init__.py - pyproject.toml: שם, תלויות, פקודותpyproject.toml: name, dependencies, commands
- כל החוקים במקום אחדAll the rules in one place
- CLI ו-API קוראים לאותן פונקציותThe CLI and API call the same functions
- קובץ
.github/workflows/tests.ymlA.github/workflows/tests.ymlfile - GitHub מריץ pytest בכל pushGitHub runs pytest on every push
- MAJOR.MINOR.PATCHMAJOR.MINOR.PATCH
מונחיםTerms
- חבילת קוד (package)code package: תיקייה של מודולים עם
__init__.py, שאפשר לייבא כיחידה אחת:from shelf.models import Book.A folder of modules with__init__.pythat can be imported as one unit:from shelf.models import Book. - pyproject.tomlpyproject.toml: קובץ ההגדרות הסטנדרטי של פרויקט פייתון: שם, גרסה, תלויות ופקודות.The standard settings file of a Python project: name, version, dependencies and commands.
- CICI: Continuous Integration: שרת שמריץ את הבדיקות אוטומטית בכל push, ומסמן אם משהו נשבר.Continuous Integration: a server that runs the tests automatically on every push and flags anything broken.
- גרסאות סמנטיותsemantic versioning: מספור MAJOR.MINOR.PATCH: שינוי שובר מעלה MAJOR, פיצ'ר חדש MINOR, תיקון PATCH.MAJOR.MINOR.PATCH numbering: a breaking change bumps MAJOR, a new feature MINOR, a fix PATCH.
- יומן שינוייםchangelog: קובץ שמתעד מה השתנה בכל גרסה, בשפה של משתמשים.A file recording what changed in each version, in users' language.
Cheatsheet
היקףScope
LAYERS = {
"models.py": "Book dataclass",
"storage.py": "SQLite: add, get, list, update",
"service.py": "rules: progress, stats, search",
"cli.py": "argparse commands",
"api.py": "FastAPI routes",
}חבילהPackage
[project]
name = "shelf"
version = "2.0.0"
description = "Track the books you read: CLI, API and stats"
requires-python = ">=3.12"
dependencies = ["fastapi", "uvicorn[standard]"]
שירותService
import sqlite3
from dataclasses import dataclass
@dataclass
class Book:
id: int
title: strCICI
name: tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4גרסהRelease
def bump(version, change):
major, minor, patch = map(int, version.split("."))
if change == "breaking":
return f"{major + 1}.0.0"
if change == "feature":
return f"{major}.{minor + 1}.0"
return f"{major}.{minor}.{patch + 1}"הצגהDemo
checklist = {
"pytest passes locally": True,
"CI is green on GitHub": True,
"README: install, usage, screenshots": True,
"demo data loaded (5+ books)": True,
"plan B screenshots ready": False,
"3-minute pitch rehearsed twice": True,שגיאות שפגשנוErrors we met
| שגיאהError | מה זה אומרWhat it means | מה עושיםWhat to do |
|---|---|---|
AssertionError | שכבה עליונה שמדלגת על שכבה ופונה ישר למסד.A top layer skipping a layer and talking straight to the database. | AssertionError: ['api.py'] talk to storage directly: ...: אם ה-API עוקף את ה-service, חוקים כמו "לא לעבור את מספר העמודים" ייכתבו פעמיים ויתפצלו. כל ממשק עובר דרך ה-service.AssertionError: ['api.py'] talk to storage directly: ...: if the API bypasses the service, rules like "don't pass the page count" get written twice and drift apart. Every interface goes through the service. |
ImportError | שוכחים את __init__.py ומייבאים עם נקודה מהמקום הלא נכון.Using a relative import from the wrong place. | ImportError: attempted relative import with no known parent package: ייבוא עם נקודה עובד רק בתוך חבילה. מריצים כ-python -m shelf.cli (או מתקינים עם pip install -e .).ImportError: attempted relative import with no known parent package: a dotted import works only inside a package. Run as python -m shelf.cli (or install with pip install -e .). |
AssertionError | חוק שנכתב רק בממשק אחד.A rule written in only one interface. | AssertionError: read 140 of 100: the API forgot the rule the CLI has: חוקים גרים בשירות, פעם אחת. שני הממשקים קוראים לו.AssertionError: read 140 of 100: the API forgot the rule the CLI has: rules live in the service, once. Both interfaces call it. |
AssertionError | הזחה שגויה ב-YAML.Wrong indentation in YAML. | AssertionError: list items at indents [3, 4]: ...: ב-YAML הזחה היא מבנה, בדיוק כמו בפייתון. GitHub יציג שגיאת תחביר והבדיקות לא ירוצו.AssertionError: list items at indents [3, 4]: ...: in YAML indentation is structure, just like Python. GitHub will show a syntax error and the tests won't run. |
AssertionError | מספר גרסה שנבנה כמחרוזת ומשווים אותו כמחרוזת.A version compared as a string. | AssertionError: max says 9.1.0: strings compare letter by letter: ממירים לטאפל מספרים: max(versions, key=lambda v: tuple(map(int, v.split(".")))).AssertionError: max says 9.1.0: strings compare letter by letter: convert to a tuple of numbers: max(versions, key=lambda v: tuple(map(int, v.split(".")))). |
ConnectionError | מסתמכים על אינטרנט בהדגמה.Relying on the internet for the demo. | ConnectionError: conference Wi-Fi is down: הדגמה שתלויה ברשת עלולה ליפול בדיוק ברגע הלא נכון. מכינים נתונים מקומיים ותשובות מוקלטות, כמו שעשינו באתר הזה.ConnectionError: conference Wi-Fi is down: a demo that needs the network may fail at exactly the wrong moment. Prepare local data and recorded replies, just like this site does. |