Add a Checkbox parameter (as well as a guide to contributing) #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
Before this PR, users of Flask-ML did not have any way to specify checkbox parameters as input. A checkbox parameter is one that has a label (i.e what the checkbox is for), and a boolean value.
This PR is part one of a two part PR series to add a checkbox to RescueBox-Desktop
Part 2 PR is here: UMass-Rescue/RescueBox-Desktop#338
This is a guide to how this PR was created:
If you want to follow along...
I recommend you follow through this guide. If you want to do so, checkout the commit hash before this PR:
1. Shell commands
2. Open up the project in a text editor of your choice
Example: In VSCode, make sure you don't have any problems in the project by checking View -> Problems
3. Modifications to openapi.yaml
The file
src/flask_ml/flask_ml_server/openapi.yamlcontains all the definitions for what data looks like in this project. We want to add a Checkbox parameter.See the changes to
openapi.yamlin the files changed to see how this is achieved.After making the above modifications, see step 4
4. Regenerate the pydantic models
Run the following bash command
If you are on Windows, then either get make, or copy the command from the Makefile and paste it in your shell.
Now, the file
src/flask_ml/flask_ml_server/models.pywill be automatically modified with the new schema.See the changes to
flask_ml_server/models.pyin the files changed to see what this looks like.5. Compiler assisted refactoring
After regenerating the models, you will see that the code breaks. If you are using VSCode (and have all the usual Python extensions installed), then View -> Problems will show you all the problems across the codebase. This is good because making any changes to our data model tells us exactly which parts of the codebase require changes. Let's fix them.
If you are following along, try fixing the code yourself. See the changes to the rest of the source files in the files changed section of this PR.
6. Writing tests
Let's run the tests and see what coverage we have:
This generates a file
htmlcov/index.html. Open up a web browser and open this file. You can also drag and drop it into a browser.See the line coverage and make sure all the lines associated with your change are covered by tests.
Let's write tests. We can add an initialization of our new parameter in
tests/constants.py. We can use this throughout our tests. Add tests as needed, and ensure cases are covered. See the modifications totests/*in this PR for example. Re-openhtmlcov/index.htmlto ensure coverage.If you are working in a separate project that uses FlaskML, you can install the modified version to your project as follows:
7. Modify the public facing website
Run the following shell commands:
This should show you a local build of the public website. We made the following changes:
8. Commit the changes
Commit the changes to Git. See the five commits below and which step it corresponds to above:
That's it! We're done. You can release a new version to PyPI if you are happy with the changes.