Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Plone ♥︎ Python 3

94 vues

Publié le

The upcoming version Plone 5.2 will support Plone 3, what does that mean for you?
When should you start to use Python 3 in your new Plone projects? When and how should you migrate existing projects to Python 3? How do you migrate addons and your custom code?
Drawing from the experience with the migration of Plone itself I'll answer all the questions that arise from moving to Python 3.

Publié dans : Logiciels
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Plone ♥︎ Python 3

  1. 1. P L O N E P Y T H O N 3 PHILIP BAUER ♥
  2. 2. TEXT (WAS UNICODE IN PY2) BYTE S (WAS STRING IN PY2) STRING (BYTES IN PY2 / TEXT IN PY3)
  3. 3. BYTES ARE MEASURED IN KILOS, STORED IN DISKS AND TRANSFERED THROUGH CABLES
  4. 4. SAY: TEXT & BYTES
 NOT: UNICODE & STRING
  5. 5. U N I C O D E S A N D W I C H B Y T E S | T E X T | B Y T E ST E X T
  6. 6. safe_text (safe_unicode) safe_bytes (safe_encode)
  7. 7. s a f e _ n a t i v e s t r i n g b y t e s i n p y 3 t e x t i n p y 3
  8. 8. >>> 'foo' == u'foo' True >>> 'foo' + u'foo' u'foofoo' >>> u'foo' + 'foo' u'foofoo' Python 2 IMPLICIT CONVERSION
  9. 9. >>> b'foo' == 'foo' False >>> 'foo' + b'foo' TypeError: can only concatenate str (not "bytes") to str >>> b'foo' + 'foo' TypeError: can't concat str to bytes Python 3 IMPLICIT CONVERSION
  10. 10. >>> byte = b'huhu' >>> byte 'huhu' >>> byte.decode('utf8') u'huhu' >>> byte.encode('utf8') 'huhu' Python 2: bytes EXPLICIT CONVERSION
  11. 11. >>> byte = b'huhu' >>> byte b'huhu' >>> byte.decode('utf8') 'huhu' >>> byte.encode('utf8') AttributeError: 'bytes' object has no attribute 'encode' Python 3: bytes EXPLICIT CONVERSION
  12. 12. >>> text = u'foo' >>> text u'foo' >>> text.encode('utf8') 'foo' >>> text.decode('utf8') u'foo' Python 2: text EXPLICIT CONVERSION
  13. 13. >>> text = 'foo' >>> text 'foo' >>> text.encode('utf8') b'foo' >>> text.decode('utf8') AttributeError: 'str' object has no attribute 'decode' Python 3: text EXPLICIT CONVERSION
  14. 14. ITERATING IS WEIRD
  15. 15. >>> [i for i in 'huhu'] ['h', 'u', 'h', 'u'] Python 2 ITERATING OVER BYTES
  16. 16. >>> [i for i in b'huhu'] [104, 117, 104, 117] >>> [chr(i) for i in b'huhu'] ['h', 'u', 'h', 'u'] >>> [chr(i).encode('utf8') for i in b'huhu'] [b'h', b'u', b'h', b'u'] Python 3 ITERATING OVER BYTES
  17. 17. P Y T H O N 3 . 3 • Py3: u'text' • Py2: b'bytes' • u'text' is text in py2 and py3 • b'bytes' is bytes in py2 and py3
  18. 18. • text/bytes is the main issue when migrating code • It makes much more sense in py3 • Writing code that works in py2/py3 is not easy
  19. 19. L E T ' S TA L K A B O U T B R A Z I L
  20. 20. ZOPE 4
  21. 21. POR TING PLONE TO PYTHON 3
  22. 22. 1. MIGRATE PACKAGES FLYING BLIND • Tools: six, sixer and python-modernize • Educated Guessing™ • Testing in Python 2
  23. 23. 2 . S TA R T U P A N D M A N U A L T E S T • Fix what breaks • Test features manually • Nightly demo
  24. 24. 3 . A U T O M AT E D T E S T S • Get > 10.000 tests to work on Python 3 • Hunt & kill test-isolation issues • doctests oh my
  25. 25. CURRENT STATE (DEMO)
  26. 26. THANK YOU TO ALL THAT HELPED
  27. 27. STEFFEN ALLNER | PHILIP BAUER | ROEL BRUGGINK | GODEFROID CHAPELLE | MAIK DERSTAPPEN | GIL FORCADA | HARALD FRISENEGGER | DAVID GLICK | DANIEL HAVLIK | MICHAEL HOWITZ | JENS KLEIN | DAVI LIMA | ALEXANDER LOECHEL | THOMAS LOTZE | PETER MATHIS | JAN MEVISSEN | ROBERT NIEDERREITER | JONI ORPONEN | ALESSANDRO PISA | JOHANNES RAGGAM | MAURITS VAN REES | MANUEL REINHARDT | THOMAS SCHORR | ERIC STEELE | JENS VAGELPOHL | MATTHEW WILKES | ANDI ZEIDLER
  28. 28. UPGRADE TO PYTHON 3
  29. 29. 6 STEP PROCESS
  30. 30. 1 . U P G R A D E T O P L O N E 5 . 2 • Use Python 2.7
  31. 31. 2 . D R O P A R C H E T Y P E S • It's not asking too much • Migration for default types is available since 2013 • Migration for custom types is available since 2015
  32. 32. 3 . M I G R AT E Y O U R C O D E T O P Y T H O N 3 • Without Database • Support Python 2 and Python 3 • Small addons: Startup and fix whatever fails • Bigger addons: Use python-modernize • Same with tests • Beware of complex doctests
  33. 33. 4 . M I G R AT E A D D O N S • Same as above • Everyone benefits
  34. 34. 5 . M I G R AT E Y O U R D ATA B A S E • See David Glick's Talk • Downtime/Read-only might be ineviable
  35. 35. 6 . D E P L O Y O N P Y T H O N 3 • Test the production-setup with WSGI early
  36. 36. STAR T NOW DON'T WAIT WORK ITERATIVELY
  37. 37. R O A D M A P • 5.2a1 now • 5.2 final in February
  38. 38. T O D O • FTP and/or WebDAV • DB Migration • Upgrade- and porting-guide • Migrate Addons • Performance-tests
  39. 39. COME TO THE SPRINT
  40. 40. BRING YOUR ADDONS
  41. 41. QUESTIONS
  42. 42. WHAT ABOUT PYTHON 4?
  43. 43. W H E N W I L L P L O N E D R O P S U P P O R T F O R P Y T H O N 2 ?
  44. 44. WHAT ABOUT ZOPE 5?
  45. 45. WILL ARCHETYPES BE POR TED TO PYTHON 3?
  46. 46. HOW DO WE REPLACE FTP/WEBDAV?
  47. 47. W H Y D I D Y O U N O T ' S I M P LY ' M I G R AT E T O G U I L L I O T I N A ?
  48. 48. CAN I NOW USE ASYNC/ AWAIT?
  49. 49. W H Y D O E S N ' T T H E P L O N E F O U N D AT I O N S I M P LY B U Y S U P P O R T F O R P Y T H O N 2 . 7 F R O M R E D H AT / I B M F O R A L L O F U S ?
  50. 50. DOES PYTHON 3 MAKE PLONE RUN FASTER?
  51. 51. CAN I RUN THE SAME DB IN PY2 AND PY3?
  52. 52. I S A D D O N < Y O U R N A M E H E R E > A L R E A D Y P O R T E D ?
  53. 53. W I L L T H I S I N C R E A S E P L O N E ' S M A R K E T S H A R E ?
  54. 54. HOW DO I DEPLOY INTO PRODUCTION?
  55. 55. WILL THIS WORK ON WINDOWS?
  56. 56. ARE PRODUCTION-TOOLS ALREADY WORK, LIKE BACKUP, ZRS OR RELSTORAGE?
  57. 57. DOES BOBTEMPLATES.PLONE AND PLONECLI ALREADY WORK IN PY3?
  58. 58. MORE QUESTIONS...
  59. 59. @StarzelDe pbauer P L O N E P Y T H O N 3 PHILIP BAUER ♥ THANKS

×