This repo uses VSCode's Dev Containers extension to standardize the development environment and avoid headache-inducing installation. All development will happen inside a Docker container which installs the same dependencies and versions on every developer's machine.
You can either run the project locally or via Github codespaces. Since Github has way better servers than most of us and running our projects can be quite demanding for most computers, we recommend using codespaces. In either case, the actual experience when coding will be similar.
- Go to the main Github page and click the green "Code" button
- Go to the codespaces tab and create a new codespace
- Everything should set itself up automatically, wait until it says "your application running is available at...".
- If you want to get back to the codespace after closing it, go to the repository and once again click the green CODE button. It should show up in a list. You can also choose to open the codespace using vscode if you don't like the URL bar at the top or want to connect to the frontend, by clicking the three dots next to the codespace.
-
Using Windows? First set up WSL 2.
- Press Windows
⊞-> "Turn Windows features on or off". Enable "Windows Subsystem for Linux", might need to enable "Virtual Machine Platform" also. - Open Powershell as admin.
wsl --installwsl --set-default-version 2wsl --install -d Ubuntu-22.04wsl --set-default Ubuntu-22.04- For more info: Microsoft documentation
- Press Windows
-
Install Docker Desktop.
- Windows users: Make sure you select Use WSL 2 instead of Hyper-V if the option is presented.
-
Open a new VSCode window and install Dev Containers extension from the Extensions menu.
-
Open the Command Palette (
Ctrl + Shift + P/Cmd + Shift + P) and selectDev Containers: Clone Repository in Container Volume.... SelectGitHub, then enterfsek/WebWebWeb.git. -
After configuration has finished in the open terminal, it should say
Done. Press any key to close the terminal. Openmain.pyand make sure VSCode has selected our Python interpreter from.venvfolder: In the bottom right corner of VSCode it should say approximatelyPython 3.11.2 ('.venv': venv). Otherwise, open Command Palette ->Python: Select Interpreterand choose./.venv/bin/python. -
Open a new Bash terminal (
Ctrl + Shift + Ö) and runuvicorn main:app --reload. Terminal should have (.env), otherwise runsource .venv/bin/activate. -
Go to http://127.0.0.1:8000/docs for the Swagger page automatically generated by FastAPI 🎉
-
From now on, whenever you want to open this project: Open a new VSCode window and in Recent, find
WebWebWeb in a unique volume [Dev Container]. Don't re-runClone Repository...from step 3.
-
Try calling some routes. You will find some routes fail since you are not logged in. Find the "Authorize" button and login using boss@fsektionen.se
dabdab. -
Call the GET
/users/meroute to view the logged in used. Change your last name to something creative by calling the PATCH/users/me. -
Evidently, the database is already filled with some starting data. This was done in the
seed.pyfile when the server started. Go check it out! -
You can stop the FastAPI server anytime by entering
Ctrl+Cin the Bash terminal. -
Run
python --version. Every developer will run the same python version thanks to containers. -
Run
pip listto see all installed pip packages.
Our project will need packages not native to Python. FastAPI is one such dependency. The actual package files are not checked into Git. Instead, a file listing the required packages exists in the project.
The file requirements.txt lists all pip packages and versions needed.
To add a new package, add a new line in requirements.txt specifiying package name and exact version. Then, in terminal, while in the WebWebWeb folder, run pip install -r requirements.txt.