-
-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor main.py #949 #1176
Refactor main.py #949 #1176
Conversation
…n code moved to app/ directory, helper functions in separate file, routes in separate files, init file for creating and configuring the Flask app
Looks very nice, but a big change, so want to spend some time going through it today. I did a quick test deploy and looks to be working fine with Google Cloud Platform so that's a good sign. Some initial thoughts/observations:
|
@SaptakS / @ibnesayeed can you cast your eyes over this too if you get a chance as think you're more familiar with Python than me! However let's limit the scope to just setting out the file structure correctly - there's a lot of legacy code here that @Super-Fly didn't write and I agree with the point in this first comment, that other refactors are better in a future PR than making this one too big. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The organization of the code looks good to me. I would suggest looking at some workflows and scripts to ensure that they will continue to function as intended because some of them watch changes in certain folders. I hope they use nested wildcards to cover the new structure automatically, but there is no harm in going through them once.
Yes once we have split it up we should look to add pytest test cases - like we have for |
I meant, we need to revisit all the places where certain paths are being watched for certain tasks to make sure they still cover what they were supposed to cover. For example: almanac.httparchive.org/.github/workflows/generate_chapters.yml Lines 20 to 27 in 8f51988
|
|
Actually skip that - not needed, that's covered by |
No, it does not need to be updated, as |
I didn't move Talisman out of the main.py because his instance is required in the same file to turn HTTPS off but basically we need it only in routes.py In order to fix that, I was thinking to create better debug detection, maybe to have .env file for development where we can override defaults, something like that With that fixed, we can move Talisman setting directly in routes.py and in configure() to set HTTPS on/off As for the add_header() cache, for me it seems logical to have all route related stuff somewhere there :) Maybe we can take out all numbers for caching in config.py? What do you think? |
Ah yes I see that now. Still, to me it seems like it's setup or config, so should really be part of
Well it depends whether you see I was thinking Also is there any way to list the routes, without having them within a WDYT? |
Really like this kind of PR by the way :) Got your points, let me look through it again and will push something btw I didn't like wrapping the routes in function but was stuck for a while and wanted to see some comments |
BTW I managed to move Check out these changes necessary to make that work: https://github.com/Super-Fly/almanac.httparchive.org/compare/main...bazzadp:refactor_py?expand=1 |
These are the diffs for
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this! Just a few naming bikesheds.
Refactor py
…sub directory, made talisman and app global for routes and errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fantastic now! Thanks so much!
One small extra ask - can you add yourself to src/config/2020.json
in the developers
team so you get credit on our Contributors page? It's in alphabetical order by first name.
@Super-Fly could you look at some suggested changes in Super-Fly#2 and then we can merge this? |
Flake8 compatibility
Fixes #949
For the purpose of the refactoring only of main.py I have done several things:
__init__
file in src/app directory for creating and configuring the Flask appI didn't do any refactoring of the rest of the code because I think this should be done in separate PR