Pie Meets Py / PyCon JP 2019

6fa3836d10d691125749472297cf516a?s=47 7pairs
September 16, 2019

Pie Meets Py / PyCon JP 2019

6fa3836d10d691125749472297cf516a?s=128

7pairs

September 16, 2019
Tweet

Transcript

  1. Pie Meets Py - PythonͰAndroidΞϓϦΛͭ͘Ζ͏ 2019-09-16 (PyCon JP 2019) ௕୩৔

    ५໵
  2. ࣗݾ঺հ • ௕୩৔ ५໵ (͸ͤ͹ ͡ΎΜ΍) • ֤छSNSͰ͸ 7pairs Ͱ׆ಈத

    • ޷͖ͳେࡕۅӂ͸தଜ߶໵ " / ޷͖ͳ෋࢜େֶ͸֎࡚मଡ # • ͓࢓ࣄͰ͸Android (Java / Kotlin) / iOS (Objective-C / Swift) ͕த৺ • ͋·ΓҰൠతͱ͸ݴ͑ͳ͍Pythonͷ࢖͍ํΛ໛ࡧ͢Δͷ͕େ޷͖ • PyCon JP 2018Ͱ͸Transcryptʹ͍ͭͯൃද • https://speakerdeck.com/7pairs
  3. ஶॻ Chalice, Transcrypt, pytest, SeleneΛར༻ͯ͠
 αʔόʔϨεΞϓϦΛ࣮૷ɾςετ͢ΔຊͰ͢ AmazonଞͰઈࢍൢചதʂ

  4. ͜ͷηογϣϯͰ࿩͢͜ͱ • PythonʹΑΔAndroidΞϓϦͷ։ൃ؀ڥ • ֤։ൃ؀ڥͷ௕ॴɾ୹ॴ • ։ൃ؀ڥͷબͼํ

  5. ͜ͷηογϣϯͰ࿩͞ͳ͍͜ͱ • ֤։ൃ؀ڥͰͷৄࡉͳ࣮૷ํ๏ • ֤։ൃ؀ڥͰͷςετํ๏

  6. ͜ͷηογϣϯͷΰʔϧ • AndroidΞϓϦ։ൃʹڵຯΛ͍࣋ͬͯͨͩ͘ • Pythonͷଟ༷ͳՄೳੑΛ஌͍ͬͯͨͩ͘ • ύʔςΟͰࢲ͕΅ͬͪʹͳΒͳ͍

  7. ͳͥ “Pie Meets Py” ʁ

  8. PieͱPyͷൃԻ (ถࠃӳޠ) • Pieʲpάɪʳ • Pythonʲpάɪθɑnʳ

  9. Pieͱ͸ʁ • Android 9.0ͷίʔυωʔϜ • Android 1.5 (3൪໨ͷόʔδϣϯ) Ҏ߱ 


    ֤όʔδϣϯʹ͸ΞϧϑΝϕοτॱʹ 
 ͓՛ࢠͷίʔυωʔϜ͕͚ͭΒΕ͍ͯΔ
  10. Android 1.5 Cupcake

  11. Android 1.6 Donut

  12. Android 2.0 Eclair

  13. Android 2.2 Froyo

  14. Android 2.3 Gingerbread

  15. Android 3.0 - 3.2 Honeycomb

  16. Android 4.0 Ice Cream Sandwich

  17. Android 4.1 - 4.3 Jelly Bean

  18. Android 4.4 Kitkat

  19. Android 5.0 - 5.1 Lollipop

  20. Android 6.0 Marshmallow

  21. Android 7.0 - 7.1 Nougat

  22. Android 8.0 - 8.1 Oreo

  23. Android 9.0 Pie

  24. Android 10 • 2019೥9݄3೔ϦϦʔε • PixelγϦʔζ͔Βॱ࣍഑৴ • ͓՛ࢠͷίʔυωʔϜ͕ഇࢭ $ •

    ੈքதͷ͢΂ͯͷϢʔβʔ͕ 
 ಉ͡Α͏ʹೝࣝͰ͖Δ໊લͰ͸ͳ͍ͨΊ
  25. ͳͥPythonͰAndroid։ൃʁ

  26. 2018೥य़ͷϫΠক

  27. ڝ߹ͦ͠͏ͳྖҬ • WebΞϓϦͷόοΫΤϯυ • ΫϩʔϦϯάʗεΫϨΠϐϯά • σʔλ෼ੳɾՄࢹԽ • ࣗવݴޠॲཧ

  28. ͤ΍ʂAltJSͰCfPग़ͨ͠Ζʂ

  29. PyCon JPʹAltJSͷηογϣϯ͕ര஀

  30. 2019೥य़ͷϫΠক

  31. ڝ߹ͦ͠͏ͳྖҬ • WebΞϓϦͷόοΫΤϯυ • (ࣗಈ) ςετ • σʔλ෼ੳɾՄࢹԽ • ࣗવݴޠॲཧ

  32. ͤ΍ʂAndroidͰCfPग़ͨ͠Ζʂ

  33. PyCon JPʹAndroidͷηογϣϯ͕ര஀

  34. PyCon mini HiroshimaͰ΋ൃද͠·͢

  35. Why did you want to develop
 Android apps in Python

    ?
  36. Because it's there.

  37. ։ൃ؀ڥ

  38. બఆͷ৚݅ • ࣮૷ݴޠ͕PythonͰ͋Δ • ࣮༻ʹ଱͑Δ଎౓Ͱಈ࡞͢Δ • Google Play StoreʹϦϦʔεͰ͖Δ

  39. ͝঺հ͢Δ։ൃ؀ڥ • React Native + Transcrypt • Kivy • Chaquopy

  40. React Native + Transcrypt

  41. React Native • Facebook͕։ൃ͍ͯ͠ΔΦʔϓϯιʔεͷ 
 ϞόΠϧΞϓϦέʔγϣϯϑϨʔϜϫʔΫ • جຊతʹReactͱಉ༷ͷݪཧͰಈ࡞͢Δ͕ 
 ඳը͸֤OSͷωΠςΟϒAPIΛར༻͢Δ

    • ࣮૷ʹ͸JavaScriptΛར༻͢Δ • Android / iOS / UWPʹରԠ
  42. Transcrypt • PythonΛJavaScriptʹม׵͢ΔAltJS • ެࣜαΠτᐌ͘ “subset of Python” Ͱ͋Γ 


    ͢΂ͯͷػೳΛαϙʔτ͍ͯ͠ΔΘ͚Ͱ͸ͳ͍ • Ұ෦ͷඪ४ϥΠϒϥϦ͕ར༻Ͱ͖ͳ͍ͳͲ • JavaScriptͷॲཧΛγʔϜϨεʹݺͼग़ͤΔ • JavaScriptͷ֎෦ύοέʔδ΋ར༻Մೳ
  43. AltJSͱͯ͠ͷPython • PyCon JP 2018ʹͯ 
 Transcryptʹ͍ͭͯൃද͠·ͨ͠ • https://www.youtube.com/watch?v=zGqUysiC1xA&t •

    https://speakerdeck.com/7pairs/pycon-jp-2018
  44. React Native + Transcrypt • React Native͸ϓϩάϥϜΛ 
 JavaScriptͰ࣮૷͢Δ •

    Transcrypt͸PythonΛJavaScriptʹม׵͢Δ • ૊Έ߹ΘͤΕ͹PythonͰReact Nativeͷ 
 ϓϩάϥϜ͕ॻ͚ΔͷͰ͸ʁ
  45. ݕূ݁Ռ • ΤϯτϦϙΠϯτ (App.js) Λআ͍ͯ 
 ͢΂ͯPythonͰ࣮૷͕Ͱ͖·ͨ͠ʂ %

  46. Positive ! • ιʔεͷߋ৽Λ؂ࢹͯ͠τϥϯεύΠϧ͢Ε͹ 
 Fast RefreshͷԸܙʹ͔͋ͣΕΔ • ܕώϯτΛ͚ͭΔ͜ͱͰ
 τϥϯεύΠϧ࣌ʹܕνΣοΫ͕Մೳ

  47. TypeScriptͰे෼ͳͷͰ͸ &

  48. TranscryptͷܕνΣοΫ def concat(a: str, b: str) -> str: return f"{a}-{b}"

    # 33-4 concat("33", "4") # error: Argument 2 to "concat" has # incompatible type "int"; expected "str" concat("33", 4)
  49. Negative $ • Pythonͷlambdaࣜͷ੍ݶʹਏΈ͕͋Δ • ͋Δఔ౓ͷن໛ͷॲཧΛॻ͖͍ͨέʔε͕ଟ͍ • JSXͷѻ͍ʹਏΈ͕͋Δ • ֎෦ͷJSXίϯύΠϥΛݺͼग़ͯ͠

    
 ͦͷ݁ՌΛຒΊࠐΉͳͲͷখࡉ޻͕ඞཁ
  50. Kivy

  51. Kivy • Φʔϓϯιʔεͷ 
 ϚϧνλονΞϓϦέʔγϣϯϑϨʔϜϫʔΫ • OpenGL ES 2.0ͱޓ׵ੑͷ͋Δ 


    άϥϑΟοΫඳըϥΠϒϥϦ • தؒݴޠKVͰͷը໘ɾ΢ΟδΣοτͷఆٛ • Android / iOS / Linux / Mac / WindowsʹରԠ
  52. KivyʹΑΔΞϓϦέʔγϣϯ։ൃͷ͢͢Ί • PyCon JP 2017ͰͷJun Okazaki͞Μͷൃද • https://www.youtube.com/watch?v=iVOVpIXzbYY • https://www.slideshare.net/JunOkazaki1/pyconjp2017-kivy

  53. KivyʹΑΔHello world from kivy.app import App from kivy.uix.button import Button

    class TestApp(App): def build(self): return Button(text='Hello World') TestApp().run()
  54. Buildozer • KivyΞϓϦͷAndroid / iOS޲͚ͷύοέʔδϟʔ • Android޲͚ͷύοέʔδϯάͷࡍʹ͸ 
 Buildozer಺෦Ͱpython-for-androidΛར༻ •

    Ұ෦ͷPythonύοέʔδͷΠϯετʔϧʹ΋ରԠ • ඇରԠͷύοέʔδΛΠϯετʔϧ͢Δʹ͸ 
 recipeΛࣗྗͰ࡞੒͢Δඞཁ͕͋Δ
  55. Plyer • OS΍୺຤ݻ༗ͷػೳΛ 
 Python͔Βར༻͢ΔͨΊͷAPI܈ • ৼಈ / Χϝϥ /

    GPS ... • ରԠ͍ͯ͠ͳ͍ϓϥοτϑΥʔϜͰ͸ 
 NotImplementedErrorΛraise͢Δ
  56. Plyerͷαϯϓϧ from plyer import vibrator vibrator.vibrate(10)

  57. Pyjnius • Python͔ΒJavaͷΫϥεʹ 
 ΞΫηε͢ΔͨΊͷϞδϡʔϧ • Plyer΋಺෦ͰPyjniusΛར༻͍ͯ͠Δ

  58. Pyjniusͷαϯϓϧ from jnius import autoclass Context = autoclass('android.content.Context') PythonActivity =

    autoclass('org.kivy.android.PythonActivity') activity = PythonActivity.mActivity vibrator = activity.getSystemService(Context.VIBRATOR_SERVICE) vibrator.vibrate(10000)
  59. Positive ! • ϑϨʔϜϫʔΫͷઃܭࢥ૝ͱͯ͠ 
 Ϛϧνλον͕ߟྀ͞Ε͍ͯΔ • OS͝ͱͷ෼ذ͕සग़͢Δ 
 ͳΜͪΌͬͯϚϧνϓϥοτϑΥʔϜͰ͸ͳ͍

    
 • ։ൃ͕׆ൃʹߦΘΕ͍ͯͯ҆৺ײ͕͋Δ
  60. Negative $ • Flutter΍Jetpack Compose͕ଘࡏ͢Δ 
 ྩ࿨ͷ࣌୅ʹ͓͍ͯ͸ 
 UIͷͨΊʹผͷݴޠ͕ඞཁʹͳΔͷ͸ඍົ •

    ଞϑϨʔϜϫʔΫͱൺ΂Δͱ 
 ͢΂ͯʹ͓͍ͯϫϯςϯϙಈ࡞͕஗͍
  61. Chaquopy

  62. Chaquopy • ެࣜαΠτᐌ͘ “Python SDK for Android” • build.gradleʹهड़Λ௥Ճͯ͠ಋೖ •

    Java / Kotlinͷ୅ΘΓʹ 
 PythonͰ࣮૷͢ΔΠϝʔδ (ࠞࡏ΋Մೳ)
  63. ChaquopyͰͷHello world from android.os import Bundle from android.support.v7.app import AppCompatActivity

    from java import jvoid, Override, static_proxy class MainActivity(static_proxy(AppCompatActivity)): @Override(jvoid, [Bundle]) def onCreate(self, state): AppCompatActivity.onCreate(self, state) self.setContentView(R.layout.activity_main)
  64. ࠓԶ͕ॻ͍͍ͯΔͷ͸Java͚ͩͬʁ &

  65. static_proxy • JavaͷclassΛҾ਺ͱͯ͠౉͠ 
 JavaͷιʔείʔυΛੜ੒͢Δ • Activity͸͜ͷϝιουͷ໭Γ஋Λܧঝ͢Δ • XMLͳͲίʔυҎ֎͔Β΋ࢀর͞ΕΔͨΊ 


    ͍ͬͨΜJavaʹ͢Δඞཁ͕͋ΔͱࢥΘΕΔ
  66. static_proxyͷαϯϓϧ # <略> class MainActivity(static_proxy(AppCompatActivity)): # <略>

  67. dynamic_proxy • JavaͷinterfaceΛҾ਺ͱͯ͠౉͠ 
 ࣮ߦ࣌ʹಈతʹJavaͷΫϥεΛੜ੒͢Δ • ಺෦Ͱ͸java.lang.reflect.ProxyΛར༻͍ͯ͠Δ • AndroidͰ͸interfaceΛଟ༻͢ΔͨΊ 


    ඇৗʹॏཁʹͳΔؔ਺
  68. dynamic_proxyͷαϯϓϧ # <略> @Override(jvoid, [Bundle]) def onCreate(self, state): AppCompatActivity.onCreate(self, state)

    self.setContentView(R.layout.activity_main) class Listener(dynamic_proxy(View.OnClickListener)): def onClick(self, view): # クリック時の処理 self.findViewById(R.id.button).setOnClickListener(Listener())
  69. Pythonύοέʔδͷಋೖ • ΞϓϦϨϕϧͷbuild.gradle಺ʹಋೖ͢ΔύοέʔδΛྻڍ͢Δ • ެࣜαΠτᐌ͘PyPIͷ্Ґ1000ύοέʔδத 
 88%͸ΠϯετʔϧՄೳ • ChaquopyͷαʔόʔͰҰ෦ύοέʔδͷwheelϑΝΠϧΛఏڙ •

    طଘͷAndroid޲͚ύοέʔδͰ͸࣮ݱෆՄೳͳػೳΛ 
 ఏڙ͢Δํ޲ʹৼΓ੾͍ͬͯΔҹ৅ (ݸਓͷײ૝Ͱ͢)
  70. Android্Ͱಈ͘pandas from android.os import Bundle from android.support.v7.app import AppCompatActivity from

    java import jvoid, Override, static_proxy import pandas as pd class MainActivity(static_proxy(AppCompatActivity)): @Override(jvoid, [Bundle]) def onCreate(self, state): AppCompatActivity.onCreate(self, state) self.setContentView(R.layout.activity_main) url = "http://npb.jp/bis/players/81085115.html" df = pd.read_html(url)[1].query('年度 == 年度') Log.d("PyConJP", str(df['本塁打'].sum()))
  71. ϥΠηϯεྉۚ • ΦʔϓϯιʔεͰͷར༻͸ແྉ • ΫϩʔζυιʔεͰͷར༻͸ 
 ։ൃऀ਺ʹԠͨ͡ϥΠηϯεܖ໿͕ඞཁ • 1ΞϓϦͷΈ༗ޮͳϥΠηϯε $39/ਓ

    • ΞϓϦ਺ແ੍ݶͷϥΠηϯε $79/ਓ
  72. Positive ! • ಋೖ͕༰қ • Java / Pythonͷύοέʔδͱ࿈ܞ͕Մೳ • Java

    / KotlinʹΑΔΞϓϦ։ൃͷ஌ݟΛ 
 ΄΅ͦͷ··׆͔͢͜ͱ͕Ͱ͖Δ
  73. Negative $ • ແྉͰ͸ͳ͍ • ϓϩΩγΛ௨ͨ͠Ϋϥεͷิ׬ʹਏΈ͕͋Δ • ·ΔͰJava΍KotlinΛॻ͍͍ͯΔؾ෼ʹͳΔ

  74. ͓·͚

  75. ੯͘͠΋બ֎ • BeeWare • PySide for Android

  76. BeeWare • PythonʹΑΔΫϩεϓϥοτϑΥʔϜ։ൃ؀ڥ • Mac / Windows / Linux /

    iPhone / iPad / Android 
 AppleTV / tvOSʹରԠ • Android͸VOCͱͷ࿈ܞͰಈ࡞͢Δ • PythonόΠτίʔυΛJavaόΠτίʔυʹม׵
  77. BeeWareબ֎ͷཧ༝ • Android Studio 3ܥͰಈ࡞͠ͳ͍ • Apple੡඼༏ઌͷํ਑Λެݴ͓ͯ͠Γ 
 ରԠ͞ΕΔ·Ͱ͕͔͔࣌ؒΓͦ͏

  78. PySide for Android • PySide (QtͷPythonόΠϯσΟϯά) ʹΑΔ 
 AndroidΞϓϦ։ൃ؀ڥ •

    Qtͱ͍͏࣮੷ͷ͋ΔGUIϥΠϒϥϦΛ 
 AndroidͰར༻͢Δ͜ͱ͕Ͱ͖Δ
  79. PySide for Androidબ֎ͷཧ༝ • Android্Ͱಈ͔ͤ·ͤΜͰͨ͠…… • ΋͠஌ݟΛ͓࣋ͪͷํ͕͍Βͬ͠ΌͬͨΒ 
 ΞυόΠεΛ͍͚ͨͩΔͱ޾͍Ͱ͢

  80. ·ͱΊ

  81. React Native + Transcrypt • ࣮੷ͷ͋ΔReact Nativeʹ৐͔ͬΔ͜ͱ͕Ͱ͖Δ • React NativeΛૉͷJavaScriptͰ

    
 ॻ͍͍ͯΔͷͰ͋Ε͹࠾༻ͯ͠΋ྑ͍͔΋ • ࢒೦ͳ͕ΒTypeScript౳ͷ༗ྗͳAltJSΛ 
 ஔ͖׵͑Δ΄ͲͷΠϯύΫτ͸……
  82. Kivy • ଞݴޠʹҾ͖ͣΒΕΔ͜ͱͷͳ͍ 
 PythonicͳAndroid։ൃ͕Ͱ͖Δ • ։ൃ͕׆ൃͰࠓޙʹظ଴͕࣋ͯΔ • Androidʹؔͯ͠͸ 


    ୺຤ͷεϖοΫ͕௥͍͍͍ͭͯͳ͍͔΋
  83. Chaquopy • ࣮༻ੑͰ͸τοϓΫϥε • طଘͷAndroid։ൃͷ஌ࣝΛ 
 ͦͷ··׆͔ͤΔͷ͸େ͖͍ • ϥΠηϯεྉ͕ۚ໰୊ʹͳΒͳ͚Ε͹ 


    ༗ྗͳબ୒ࢶʹͳΔ͸ͣ
  84. ࠷ޙʹ • ʮPythonͰAndroidΞϓϦ։ൃ͸ݫ͍͠ʯ 
 ͱ͍͏݁࿦ʹ͢Δͭ΋ΓͰCfPΛఏग़͕ͨ͠ 
 ͍͍ҙຯͰཪ੾ΒΕͨ • Android Studio͸αΠζ͕େ͖͍ͷͰ

    
 ձ৔ͷWi-FiͰ͸μ΢ϯϩʔυ͠ͳ͍ͰͶʂ
  85. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠