#5 Python 2-to-3 conversion with Dependency Check
Merged 3 years ago by bt0dotninja. Opened 3 years ago by t0xic0der.
Unknown source rework-2-to-3  into  master

file modified
+28 -27
@@ -14,22 +14,23 @@

  

  .. code:: bash

  

-     sudo yum install fedmsg

-     sudo yum install python-fedmsg-meta-fedora-infrastructure

-     sudo yum install python-fabulous

-     sudo yum install tweepy

+     sudo dnf install fedmsg

+     sudo dnf install python-fedmsg-meta-fedora-infrastructure

+     sudo dnf install python3-pip

+     pip3 install fabulous --user

+     pip3 install tweepy --user

  

  ----

  

  Your first fedmsg script

  ~~~~~~~~~~~~~~~~~~~~~~~~

  

- .. code:: python

+ .. code:: python3

  

      import fedmsg

      import pprint

  

-     print "Posting up to listen on the fedmsg bus.  Waiting for a message..."

+     print("Posting up to listen on the fedmsg bus.  Waiting for a message...")

      for name, endpoint, topic, msg in fedmsg.tail_messages():

          pprint.pprint(msg)

  
@@ -40,10 +41,10 @@

  It's like a million voices cried out and then were silent

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  

- .. code:: python

+ .. code:: python3

  

-     #topic_filter = 'fedbadges'     # We really want this, but its rare

-     topic_filter = 'fedoratagger'   # This is much easier to test with

+     #topic_filter = "fedbadges"      # We really want this, but its rare

+     topic_filter  = "fedoratagger"   # This is much easier to test with

  

      for name, endpoint, topic, msg in fedmsg.tail_messages():

          if topic_filter not in topic:
@@ -59,7 +60,7 @@

  Some config at the top

  ~~~~~~~~~~~~~~~~~~~~~~

  

- .. code:: python

+ .. code:: python3

  

      import fedmsg.config

      import logging.config
@@ -75,7 +76,7 @@

  So meta

  ~~~~~~~

  

- .. code:: python

+ .. code:: python3

  

      import fedmsg.meta

  
@@ -93,14 +94,14 @@

          # Use it to make nice text and other things

          # See also: msg2icon, msg2link, msg2usernames, msg2packages...

          subtitle = fedmsg.meta.msg2subtitle(msg, **config)

-         print subtitle

+         print(subtitle)

  

  ----

  

  A picture is worth a thousand words

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  

- .. code:: python

+ .. code:: python3

  

      import tempfile

      import urllib
@@ -113,12 +114,12 @@

          icon = fedmsg.meta.msg2icon(msg, **config)

  

          _, filename = tempfile.mkstemp(suffix='.png')

-         print "Downloading", icon, "to", filename

+         print("Downloading", icon, "to", filename)

          urllib.urlretrieve(icon, filename)

  

-         print fabulous.image.Image(filename)

+         print(fabulous.image.Image(filename))

  

-         print "Cleaning up %r" % filename

+         print("Cleaning up %r" % filename)

          os.remove(filename)

  

  
@@ -152,7 +153,7 @@

  

  In it, put a file called ``fedmsg.d/twitter-secrets.py`` that looks like this:

  

- .. code:: python

+ .. code:: python3

  

      config = dict(

          consumer_key        = "your api key goes here",
@@ -174,7 +175,7 @@

  

  Go back to ``yourwordcloudbot.py`` and add the following:

  

- .. code:: python

+ .. code:: python3

  

      import tweepy

  
@@ -192,7 +193,7 @@

  And further down

  ~~~~~~~~~~~~~~~~

  

- .. code:: python

+ .. code:: python3

  

      for name, endpoint, topic, msg in fedmsg.tail_messages():

  
@@ -201,16 +202,16 @@

          icon = fedmsg.meta.msg2icon(msg, **config)

  

          _, filename = tempfile.mkstemp(suffix='.png')

-         print "Downloading", icon, "to", filename

+         print("Downloading", icon, "to", filename)

          urllib.urlretrieve(icon, filename)

  

          # Construct and post our tweet.

-         #print fabulous.image.Image(filename)

+         #print(fabulous.image.Image(filename))

          content = subtitle + " " + link

-         print "Tweeting %r" % content

+         print("Tweeting %r" % content)

          twitter_api.update_with_media(filename, content)

  

-         print "Cleaning up %r" % filename

+         print("Cleaning up %r" % filename)

          os.remove(filename)

  

  ----
@@ -390,7 +391,7 @@

  

      fedmsg-tail --really-pretty

  

- .. code:: python

+ .. code:: python3

  

      {

          "i": 1,
@@ -413,12 +414,12 @@

  consuming messages from python

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  

- .. code:: python

+ .. code:: python3

  

      import fedmsg

  

      for name, endpoint, topic, msg in fedmsg.tail_messages():

-         print topic, msg

+         print(topic, msg)

  

  

  consuming messages with a daemon
@@ -429,7 +430,7 @@

  <http://www.fedmsg.com/en/latest/consuming/#the-hub-consumer-approach>`_

  for writing plugins, but they look like this:

  

- .. code:: python

+ .. code:: python3

  

      import pprint

      import fedmsg.consumers

file modified
+15 -11
@@ -1,4 +1,4 @@

- #!/usr/bin/env python2

+ #!/usr/bin/env python3

  """

  Using custom colors

  ====================
@@ -6,7 +6,14 @@

  """

  

  from os import path

- from scipy.misc import imread

+ 

+ # imread is deprecated after version 1.2.0.

+ # from scipy.misc import imread

+ 

+ # Rather use, imread from matplotlib.pyplot

+ # Best for Python 3 compliance

+ from matplotlib.pyplot import imread

+ 

  import matplotlib.pyplot as plt

  import random

  import tempfile
@@ -37,13 +44,10 @@

  

  

  def test_scrub_logs():

-     scrubbed_logs = scrub_logs("""

-     there once was a guy who was cool

-     blahblahblah <threbean> this is the shit.

-     1234567890 * pingou lol

-     """)

- 

-     print scrubbed_logs

+     scrubbed_logs = scrub_logs("there once was a guy who was cool" + \

+                                "blahblahblah <threbean> this is the shit." + \

+                                "1234567890 * pingou lol")

+     print(scrubbed_logs)

  

  

  def grey_color_func(word, font_size, position, orientation, random_state=None):
@@ -65,7 +69,7 @@

  

      wc.recolor(color_func=grey_color_func, random_state=3)

  

-     _, tmpfilename = tempfile.mkstemp('-wordcloud.png')

+     _, tmpfilename = tempfile.mkstemp("-wordcloud.png")

      wc.to_file(tmpfilename)

      return tmpfilename

  
@@ -79,6 +83,6 @@

      text = "\n".join(lines)

      scrubbed = scrub_logs(text)

      fname = generate_word_cloud(scrubbed, "Fedora_logo_simple.png")

-     print fname

+     print(fname)

  

  test_generate_word_cloud()

file modified
+38 -23
@@ -1,35 +1,50 @@

+ arrow==0.15.6

+ attrs==19.3.0

+ Automat==20.2.0

  beautifulsoup4==4.3.2

- Cython==0.22

+ certifi==2020.4.5.1

+ chardet==3.0.4

+ constantly==15.1.0

+ cycler==0.10.0

+ Cython==0.29.17

  decorator==3.4.2

  Django==1.8

- fedmsg==0.13.1

+ fedmsg==1.1.1

  fedmsg-meta-fedora-infrastructure==0.5.2

+ hyperlink==19.0.0

+ idna==2.9

  image==1.3.9

+ incremental==17.5.0

  kitchen==1.2.1

- matplotlib==1.4.3

+ kiwisolver==1.2.0

+ lockfile==0.12.2

+ matplotlib==3.2.1

  mock==1.0.1

  moksha.common==1.2.3

- moksha.hub==1.4.4

+ moksha.hub==1.5.17

  munch==2.0.2

  nose==1.3.6

- numpy==1.9.2

+ numpy==1.18.4

  oauthlib==0.7.2

- Pillow==2.8.1

- psutil==2.2.1

- Pygments==2.0.2

- pyparsing==2.0.3

- python-dateutil==2.4.2

- python-fedora==0.4.0

- pytz==2015.2

- pyzmq==14.6.0

- requests==2.6.2

- requests-oauthlib==0.4.2

- scipy==0.15.1

- six==1.9.0

- tweepy==3.3.0

- Twisted==15.1.0

+ openidc-client==0.6.0

+ Pillow==7.1.2

+ psutil==5.7.0

+ Pygments==2.6.1

+ PyHamcrest==2.0.2

+ pyparsing==2.4.7

+ PySocks==1.7.1

+ python-dateutil==2.8.1

+ python-fedora==1.0.0

+ pytz==2020.1

+ pyzmq==19.0.1

+ requests==2.23.0

+ requests-oauthlib==1.3.0

+ scipy==1.4.1

+ six==1.14.0

+ tweepy==3.8.0

+ Twisted==20.3.0

  txWS==0.9.1

- txZMQ==0.7.4

- urllib3==1.10.3

- wordcloud==1.0.0

- zope.interface==4.1.2

+ txZMQ==0.8.2

+ urllib3==1.25.9

+ wordcloud==1.7.0

+ zope.interface==5.1.0

file modified
+9 -10
@@ -1,10 +1,7 @@

- #!/usr/bin/env python

+ #!/usr/bin/env python3

  

  import os

  import site

- site.addsitedir(os.path.dirname(__file__))

- site.addsitedir('/home/decause/.virtualenvs/word_cloud/lib/python2.7/site-packages/')

- 

  

  import fedmsg.config

  import fedmsg.meta
@@ -13,6 +10,9 @@

  import tweepy

  from gencloud import generate_word_cloud, scrub_logs, get_meeting_log

  

+ site.addsitedir(os.path.dirname(__file__))

+ site.addsitedir('/home/decause/.virtualenvs/word_cloud/lib/python2.7/site-packages/')

+ 

  # first load the fedmsg config from fedmsg.d

  config = fedmsg.config.load_config()

  
@@ -33,7 +33,7 @@

  

  fedmsg.init(active=True)

  

- print "STARTING UP.  Listening for fedmsg messages."

+ print("STARTING UP.  Listening for fedmsg messages.")

  for name, endpoint, topic, msg in fedmsg.tail_messages():

      if topic_filter not in topic:

          continue
@@ -45,7 +45,7 @@

  

      content = subtitle + " " + link + " " + "#fedora"

  

-     print "Working with url", url

+     print("Working with url " + str(url))

  

      # get the meeting log

      text = get_meeting_log(url)
@@ -56,15 +56,14 @@

      # generate the word_cloud

      word_cloud = generate_word_cloud(text, mask)

  

- 

-     print "Tweeting %r" % content

+     print("Tweeting " + str(content))

      twitter_api.update_with_media(word_cloud, content)

  

      try:

          os.remove(word_cloud)

      except Exception as e:

-         print "broked!", str(e)

+         print("broked! " + str(e))

  

      fedmsg.publish(topic="log", modname="logger", msg=dict(msg="Tweeted, lol"))

  

-     print "Done."

+     print("Done.")

Check the commit logs. :)

Pull-Request has been merged by bt0dotninja

3 years ago