Skip to content
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

feat: add WSGI adapter #1085

Merged
merged 9 commits into from
May 28, 2024
Merged

feat: add WSGI adapter #1085

merged 9 commits into from
May 28, 2024

Conversation

WilliamBergamin
Copy link
Contributor

This PR introduced a WSGI adapter to bolt python, this will allow Bolt to be deployed in production without the need for an other WSGI compatible Web Framework like Flask

Testing

  1. Pull this branch
  2. Use the examples/wsgi/app.py as starting point for a test app
  3. Run scripts/build_pypi_package.sh
  4. Use the .whl file found under dist/ to run pip install /path/to/dist/slack_bolt.whl
  5. Run pip install gunicorn
  6. Run gunicorn app:api -b 0.0.0.0:3000 --log-level debug to start the application

Category

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

@WilliamBergamin WilliamBergamin added the enhancement New feature or request label May 24, 2024
@WilliamBergamin WilliamBergamin requested a review from seratch May 24, 2024 19:15
@WilliamBergamin WilliamBergamin self-assigned this May 24, 2024
@seratch
Copy link
Member

seratch commented May 24, 2024

Can you check the flake8 errors? https://github.com/slackapi/bolt-python/actions/runs/9228875341/job/25393855815?pr=1085

@seratch seratch added this to the 1.19.0 milestone May 24, 2024
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. This is a nice addition! Once you clean up things, we can go ahead with merging the change for the next minor release.

@@ -0,0 +1 @@
ENCODING = "utf-8" # should always be utf-8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for Slack apps but perhaps the comment should be clearer to clarify we understand this is not true for WSGI in general:

Suggested change
ENCODING = "utf-8" # should always be utf-8
ENCODING = "utf-8" # The content encoding for Slack requests/responses is always utf-8

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's good to rename this file to "intenrals.py" for consistency with other source files in this project?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the file to internals.py and updated the comment 💯

Copy link

codecov bot commented May 27, 2024

Codecov Report

Attention: Patch coverage is 91.95402% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 91.76%. Comparing base (dbe2333) to head (dd719c0).

Files Patch % Lines
slack_bolt/adapter/wsgi/handler.py 84.61% 6 Missing ⚠️
slack_bolt/adapter/wsgi/http_response.py 95.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1085   +/-   ##
=======================================
  Coverage   91.76%   91.76%           
=======================================
  Files         181      186    +5     
  Lines        6315     6403   +88     
=======================================
+ Hits         5795     5876   +81     
- Misses        520      527    +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

name = key.lower().replace("_", "-")
headers[name] = value
if key.startswith("HTTP_"):
name = key[len("HTTP_"):].lower().replace("_", "-") # fmt: skip
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out the black formatter was cause the Flake8 issue, the workaround if to add # fmt: skip on the line causing the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Black Formatter will add a whitespace between len("HTTP_") and :, Flake8 does not align with this syntax, the Black Formatter does not allow ignoring specific rules

key[len("HTTP_") :].lower().replace("_", "-")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense; thanks for clarifying it

@WilliamBergamin WilliamBergamin marked this pull request as ready for review May 27, 2024 19:04
@WilliamBergamin WilliamBergamin requested a review from seratch May 27, 2024 19:04
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you; looks great to me 👍

name = key.lower().replace("_", "-")
headers[name] = value
if key.startswith("HTTP_"):
name = key[len("HTTP_"):].lower().replace("_", "-") # fmt: skip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense; thanks for clarifying it

@seratch seratch merged commit 549252c into slackapi:main May 28, 2024
12 checks passed
@WilliamBergamin WilliamBergamin deleted the wsgi-adapter branch May 28, 2024 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants