diff --git a/.gitignore b/.gitignore index 7fdfd7d..fe4331f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ # Local database files *.duckdb -# Python environment +# Python environment (UV creates .venv by default) .venv/ # Mono auto generated files diff --git a/TUTORIAL.md b/TUTORIAL.md index 3a873c4..d135b9e 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -104,41 +104,52 @@ If you don't have git: -#### 4. The Sandbox (Virtual Environment) +#### 4. UV -In tech policy, you know the value of containment. We don't want to install software libraries globally where they might break other things. We use a **Virtual Environment (venv)**—a self-contained sandbox for this specific project. +In tech policy, you know the value of containment. We don't want to install software libraries globally where they might break other things. We use **UV**—a modern, fast Python package manager that handles everything for us: creating a sandbox, installing the right Python version, and fetching dependencies. + +* *Concept:* **UV** is like a smart assistant that sets up your entire Python environment automatically. It reads a "shopping list" called `pyproject.toml` and fetches everything you need in one command. + +**Installing UV:** **On Windows (PowerShell):** ```powershell -python -m venv venv -.\venv\Scripts\activate - +powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" ``` +After installation, **close and reopen PowerShell** for the changes to take effect. + **On Mac/Linux (Terminal):** ```bash -python3 -m venv venv -source venv/bin/activate - +curl -LsSf https://astral.sh/uv/install.sh | sh ``` -*Check:* You should see `(venv)` appear at the start of your command prompt line. You are now inside the sandbox. +After installation, either restart your terminal or run: +```bash +source $HOME/.local/bin/env +``` -#### 5. Install Dependencies (The "Pip" Step) +*Check:* Type `uv --version` and press Enter. You should see a version number like `uv 0.5.x`. If you see "command not found", try restarting your terminal. -We need to equip our sandbox with specific tools like `streamlit` (for the website) and `duckdb` (for the database). To do this, we use **pip**. +#### 5. Install Dependencies (The "UV Sync" Step) -* *Concept:* **Pip** is the App Store installer for Python. Instead of browsing a store, we give it a shopping list called `requirements.txt`, and it fetches everything for us automatically. +Now we use UV to create our sandbox and install all the tools we need (like `streamlit` for the website and `duckdb` for the database). -Run this command: +Run this command from inside the project folder: ```bash -pip install -r requirements.txt - +uv sync ``` +*What just happened?* UV did several things automatically: +1. Created a `.venv` folder (the sandbox) +2. Installed the correct Python version if needed +3. Downloaded and installed all the required libraries + +*Check:* You should see output showing packages being installed. When it's done, you'll see something like "Resolved X packages" and "Installed X packages". + #### 6. Load the Cartridge Tell Ollama to download the specific brain we need (model `qwen3:4b`). @@ -175,10 +186,11 @@ We have set `debug_mode = true` by default. **Save the file** if you made any changes. Now, run the app from your CLI: ```bash -streamlit run parliament.py - +uv run streamlit run parliament.py ``` +*Note:* We use `uv run` to execute commands inside our sandbox. This ensures Streamlit uses the correct Python environment with all our installed dependencies. + ### 🌐 Part 3: Accessing the Dashboard *(Time: 2 mins)* diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1bdf510 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[project] +name = "parliament-uk" +version = "0.1.0" +description = "A demonstrator for the Regulate Tech podcast series that pulls and analyses UK Parliament data" +readme = "README.md" +requires-python = ">=3.11" +dependencies = [ + "streamlit", + "duckdb", + "requests", + "pandas", + "toml", +] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 9769434..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -streamlit -duckdb -requests -pandas -toml \ No newline at end of file