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

Made module exclusively Python3 #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AidanDelaney
Copy link

Hi,
First of all, thank you for this module. It has saved us a good chunk of development time. I've updated this module so that it is Python 3 only. I've also added another test and updated it for Flask > 1.0. Hooks can now return their http status, which the runner is free to ignore, or return to the end-user. Please let me know if you'd like me to change this PR in any way.

Thank you.

@AidanDelaney
Copy link
Author

This branch should now cleanly merge onto master. It removes Python 2 runtimes from tox, and Travis.

Copy link
Contributor

@alexchamberlain alexchamberlain left a comment

Choose a reason for hiding this comment

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

Overall, this LGTM - a few comments on the boundaries.


import sys
if sys.version_info[0] < 3:
raise Exception(
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider RuntimeError.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

setup.py Outdated
description="Very simple, but powerful, microframework for writing Github webhooks in Python",
url="https://github.com/bloomberg/python-github-webhook",
author="Alex Chamberlain, Fred Phillips, Daniel Kiss, Daniel Beer",
author_email="[email protected], [email protected], [email protected], [email protected]",
license='Apache 2.0',
packages=["github_webhook"],
install_requires=['flask', 'six'],
install_requires=['flask==1.0.2'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider >= 1.0.2.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

@@ -69,7 +69,9 @@ def _postreceive(self):
'%s (%s)', _format_event(event_type, data), _get_header('X-Github-Delivery'))

for hook in self._hooks.get(event_type, []):
hook(data)
resp = hook(data)
Copy link
Contributor

Choose a reason for hiding this comment

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

If the use case is sending an error, would this be better represented with an exception?

Copy link
Author

Choose a reason for hiding this comment

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

In this case we're returning the http code that the wrapped function returns. This could be any http code such as a 301 which is not necessarily an error. I think the current approach is the best choice here, but I'm happy to be corrected.

setup.py Outdated
@@ -9,7 +9,7 @@
license='Apache 2.0',
packages=["github_webhook"],
install_requires=['flask==1.0.2'],
tests_require=['mock', 'nose'],
tests_require=['mock', 'pytest', 'nose'],
Copy link
Contributor

Choose a reason for hiding this comment

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

We should remove mock and nose here.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

tox.ini Outdated

[testenv]
deps =
pytest
pytest-cov
flask
six
py{27,py}: mock
pypy: mock
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're Python 3 only, is pypy appropriate?

Copy link
Author

Choose a reason for hiding this comment

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

I've changed it to pypy3, but is there any real reason to support pypy?

tox.ini Outdated

[testenv]
deps =
pytest
pytest-cov
flask
pypy: mock
mock
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove mock.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

This change uses the post 1.0 version of the Flask API.  We drop
support for Python 2 which allows us to remove dependencies on
`mock` and `six`.  Furthermore, we test against the documented
`postevent` from GitHub.  We choose to use the entire object
rather than a `postevent`-like object in order to test against
"real world" data.

Signed-off-by: Aidan Delaney <[email protected]>
Changed the error thrown on detecting a legacy Python 2 environment
to be a RuntimeError.  Also removed tox dependency on mock and made
the Flask dependency less strict.  We now depend on any Flask release
greater than 1.0.x.

Signed-off-by: Aidan Delaney <[email protected]>
@legoktm legoktm mentioned this pull request Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants