Skip to content

Commit abddf59

Browse files
authored
add vscode section to readme, fix other minor stuff (rubberdok#1041)
2 parents f24478b + adfe579 commit abddf59

File tree

1 file changed

+70
-22
lines changed

1 file changed

+70
-22
lines changed

README.md

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [Database](#database)
1717
- [Backend](#backend)
1818
- [Frontend](#frontend)
19+
- [VSCode](#vscode)
1920
- [Using test users](#using-test-users)
2021
- [Development Workflow](#development-workflow)
2122
- [Tech Stack](#tech-stack)
@@ -162,6 +163,11 @@ Website for the students at Industrial Economics and Technology Management at NT
162163

163164
## Project Setup
164165

166+
[With Docker](#with-docker) below describes how to set up the project fully in Docker. This may not work perfectly for
167+
everyone, particularly those using Windows - they may instead wish to follow the steps under
168+
[Without Docker](#without-docker). Finally, [VSCode](#vscode) describes how to configure your development environment in
169+
the VSCode editor.
170+
165171
### With Docker
166172

167173
1. Download, install and start Docker Desktop: https://www.docker.com/products/docker-desktop
@@ -248,21 +254,23 @@ If you still want to run Postgres without Docker, download and install it from h
248254
- If you do not want to use Python 3.9 globally, type `pyenv local 3.9.X` instead (make sure you are in the
249255
`indok-web` folder when you do this)
250256
- Type `python --version` to verify that it has been set to `3.9.X`
251-
5. Type `cd indok-web/backend` to move into the backend folder (or just `cd backend` if you were already in `indok-web`)
257+
5. Type `cd indok-web` to move into the project folder (if you weren't already there)
252258
6. Type `python -m venv venv`
253259
- This sets up a Python virtual environment, to isolate this project from others
254260
7. Type `source venv/bin/activate` to activate the virtual environment
255261
- If on Windows, type `.\venv\scripts\activate` instead
256-
8. Type `python -m pip install -r requirements/local.txt` to install dependencies
262+
8. Type `cd backend` to move into the `backend` folder
263+
9. Type `python -m pip install -r requirements/local.txt` to install dependencies
257264
- If on Windows, also install the GTK3 runtime from the `.exe` here:
258265
https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases (one of the Python libraries we
259266
use depends on this)
260-
9. Ask the project maintainers for dev environment variables (not strictly required, but step 14 will not work without this)
261-
- If you're a member of Rubberdøk:
262-
- Go to the `#dev` channel in Slack
263-
- Find the pinned post with dev environment variables
264-
- Copy the variables for `backend/.env` into your own `.env` file in `indok-web/backend` (make sure not to overwrite the `DB_HOST` variable from the database setup)
265-
10. Set the environment variable `DJANGO_READ_DOT_ENV_FILE` to `true`
267+
10. Ask the project maintainers for dev environment variables (not strictly required, but step 14 will not work without this)
268+
- If you're a member of Rubberdøk:
269+
- Go to the `#dev` channel in Slack
270+
- Find the pinned post with dev environment variables
271+
- Copy the variables for `backend/.env` into your own `.env` file in `indok-web/backend` (make sure not to
272+
overwrite the `DB_HOST` variable from the database setup)
273+
11. Set the environment variable `DJANGO_READ_DOT_ENV_FILE` to `true`
266274
- On Mac/Linux:
267275
- Type `code ~/.zshrc` to open the `zsh` config in VSCode
268276
- If `code` doesn't work, try `open ~/.zshrc` to open it in another text editor
@@ -273,30 +281,33 @@ If you still want to run Postgres without Docker, download and install it from h
273281
- If `code` doesn't work, type `echo $profile` and open that file in some other text editor
274282
- Paste this line somewhere in that file: `$env:DJANGO_READ_DOT_ENV_FILE = "true"`
275283
- Save the file, and re-open PowerShell
276-
11. Type `python manage.py runserver` to run the backend server
284+
12. Type `python manage.py runserver` to run the backend server
277285
- If it fails, make sure that you:
278286
- are in the `indok-web/backend` folder
279287
- have your virtual environment active
280288
- have the database running
281-
12. Open a new terminal (leave the previous terminal open to keep the server running!)
282-
- Type `cd indok-web/backend` to get back to the backend folder
283-
- Type `source venv/bin/activate` (Mac) or `.\venv\scripts\activate` (Windows) to re-activate the virtual environment in this new terminal
284-
13. Type `python manage.py migrate` to update the database with our backend models
285-
14. Type `python manage.py loaddata initial_data` to load example data into the database
289+
13. Open a new terminal (leave the previous terminal open to keep the server running!)
290+
- Type `cd indok-web` to move into `indok-web` (or `cd ..` if you were put in `indok-web/backend`)
291+
- Type `source venv/bin/activate` (Mac) or `.\venv\scripts\activate` (Windows) to re-activate the virtual
292+
environment in this new terminal
293+
- Type `cd backend` to get back to the backend folder
294+
14. Type `python manage.py migrate` to update the database with our backend models
295+
15. Type `python manage.py loaddata initial_data` to load example data into the database
286296
- This also creates an admin user with username `admin` and password `admin123`
287297

288298
Now the backend should be running at `localhost:8000`! You can check out the GraphQL API at `localhost:8000/graphql`, or
289299
use the Django admin panel at `localhost:8000/admin` (log in with the admin user from step 14).
290300

291301
If you want to close the backend, press `Ctrl + C` in the terminal where it runs. To start it again:
292302

293-
1. Move into the backend folder (`cd indok-web/backend`)
303+
1. Move into the `indok-web` folder (`cd indok-web`)
294304
2. Activate your virtual environment
295305
- On Mac: `source venv/bin/activate`
296306
- On Windows: `.\venv\scripts\activate`
297-
3. Type `python manage.py runserver`
298-
4. If you need to run migrations:
299-
- Open a new terminal, and repeat steps 1 and 2
307+
3. Move into the backend folder (`cd backend`)
308+
4. Type `python manage.py runserver`
309+
5. If you need to run migrations:
310+
- Open a new terminal, and repeat steps 1-3
300311
- If you've made changes to Django models and want to generate new migrations: `python manage.py makemigrations`
301312
- Run migrations with `python manage.py migrate`
302313

@@ -329,6 +340,43 @@ Now the frontend should be running at `localhost:3000`! You can check it out in
329340
If you want to close the frontend, press `Ctrl + C` in the terminal where it runs. To start it again, type `yarn dev`
330341
inside `indok-web/frontend` (if dependencies have changed, you may have to run `yarn` first).
331342

343+
### VSCode
344+
345+
First of all, we recommend installing the following extensions:
346+
347+
- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
348+
- [Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
349+
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
350+
351+
Next, open the `indok-web` folder in VSCode, create a folder called `.vscode` at the top level, and a `settings.json`
352+
file inside that. Paste the following in it:
353+
354+
```
355+
{
356+
// Sets VSCode to auto-format files when saving
357+
"editor.formatOnSave": true,
358+
359+
// Configures Prettier, our formatter for TypeScript
360+
"[html][css][json][jsonc][yaml][javascript][javascriptreact][typescript][typescriptreact]": {
361+
"editor.defaultFormatter": "esbenp.prettier-vscode"
362+
},
363+
364+
// Configures Black, our formatter for Python
365+
"python.formatting.provider": "black",
366+
"python.formatting.blackArgs": ["--config=backend/pyproject.toml"],
367+
368+
// Configures flake8, our linter for Python
369+
"python.linting.flake8Enabled": true,
370+
"python.linting.flake8Args": ["--config=backend/tox.ini"],
371+
372+
// Allows the Python VSCode extension to suggest correct auto-import paths when having the project open in indok-web
373+
"python.analysis.extraPaths": ["backend"]
374+
}
375+
```
376+
377+
Finally, if you're on Mac, we recommend pressing `Cmd + Shift + P`, searching for "shell command", and clicking
378+
`Shell Command: Install 'code' command in PATH`. This lets you open your current folder in the terminal, using `code .`.
379+
332380
### Using test users
333381

334382
The `python manage.py loaddata initial_data` command used in the setup above sets up one admin user and two test users:
@@ -368,14 +416,14 @@ An outline of how a developer may work with this project:
368416
- Database (still with Docker):
369417
- Type `docker compose up postgres`
370418
- Backend:
371-
- Type `cd backend` to move into the backend folder
372419
- Activate your Python virtual environment
373420
- Mac: type `source venv/bin/activate`
374421
- Windows: type `.\venv\scripts\activate`
375422
- If you've followed the steps in the `#dev` channel in the Rubberdøk Slack: simply type `venv`
423+
- Type `cd backend` to move into the backend folder
376424
- Type `python manage.py runserver`
377425
- If it says you have unapplied migrations:
378-
- Open a new terminal, move back to `indok-web/backend`, and activate your virtual environment again
426+
- Open a new terminal in `indok-web`, activate your virtual environment again, then `cd backend`
379427
- Type `python manage.py migrate`
380428
- If it complains about missing dependencies:
381429
- Close the server (`Ctrl + C`)
@@ -465,8 +513,8 @@ An outline of how a developer may work with this project:
465513
- This is because we have configured "pre-commit hooks" to format and lint your code on commit
466514
- Since `black` and `flake8` are part of your Python virtual environment, you have to activate your virtual
467515
environment for these to work
468-
- In the terminal, type `source backend/venv/bin/activate` (Mac) / `.\backend\venv\scripts\activate` (Windows) /
469-
`venv backend` (from Rubberdøk Slack)
516+
- In the terminal, type `source venv/bin/activate` (Mac) / `.\venv\scripts\activate` (Windows) / `venv` (from
517+
Rubberdøk Slack)
470518
- If committing through the terminal, just run `git commit` again after this
471519
- If committing through VSCode, you may have to restart VSCode from the terminal to use your virtual environment
472520
(`code .`)

0 commit comments

Comments
 (0)