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

Begin porting from Python2/Django 1.11 to Python3/Django 2.0 #70

Closed
wants to merge 29 commits into from

Conversation

speizerj
Copy link
Contributor

@speizerj speizerj commented Dec 3, 2017

Changes the Dockerfile to use Python 3.6, and requirements.txt to use Django 2.0

Clean up exceptions to Python3 format in dashboard/helpers.py

Changes the Dockerfile to use Python 3.6, and requirements.txt to use Django 2.0

Clean up exceptions to Python3 format in dashboard/helpers.py
@owocki
Copy link
Contributor

owocki commented Dec 3, 2017

awesome! a few questions:

  1. mind resolving the conflicts?
  2. whats left TODO here?
  3. should i ask the community to test this yet?

@speizerj
Copy link
Contributor Author

speizerj commented Dec 3, 2017

mind resolving the conflicts?

yep, will do

whats left TODO here?

I need to get the app to a point where it can run the local server successfully before we can test. I'll have a better time estimate after working on it some more today.

should i ask the community to test this yet?

hold off for now, once the app is running then I'll need the help

Changing the requirements.txt file to simply "PyPDF2" may have done the trick here. PyPDF hasn't been actively maintained for years and it appears that PyPDF2 has ported it to Python3 successfully.
DRF needed to be upgraded to be compatible with Django 2.0, and the sitemaps module just needed some basic tweaking to get working.
@speizerj
Copy link
Contributor Author

speizerj commented Dec 3, 2017

@owocki the local server is now running successfully on python3/django2. I've tested out the lifecycle of a funded issue on Ropsten and it's working for me (funding, claiming, accepting, rejecting)

Tips appear to be broken and so that's what I'll work on next, but if anyone has any insight there I'm all ears. The request.body is empty in send_tip_2 view, not sure why.

Now would be a good time to open it up to testing - I'm sure there are plenty of edge cases.

Dockerfile Outdated
@@ -1,4 +1,4 @@
FROM python:2.7-slim
FROM python:3.6
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to switch this to 3.6-slim-jessie ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure thing

@owocki
Copy link
Contributor

owocki commented Dec 4, 2017

just posted about this to #focus-dev-python on slack.

also, looks like theres a bunch new merge conflicts. might be because of the isort PR. sorry!

@mbeacom
Copy link
Contributor

mbeacom commented Dec 4, 2017

My apologies! Most, if not all of those conflicts should be fine to resolve if you drop in the setup.cfg and run sort -rc --atomic . in the repo root: web @speizerj

@owocki
Copy link
Contributor

owocki commented Dec 4, 2017

installing the dependancies so i can test now..

1 similar comment
@owocki
Copy link
Contributor

owocki commented Dec 4, 2017

installing the dependancies so i can test now..

@owocki
Copy link
Contributor

owocki commented Dec 4, 2017

got it running and most pages seem to work; did not test the flows end to end but i similarly get the tips error

@mbeacom
Copy link
Contributor

mbeacom commented Dec 4, 2017

The failure on send_tip_2 is because b'' is being passed as request.body and falsely passing through if request.body != '': since it's true.
Not saying this is the right answer, but if request.body not in ['', b'']: at least eliminates the JSONDecodeError

@speizerj
Copy link
Contributor Author

speizerj commented Dec 4, 2017

dockerfile has been updated and merge conflicts resolved manually - working on the tip bug now

Changed the send/receive tip views to check for response.body rather than comparing equality to an emtpy string
@speizerj
Copy link
Contributor Author

speizerj commented Dec 4, 2017

Tips appear to be working now, though I could only test out the sending functionality. The receive page appears to work as well but I couldn't confirm because I don't have the proper setup to test out the email functionality, and I couldn't get a link to test.

Copy link
Contributor

@jasonrhaas jasonrhaas left a comment

Choose a reason for hiding this comment

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

Just a few minor comments.

@@ -1,12 +1,12 @@
FROM python:2.7-slim
FROM python:3.6-slim-jessie
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason you chose the -slim-jessie image over the -slim or just the regular python:3.6 image? I'm wondering if some of the linux packages you are installing below might already be included in one of the other python images. Might speed up the build time a bit.

Copy link
Contributor

@mbeacom mbeacom Dec 4, 2017

Choose a reason for hiding this comment

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

Using the slim base cuts this docker image size in half... The slim base for 3.6 defaults to stretch, which is unsupported by a dependency we use due to the openssl version at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right -- I usually use the slim versions also unless I have some issue installing things on the container. Makes sense then re: openssl version.

@@ -67,7 +67,7 @@ def title(request):
urlVal = URLValidator()
try:
urlVal(url)
except ValidationError, e:
except ValidationError as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Total nit pick but if you aren't using any information from the Error Message you shouldn't even need the as e part.

Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@@ -77,7 +77,7 @@ def title(request):

try:
html_response = requests.get(url)
except ValidationError, e:
except ValidationError as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

@@ -96,7 +96,7 @@ def title(request):
for link in soup.find_all('h1'):
print(link.text)

except ValidationError, e:
except ValidationError as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

@@ -119,7 +119,7 @@ def keywords(request):
urlVal = URLValidator()
try:
urlVal(url)
except ValidationError, e:
except ValidationError as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

@@ -138,7 +138,7 @@ def keywords(request):
keywords.append(split_repo_url[-2])

html_response = requests.get(repo_url)
except ValidationError, e:
except ValidationError as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

@@ -149,7 +149,7 @@ def keywords(request):
for ele in eles:
keywords.append(ele.text)

except ValidationError, e:
except ValidationError as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

@@ -53,7 +53,7 @@ def send_tip(request):
@ratelimit(key='ip', rate='2/m', method=ratelimit.UNSAFE, block=True)
def receive_tip(request):

if request.body != '':
if request.body:
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@owocki
Copy link
Contributor

owocki commented Dec 4, 2017

thanks for pushing this fwd yall. heads down on other stuff today, but hit me up on slack if you want more community involvement

Since byte object doesn't have a format method, use % formatting instead, per: https://stackoverflow.com/a/22701750
@speizerj
Copy link
Contributor Author

speizerj commented Dec 7, 2017

FYI here's the error I'm getting when trying to submit the /whitepaper form (looks to be sendgrid related - assuming it's lack of credentials):

Traceback:

File "/usr/local/lib/python3.6/site-packages/python_http_client/client.py" in _make_request
  157.             return opener.open(request)

File "/usr/local/lib/python3.6/urllib/request.py" in open
  532.             response = meth(req, response)

File "/usr/local/lib/python3.6/urllib/request.py" in http_response
  642.                 'http', request, response, code, msg, hdrs)

File "/usr/local/lib/python3.6/urllib/request.py" in error
  570.             return self._call_chain(*args)

File "/usr/local/lib/python3.6/urllib/request.py" in _call_chain
  504.             result = func(*args)

File "/usr/local/lib/python3.6/urllib/request.py" in http_error_default
  650.         raise HTTPError(req.full_url, code, msg, hdrs, fp)

During handling of the above exception (HTTP Error 401: Unauthorized), another exception occurred:

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.6/site-packages/ratelimit/decorators.py" in _wrapped
  30.             return fn(*args, **kw)

File "/code/app/tdi/views.py" in whitepaper_new
  76.     send_mail(settings.CONTACT_EMAIL, settings.CONTACT_EMAIL, "New Whitepaper Request", str(body))

File "/code/app/marketing/mails.py" in send_mail
  62.     response = sg.client.mail.send.post(request_body=mail.get())

File "/usr/local/lib/python3.6/site-packages/python_http_client/client.py" in http_request
  227.                 return Response(self._make_request(opener, request))

File "/usr/local/lib/python3.6/site-packages/python_http_client/client.py" in _make_request
  161.             raise exc

Exception Type: UnauthorizedError at /whitepaper
Exception Value: HTTP Error 401: Unauthorized

@owocki
Copy link
Contributor

owocki commented Dec 7, 2017

you can generate a free sendgrid key at sendgrid.com (or just comment out that line for testing)

…ring generation

The whitepaper PDF generation did not work in Python3. The majority of changes were porting from using file() to open().

For bytestring generation - I've changed the format to use string.encode() instead of coercing the string to a bytestring with b"".
@speizerj
Copy link
Contributor Author

speizerj commented Dec 7, 2017

Whitepaper generation is now working for me locally, though I had to test with a dummy PDF (I don't have the whitepaper source). The watermark is being generated but does appear to be cut off a bit on the right hand side - not sure if that's a new bug or existing.

allow_tags has been deprecated (see https://docs.djangoproject.com/en/dev/internals/deprecation/#deprecation-removed-in-2-0)

Using format_html and mark_safe instead.
@owocki
Copy link
Contributor

owocki commented Dec 11, 2017

looks like theres a few merge conflicts on this PR now. we should go ahead and get this merged so that the overhead of keeping it current is less :P

@owocki
Copy link
Contributor

owocki commented Dec 11, 2017

@ speizerj thanks for your help on this so far. i can do a final round of QA and hopefully we can get this out by mid week

@speizerj
Copy link
Contributor Author

no worries @owocki I don't mind keeping it current - I'll take care of those merge conflicts tonight.

Sounds good re: QA/merge - let me know how I can help

@mbeacom
Copy link
Contributor

mbeacom commented Dec 11, 2017

I'm going to be raising a PR for GH integration and bounty model changes this evening, so I should be able to run through this again at some point shortly. Anything specific that I should hit or just run down the views and hit some of the common methods? I was hoping to get in some general tests to help you out, but didn't get that far yet! Maybe after the GH/bounty changes! Also, sorry for the conflicts! 😛

@owocki
Copy link
Contributor

owocki commented Dec 18, 2017

derp. looks like theres some merge conflcits now..

i could likely carve out some time to nail this down on weds if anyone else wants to do that with me

@speizerj
Copy link
Contributor Author

sure thing - I'll take care of the conflicts tonight and then happy to join you on Wed

@mbeacom
Copy link
Contributor

mbeacom commented Dec 19, 2017

We should be good with GH/express interest before then, so I should be free to help you both test/resolve whatever is needed as well (and you'll probably have more merge conflicts :trollface: )

Let me know if either of you need any help with this before then!

The tinyurl library is not python3 compatible, so I've migrated to the pyshortener library.
@jasonrhaas
Copy link
Contributor

hows it going on the move from Python 2 --> 3?

@owocki
Copy link
Contributor

owocki commented Jan 10, 2018

its... fallen to the backburner unforgtunately... :(

@owocki
Copy link
Contributor

owocki commented Jan 16, 2018

closing this as it's been moved over to the january2018_feature_integration branch. @mbeacom @speizerj are there any ongoing topics of converstaion from this branch you want to carry over there?

@owocki owocki closed this Jan 16, 2018
@speizerj
Copy link
Contributor Author

Nope I think we should be good, the only outstanding items were keeping it current with regards to merge conflicts and testing out all the flows to ensure there were no issues. I'll follow up on the new PR

@gitcoinbot
Copy link
Member

This issue now has a funding of 0.03 ETH (33.65 USD) attached to it.

  • If you would like to work on this issue you can claim it here.
  • If you've completed this issue and want to claim the bounty you can do so here
  • Questions? Get help on the Gitcoin Slack
  • $12461.63 more Funded OSS Work Available at: https://gitcoin.co/explorer

@owocki
Copy link
Contributor

owocki commented Feb 1, 2018

whoops.. meant to post this to another issue.. cleaning this up now

@gitcoinbot
Copy link
Member

The funding of 0.03 ETH (33.36 USD) attached to this issue has been killed by the bounty submitter

owocki pushed a commit that referenced this pull request Apr 30, 2021
leaderboard clientside  jscript version that just needs thegraph fetch
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.

None yet

5 participants