Fix Docker Build Errors and Refactor the code in src/flask.py#189
Open
shoaibnigamshaik wants to merge 8 commits intocs50:mainfrom
Open
Fix Docker Build Errors and Refactor the code in src/flask.py#189shoaibnigamshaik wants to merge 8 commits intocs50:mainfrom
shoaibnigamshaik wants to merge 8 commits intocs50:mainfrom
Conversation
dmalan
requested changes
Apr 12, 2025
Member
dmalan
left a comment
There was a problem hiding this comment.
Thank you for this! Best to submit smaller PRs, though, that address individual issues. And the pkgutil code should be tightened up!
| _wrap_flask(module) # Pass the loaded module object to _wrap_flask | ||
|
|
||
| # Monkey-patch the loader's exec_module method with our wrapper | ||
| flask_spec.loader.exec_module = _exec_module_after |
Author
|
@dmalan thank you for reviewing my PR! My bad for such a cluttered PR! (I'm new to this) I resolved most of the conversations, and a couple merge conflicts with main. I'm eager for @rongxin-liu's reviewing! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi there 👋
I'm an online student currently working through the CS50 series — almost done with CS50x, CS50P, and CS50W. Out of curiosity, I decided to check out
cs50/python-cs50, so I cloned the repo and tried runningdocker compose build, as shown in the README.However, the build failed due to missing system dependencies required for installing the
mysqlclientandpsycopg2-binaryPython packages. To fix this, I updated the Dockerfile to include the following packages:build-essentialpkg-configlibpq-devAfter that, the image built successfully! 🎉
I then ran
docker compose up— both MySQL and PostgreSQL servers started as expected. I useddocker exec -it python-cs50 bash -lto get into the container, and ran the test commands listed in the README. Everything worked fine, except the final command, which tries to commit without an active transaction. I might open a separate issue for that later.Also, while reading the
docker buildlogs, I saw this warning:WARN[0000] /home/shoaib-quantumcalc/python-cs50/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusionSo I removed the
versionline fromdocker-compose.yml, rebuilt the image, and the warning went away.Another fix:
I updated the src/flask.py file to use
importlib.util.find_spec("flask")instead ofpkgutil.get_loader, as the latter is getting deprecated in Python 3.14, and I was afraid future students may not be able to use this library anymore.I initially saw this error when I was running pytest in my project. It said:
So I went on and replaced it. Not just that, I've refactored the code quite a bit in flask.py! For instance, I've removed unused imports, and replaced
except:with:
to align with best practices.
Thanks for this awesome library — it's been fun using it in my projects! It has made it relatively trivial to use it for managing databases compared to other libraries! Hope this PR is helpful. 🙌
P.S. I also took a course on Docker (via YouTube University 😄).