chore, docs: code formatting, README.md - #64
Conversation
This commit adds ruff as a dependency to the project and formats the code according to the rules in `backend/pyproject.toml`. It also allows for installs to be done using either `uv` or `pip` via `(uv) pip install -r backend/requirements.txt`, which should help cut down on the length of the install process.
A lot of the backend documentation in README.md was similar for different operating systems. This commit combines these similar lines to make the README.md a little more clear for new users. It also shows how to integrate uv` into our backend.
It's easier to get an LSP to pick up on what types variables and function parameters are supposed to be if there's type-hinting aplenty in the repo. This commit adds type hints to functions, global variables, and some local variables where they're not immediately obvious. Future commits should try to have type-hinting where possible and reasonable.
Some types don't want to statically resolve with just Pylance. The extra django stub dependencies allow for the LSP to more consistently understand which types are which. This should allow for fewer syntax errors when building in the future.
Apparently, pytest-django wants the parameters to be named "db" instead of anything. This reverts instances of preceeding underscores from the parameter lists of functions in tests.py to resolve this issue.
|
|
||
|
|
||
| # serializers are cool because they allow you to skip having to deal with the model constructors | ||
| User = get_user_model() |
There was a problem hiding this comment.
Django needs this line to avoid any conflicts when loading the default user model
|
|
||
| def create(self, validated_data): | ||
| return User.objects.create_user(**validated_data) # hashes passwords | ||
| extra_kwargs = {"password": {"write_only": True, "style": {"input_type": "password"}}} |
There was a problem hiding this comment.
New commit adds a trailing comma to get ruff to format as requested
| @@ -1,40 +1,42 @@ | |||
| from .models import Task | |||
| from rest_framework import serializers | |||
| from django.contrib.auth import get_user_model | |||
There was a problem hiding this comment.
Leave the django.contrib.auth import there
See below comment on Line 7
| @@ -1,153 +1,142 @@ | |||
| # Some tests created with aid from Gemini | |||
There was a problem hiding this comment.
We should probably still mention that some of the tests were LLM generated to be honest
There was a problem hiding this comment.
I'm not sure this is entirely necessary, but mentioning is fine with me.
| api_client: APIClient, | ||
| test_user: StudyUser, | ||
| test_task: Task, | ||
| test_username: str, |
| def test_task_belongs_to_requesting_user( | ||
| self, | ||
| api_client: APIClient, | ||
| test_user: StudyUser, |
| self, | ||
| api_client: APIClient, | ||
| test_user: StudyUser, | ||
| other_user: StudyUser, |
|
|
||
| # postman | ||
| .postman/ | ||
| postman/ |
There was a problem hiding this comment.
BTW I'm planning on using Insomnia instead of Postman right now
There was a problem hiding this comment.
Fine, but there's no harm in having Postman gitignore stuff here for right now. Once you set up Insomnia add it to the .gitignore
Fixes some requested changes requested in PR 64.
| "reward": 50, | ||
| "description": "Finish algebra 1", | ||
| "due_date": "2029-12-31" | ||
| "due_date": "2029-12-31", |
There was a problem hiding this comment.
It'll still break the JSON, even if it's not within the quotes. Trailing commas are disallowed in JSON objects, see this
| def test_create_task_missing_due_date( | ||
| self, | ||
| api_client: APIClient, | ||
| test_user: StudyUser, |
Co-authored-by: Andres <84483578+fmcubium@users.noreply.github.com>
fmcubium
left a comment
There was a problem hiding this comment.
An internal decision on formatting was made and I was also mistaken on Django serializers. LGTM
chore, docs: code formatting, README.md
This pull request contains some chores to tidy up that backend and make it easier to understand. In more detail, it streamlines the README.md, adds type hints, and adds some tooling to the requirements.txt to make local LSPs run more effectively.