SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Downloaden Sie, um offline zu lesen
SupportingPython3
in Large Scale Project
Kir Chou
A9 (Amazon Product Search)
1
Kir Chou
22
kir.chou
note35
2
3
Outline
q Background & Talks
q How to support python3?
q Execution Plan
q Lessons Learned
q Things can help you
https://pythonclock.org/
Python 2.7 EOL
2020 Jan 1st
4
Background
Python2only = Technical Debt
Talks:
Why Python3?
• Guido van Rossum (PyCascades 2018)
BDFL Python 3 retrospective
• Victor Stinner (PyCon 2018)
Python 3: ten years later
5
Talks:
How to make code Python2/3 compatible?
• Ned Batchelder (PyCon2012)
Pragmatic Unicode
Difference of String in python 2 and 3
• Brett Cannon (PyCon2015)
author of SupportingPython3
How to make your code Python 2/3 compatible
Strategy to support python3
6
Talks:
Learn from others
• Jason Fried (PyCon2018)
Fighting the Good Fight:
Python 3 in your organization
Facebook 5 years journey from python2 to 3
• Max Bélanger and Damien DeVille
How we rolled out one of the largest Python 3
migrations ever
Dropbox journey since 2015
7
How to support python3?
8
9
Python2
Code
Python3
Code
Python2/3
Code
Python2.x
Python3.y
Result
Ideal world
Result
10
Python2
Code
Python3
Code
Python2/3
Code
Supporting python3
in ideal world – (1)
1. Make all code in python3
11
Python2
Code
Python3
Code
Python2/3
Code
Python2.x
Python3.y
Result
Supporting python3
in ideal world – (2)
Result
2. Make sure the result is same
12
Python2
Code
Python3
Code
Python2/3
Code
Python2.x
Python3.y
Supporting python3
in ideal world – (3)
Result
3. Stop executing code
by python2 interpreter
13
真・How to support python3?
14
Large Scale
• Packages number: 3 digits
• 10+ years old packages
• Complicated relationship between packages
• Source line of code: Million level
• Number of production environment: 2 digits
• Build system for python: >1
• Deployment system: >1
15
16
Large Scale Project @ Real World
Python
Code
PythonX.Y Result
Q1. How to find your python code?
Q2. What interpreter do your system support?
Q3. What’s the intention of the result?
Python Code
Q1. How to find your python code?
17
Python
Package
Non-Python
Package
Inline
Command
Company
Internal
Dependencies
External
Dependencies
Q2. What interpreter do your
system support?
• Supported python interpreter?
• Default version of the system
• Virtualenv
• Dockerfile
• …
• Used python interpreter?
• By interpreter (pythonX.Y xxx.py)
• By shebang (#!/usr/bin/env python)
• By build system to wrap the script
• …
18
Q3. What’s the intention of the result?
19
Python
Code
PythonX.Y Result
unit tests
site-packages
script
application
Test Runner
Build System
Deployment System / …
Deployment System
integration tests Test Server’s Deployment System
Execution Plan
20
21
1. Prepare POC
2. Build a Team
3. Write Guideline
5. Estimate Task Size
6. Migrate Progressively
4. Investigate Tasks
1. Prepare PoC
Example @ my github
1. Find a tiny migratable package
2. Learn the approach to support python3
3. Prove of concept to support python3
4. Broadcast the idea to other knowledgeable people
and human resource allocator
22
23
Do you need a team for
Supporting Python3?
24
Gathering
Knowledges
25
Gathering
Knowledges
26
Formulating
the
Guideline
Consultation Sharing
Knowledges
Entry point
for external team
3. Write the Guideline
• How to SupportingPython3? (@Background)
• How to handle complicated case like “str”?
• How to verify the “result”?
• Test coverage / Local integration test
• Linter (Optional)
• Static type checker (Optional)
• Integration Test (Not always feasible)
• E2E test (Not always feasible)
• What’s the supporting python3 strategy?
(Explain later)
27
4. Investigate Tasks (Q1)
• Get dependency tree by the Entry-point
(Script/Application)
28
Entry-point
Dependencies
4. Investigate Tasks (Q1)
29
🚨 For large scale internal project, there is NO
general solution, caniusepython3 can only help
external package
• We internally developed script to verify that…
30
4. Investigate Tasks (Q2 & Q3)
• Build System
• Assure a reasonable coverage
• Assure unit test passed in both versions
• Deployment System (In production)
• Have site-packages in both versions
• Execute part of the script/service in python3
31
PyCon 2019: Thea Flowers (tox, nox)
5. Estimate Task Size
🚨 It’s hard to measure the task size in general, here
are few matrix we used
• Original code quality & test coverage
• Source lines of code (SLoC)
• Internal dependency but own by other team
• Edge case (Orphaned open source package)
• Build system efforts
• Deployment system efforts
32
6. Migrate Progressively
(Transition Period)
33
Transition Period
Code is ready in python3, but not yet executed in python3
6. Migrate Progressively
(Progress Tracker)
• In the example
• Z Dependency is migrated and run in part of production service
• Y Dependency is migrated but not yet in any production service
• X Application is working in progress.
34
Size Inspected WIP 2/3
Compatible
Unit
Tested
Partially
In Prod
All
In Prod
1
4
5
② Y Dependency
① Z Dependency
③ X Application
Lessons Learned
35
Always be ready to face
Unexpected Chores
• Build System / Deployment System
• The old system only supports up to python34
∵ Python34 is EOL, most packages used old system
∴ Work on build system migration in parallel
∵ The old system never run certain package’s unit test
∴ More bugs…
• The new build system need workaround to execute
linter, type checker in different python version
• Many unexpected package without python3 support
• 3rd party package – orphaned package
• Internal package
36
String
The most difficult part of supporting python3
• Not Ascii-code only
• Follow the community approach is recommended
(100% works)
• Example:
https://github.com/note35/SupportingPython3-notes
• Ascii-code only (Easier)
• str can be accepted except some corner cases
(~100% works)
37
Things can help you
38
Things can help you
• 2 major 3rd party libraries: six and future
• Select 1 of them, and add them to the guideline
• 2 built-in solution: 2to3 and __future__
• 2to3 only provides limited help
• __future__ is a safeguard after supporting python3
• The usage of unicode_literals eventually be dropped
39
Things can help you (cont.)
• Linter
• pylint or flake8 are recommended
• Since you need to touch all legacy packages, it’s more
comfortable to read them in unified syntax
• Auto-linter: autopep8, black, and yapf
• Static Type Checker
• mypy is recommended (pyre-check only support 3.5+)
• Types helps the progress of code review
• By dropbox and our experience
40
Summary
41
If you need to support python3…
• SupportPython3 is difficult and long
• Side benefits…
• Get better understanding of extremely old packages
• Make code with higher quality
• Ready for next “migration” 42
Time
Environment
Complexity
Project Size
If you do NOT need it?
• You know how to estimate the complexity behind
your python project now!
43
44
45

Weitere ähnliche Inhalte

Mehr von Kir Chou

Spime - personal assistant
Spime - personal assistantSpime - personal assistant
Spime - personal assistantKir Chou
 
Ch9 package & port(2013 ncu-nos_nm)
Ch9 package & port(2013 ncu-nos_nm)Ch9 package & port(2013 ncu-nos_nm)
Ch9 package & port(2013 ncu-nos_nm)Kir Chou
 
Ch8 file system management(2013 ncu-nos_nm)
Ch8   file system management(2013 ncu-nos_nm)Ch8   file system management(2013 ncu-nos_nm)
Ch8 file system management(2013 ncu-nos_nm)Kir Chou
 
Ch7 user management(2013 ncu-nos_nm)
Ch7   user management(2013 ncu-nos_nm)Ch7   user management(2013 ncu-nos_nm)
Ch7 user management(2013 ncu-nos_nm)Kir Chou
 
Ch10 firewall(2013 ncu-nos_nm)
Ch10 firewall(2013 ncu-nos_nm)Ch10 firewall(2013 ncu-nos_nm)
Ch10 firewall(2013 ncu-nos_nm)Kir Chou
 
Knowledge Management in Distributed Agile Software Development
Knowledge Management in Distributed Agile Software DevelopmentKnowledge Management in Distributed Agile Software Development
Knowledge Management in Distributed Agile Software DevelopmentKir Chou
 
Sitcon2014 community by server (kir)
Sitcon2014   community by server (kir)Sitcon2014   community by server (kir)
Sitcon2014 community by server (kir)Kir Chou
 
Webapp(2014 ncucc)
Webapp(2014 ncucc)Webapp(2014 ncucc)
Webapp(2014 ncucc)Kir Chou
 
廢除雙二一議題 保留方論點 (2013ncu全幹會)
廢除雙二一議題   保留方論點 (2013ncu全幹會)廢除雙二一議題   保留方論點 (2013ncu全幹會)
廢除雙二一議題 保留方論點 (2013ncu全幹會)Kir Chou
 
Ch6 ssh(2013 ncu-nos_nm)
Ch6   ssh(2013 ncu-nos_nm)Ch6   ssh(2013 ncu-nos_nm)
Ch6 ssh(2013 ncu-nos_nm)Kir Chou
 
Ch5 network basic(2013 ncu-nos_nm)
Ch5   network basic(2013 ncu-nos_nm)Ch5   network basic(2013 ncu-nos_nm)
Ch5 network basic(2013 ncu-nos_nm)Kir Chou
 
Ch4 vi editor(2013 ncu-nos_nm)
Ch4    vi editor(2013 ncu-nos_nm)Ch4    vi editor(2013 ncu-nos_nm)
Ch4 vi editor(2013 ncu-nos_nm)Kir Chou
 
Ch3 basic command(2013 ncu-nos_nm)
Ch3   basic  command(2013 ncu-nos_nm)Ch3   basic  command(2013 ncu-nos_nm)
Ch3 basic command(2013 ncu-nos_nm)Kir Chou
 
Ch2 unix introduction(2013 ncu-nos_nm)
Ch2   unix introduction(2013 ncu-nos_nm)Ch2   unix introduction(2013 ncu-nos_nm)
Ch2 unix introduction(2013 ncu-nos_nm)Kir Chou
 
Ch1.b hardware & hypervisor(2013 ncu-nos_nm)
Ch1.b   hardware & hypervisor(2013 ncu-nos_nm)Ch1.b   hardware & hypervisor(2013 ncu-nos_nm)
Ch1.b hardware & hypervisor(2013 ncu-nos_nm)Kir Chou
 
Ch1 computer hardware(2013 ncu-nos_nm)
Ch1   computer hardware(2013 ncu-nos_nm)Ch1   computer hardware(2013 ncu-nos_nm)
Ch1 computer hardware(2013 ncu-nos_nm)Kir Chou
 

Mehr von Kir Chou (18)

Spime - personal assistant
Spime - personal assistantSpime - personal assistant
Spime - personal assistant
 
Ch9 package & port(2013 ncu-nos_nm)
Ch9 package & port(2013 ncu-nos_nm)Ch9 package & port(2013 ncu-nos_nm)
Ch9 package & port(2013 ncu-nos_nm)
 
Ch8 file system management(2013 ncu-nos_nm)
Ch8   file system management(2013 ncu-nos_nm)Ch8   file system management(2013 ncu-nos_nm)
Ch8 file system management(2013 ncu-nos_nm)
 
Ch7 user management(2013 ncu-nos_nm)
Ch7   user management(2013 ncu-nos_nm)Ch7   user management(2013 ncu-nos_nm)
Ch7 user management(2013 ncu-nos_nm)
 
Ch10 firewall(2013 ncu-nos_nm)
Ch10 firewall(2013 ncu-nos_nm)Ch10 firewall(2013 ncu-nos_nm)
Ch10 firewall(2013 ncu-nos_nm)
 
Knowledge Management in Distributed Agile Software Development
Knowledge Management in Distributed Agile Software DevelopmentKnowledge Management in Distributed Agile Software Development
Knowledge Management in Distributed Agile Software Development
 
Cms part2
Cms part2Cms part2
Cms part2
 
Cms part1
Cms part1Cms part1
Cms part1
 
Sitcon2014 community by server (kir)
Sitcon2014   community by server (kir)Sitcon2014   community by server (kir)
Sitcon2014 community by server (kir)
 
Webapp(2014 ncucc)
Webapp(2014 ncucc)Webapp(2014 ncucc)
Webapp(2014 ncucc)
 
廢除雙二一議題 保留方論點 (2013ncu全幹會)
廢除雙二一議題   保留方論點 (2013ncu全幹會)廢除雙二一議題   保留方論點 (2013ncu全幹會)
廢除雙二一議題 保留方論點 (2013ncu全幹會)
 
Ch6 ssh(2013 ncu-nos_nm)
Ch6   ssh(2013 ncu-nos_nm)Ch6   ssh(2013 ncu-nos_nm)
Ch6 ssh(2013 ncu-nos_nm)
 
Ch5 network basic(2013 ncu-nos_nm)
Ch5   network basic(2013 ncu-nos_nm)Ch5   network basic(2013 ncu-nos_nm)
Ch5 network basic(2013 ncu-nos_nm)
 
Ch4 vi editor(2013 ncu-nos_nm)
Ch4    vi editor(2013 ncu-nos_nm)Ch4    vi editor(2013 ncu-nos_nm)
Ch4 vi editor(2013 ncu-nos_nm)
 
Ch3 basic command(2013 ncu-nos_nm)
Ch3   basic  command(2013 ncu-nos_nm)Ch3   basic  command(2013 ncu-nos_nm)
Ch3 basic command(2013 ncu-nos_nm)
 
Ch2 unix introduction(2013 ncu-nos_nm)
Ch2   unix introduction(2013 ncu-nos_nm)Ch2   unix introduction(2013 ncu-nos_nm)
Ch2 unix introduction(2013 ncu-nos_nm)
 
Ch1.b hardware & hypervisor(2013 ncu-nos_nm)
Ch1.b   hardware & hypervisor(2013 ncu-nos_nm)Ch1.b   hardware & hypervisor(2013 ncu-nos_nm)
Ch1.b hardware & hypervisor(2013 ncu-nos_nm)
 
Ch1 computer hardware(2013 ncu-nos_nm)
Ch1   computer hardware(2013 ncu-nos_nm)Ch1   computer hardware(2013 ncu-nos_nm)
Ch1 computer hardware(2013 ncu-nos_nm)
 

Kürzlich hochgeladen

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Kürzlich hochgeladen (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

SupportingPython3 in Large Scale Project

  • 1. SupportingPython3 in Large Scale Project Kir Chou A9 (Amazon Product Search) 1
  • 3. 3 Outline q Background & Talks q How to support python3? q Execution Plan q Lessons Learned q Things can help you
  • 4. https://pythonclock.org/ Python 2.7 EOL 2020 Jan 1st 4 Background Python2only = Technical Debt
  • 5. Talks: Why Python3? • Guido van Rossum (PyCascades 2018) BDFL Python 3 retrospective • Victor Stinner (PyCon 2018) Python 3: ten years later 5
  • 6. Talks: How to make code Python2/3 compatible? • Ned Batchelder (PyCon2012) Pragmatic Unicode Difference of String in python 2 and 3 • Brett Cannon (PyCon2015) author of SupportingPython3 How to make your code Python 2/3 compatible Strategy to support python3 6
  • 7. Talks: Learn from others • Jason Fried (PyCon2018) Fighting the Good Fight: Python 3 in your organization Facebook 5 years journey from python2 to 3 • Max Bélanger and Damien DeVille How we rolled out one of the largest Python 3 migrations ever Dropbox journey since 2015 7
  • 8. How to support python3? 8
  • 12. 12 Python2 Code Python3 Code Python2/3 Code Python2.x Python3.y Supporting python3 in ideal world – (3) Result 3. Stop executing code by python2 interpreter
  • 13. 13
  • 14. 真・How to support python3? 14
  • 15. Large Scale • Packages number: 3 digits • 10+ years old packages • Complicated relationship between packages • Source line of code: Million level • Number of production environment: 2 digits • Build system for python: >1 • Deployment system: >1 15
  • 16. 16 Large Scale Project @ Real World Python Code PythonX.Y Result Q1. How to find your python code? Q2. What interpreter do your system support? Q3. What’s the intention of the result?
  • 17. Python Code Q1. How to find your python code? 17 Python Package Non-Python Package Inline Command Company Internal Dependencies External Dependencies
  • 18. Q2. What interpreter do your system support? • Supported python interpreter? • Default version of the system • Virtualenv • Dockerfile • … • Used python interpreter? • By interpreter (pythonX.Y xxx.py) • By shebang (#!/usr/bin/env python) • By build system to wrap the script • … 18
  • 19. Q3. What’s the intention of the result? 19 Python Code PythonX.Y Result unit tests site-packages script application Test Runner Build System Deployment System / … Deployment System integration tests Test Server’s Deployment System
  • 21. 21 1. Prepare POC 2. Build a Team 3. Write Guideline 5. Estimate Task Size 6. Migrate Progressively 4. Investigate Tasks
  • 22. 1. Prepare PoC Example @ my github 1. Find a tiny migratable package 2. Learn the approach to support python3 3. Prove of concept to support python3 4. Broadcast the idea to other knowledgeable people and human resource allocator 22
  • 23. 23 Do you need a team for Supporting Python3?
  • 27. 3. Write the Guideline • How to SupportingPython3? (@Background) • How to handle complicated case like “str”? • How to verify the “result”? • Test coverage / Local integration test • Linter (Optional) • Static type checker (Optional) • Integration Test (Not always feasible) • E2E test (Not always feasible) • What’s the supporting python3 strategy? (Explain later) 27
  • 28. 4. Investigate Tasks (Q1) • Get dependency tree by the Entry-point (Script/Application) 28 Entry-point Dependencies
  • 29. 4. Investigate Tasks (Q1) 29 🚨 For large scale internal project, there is NO general solution, caniusepython3 can only help external package • We internally developed script to verify that…
  • 30. 30
  • 31. 4. Investigate Tasks (Q2 & Q3) • Build System • Assure a reasonable coverage • Assure unit test passed in both versions • Deployment System (In production) • Have site-packages in both versions • Execute part of the script/service in python3 31 PyCon 2019: Thea Flowers (tox, nox)
  • 32. 5. Estimate Task Size 🚨 It’s hard to measure the task size in general, here are few matrix we used • Original code quality & test coverage • Source lines of code (SLoC) • Internal dependency but own by other team • Edge case (Orphaned open source package) • Build system efforts • Deployment system efforts 32
  • 33. 6. Migrate Progressively (Transition Period) 33 Transition Period Code is ready in python3, but not yet executed in python3
  • 34. 6. Migrate Progressively (Progress Tracker) • In the example • Z Dependency is migrated and run in part of production service • Y Dependency is migrated but not yet in any production service • X Application is working in progress. 34 Size Inspected WIP 2/3 Compatible Unit Tested Partially In Prod All In Prod 1 4 5 ② Y Dependency ① Z Dependency ③ X Application
  • 36. Always be ready to face Unexpected Chores • Build System / Deployment System • The old system only supports up to python34 ∵ Python34 is EOL, most packages used old system ∴ Work on build system migration in parallel ∵ The old system never run certain package’s unit test ∴ More bugs… • The new build system need workaround to execute linter, type checker in different python version • Many unexpected package without python3 support • 3rd party package – orphaned package • Internal package 36
  • 37. String The most difficult part of supporting python3 • Not Ascii-code only • Follow the community approach is recommended (100% works) • Example: https://github.com/note35/SupportingPython3-notes • Ascii-code only (Easier) • str can be accepted except some corner cases (~100% works) 37
  • 38. Things can help you 38
  • 39. Things can help you • 2 major 3rd party libraries: six and future • Select 1 of them, and add them to the guideline • 2 built-in solution: 2to3 and __future__ • 2to3 only provides limited help • __future__ is a safeguard after supporting python3 • The usage of unicode_literals eventually be dropped 39
  • 40. Things can help you (cont.) • Linter • pylint or flake8 are recommended • Since you need to touch all legacy packages, it’s more comfortable to read them in unified syntax • Auto-linter: autopep8, black, and yapf • Static Type Checker • mypy is recommended (pyre-check only support 3.5+) • Types helps the progress of code review • By dropbox and our experience 40
  • 42. If you need to support python3… • SupportPython3 is difficult and long • Side benefits… • Get better understanding of extremely old packages • Make code with higher quality • Ready for next “migration” 42 Time Environment Complexity Project Size
  • 43. If you do NOT need it? • You know how to estimate the complexity behind your python project now! 43
  • 44. 44
  • 45. 45