Autodoc

 Autodoc

Py-Autodoc

D34086a19899706bc3abeb8a2c7eecf7?s=128

heavenshell

March 13, 2014
Tweet

Transcript

  1. Autodoc ʹ͍ͭͯ େࡕ Python Ϣʔβͷू·Γ 2014/03 2014.03.13 @heavenshell 14೥3݄14೔༵ۚ೔

  2. ͓·͑ɺ୭Α Software engineer, Programmer py-qiita, py-jokk, vim-pydocstring, vim-jsdoc, vim- connpass,

    etc — Python, Vim, Vimperator PHP, Perl, Java, JavaScript ޷͖ͳ Python ͷඪ४ؔ਺͸ print() ͱ dir() 14೥3݄14೔༵ۚ೔
  3. My contribution 14೥3݄14೔༵ۚ೔

  4. My contribution 14೥3݄14೔༵ۚ೔

  5. My contribution 14೥3݄14೔༵ۚ೔

  6. My contribution 14೥3݄14೔༵ۚ೔

  7. My best pull request @2013 14೥3݄14೔༵ۚ೔

  8. 14೥3݄14೔༵ۚ೔

  9. 14೥3݄14೔༵ۚ೔

  10. 14೥3݄14೔༵ۚ೔

  11. orz 14೥3݄14೔༵ۚ೔

  12. Autodoc 14೥3݄14೔༵ۚ೔

  13. 14೥3݄14೔༵ۚ೔

  14. ࠓճ͸ Sphinx ͷAutodoc ͞Μ Ͱ͸ͳ͘ผͷ Autodoc ͞Μ 14೥3݄14೔༵ۚ೔

  15. 14೥3݄14೔༵ۚ೔

  16. 14೥3݄14೔༵ۚ೔

  17. 3BDLBQQMJDBUJPOͰ࣮૷͞Εͨ"1*ʹରͯ͠ɺ 34QFDͰॻ͔ΕͨςετΛݩʹ"1*υΩϡϝϯτΛੜ ੒͢Δ΋ͷɻςετΛ࣮ߦ͢Δͱɺςετதʹൃߦ ͨ͠ϦΫΤετ΍Ϩεϙϯεɺͦͷςετʹ෇͚ΒΕ ͨϝοηʔδΛݩʹɺྑ͍ײ͡ʹ৘ใΛ·ͱΊɺ .BSLEPXOܗࣜͰ"1*υΩϡϝϯτΛهͨ͠ϑΝΠϧ Λੜ੒ͯ͘͠ΕΔɻྫ͑͹(JU)VCͰ͸.BSLEPXOϑ ΝΠϧΛద౰ʹඳըͯ͘͠ΕΔͷͰɺԼਤͷΑ͏ʹ (JU)VC্Ͱ؆୯ʹυΩϡϝϯτΛӾཡग़དྷΔΑ͏ʹ ͳΔɻ

    http://r7kamura.github.io/2013/12/01/autodoc.html 14೥3݄14೔༵ۚ೔
  18. ࠓ๺࢈ۀ RSpec Ͱ API αʔόʹରͯ͠ςετΛॻ͘ ϦΫΤετͱϨεϙϯεͷ಺༰Λ Markdown Ͱग़ྗ ςετ͔ΒυΩϡϝϯτੜ੒ͯ͘͠Εͯศར 14೥3݄14೔༵ۚ೔

  19. ࣗಈతʹυΩϡϝϯτΛੜ੒Ͱ͖Δͷ͸ૉ੖Β͍͠ ςετΛ࣮ߦ͢ΔͱυΩϡϝϯτ͕ੜ੒͞ΕΔͷ͸ϝϯ ςφϯείετ͕௿͍ ࣮ࡏ͢Δ API ʹର࣮ͯ͠ߦ͢ΔͷͰɺੜ͖ͨυΩϡϝ ϯτ υΩϡϝϯτΛࣗಈੜ੒͞ΕΔϝϦοτ͸ Python Ϣʔβ

    ʔ͸ྑ͘஌ͬͯΔ 14೥3݄14೔༵ۚ೔
  20. ଞݴޠʹΑΔ࣮૷ 14೥3݄14೔༵ۚ೔

  21. Test::JsonAPI::Autodoc http://moznion.hatenadiary.com/entry/ 2013/11/02/232144 14೥3݄14೔༵ۚ೔

  22. ॻ͖ํ͸ͪΐͬͱҟͳΔ͚ Ͳςετ͔ΒυΩϡϝϯτ Λग़ྗ͢Δͷ͸ಉ͡ 14೥3݄14೔༵ۚ೔

  23. Py-Autodoc http://github.com/heavenshell/py-autodoc 14೥3݄14೔༵ۚ೔

  24. ରԠͯ͠ΔςετFW Unittest py.test nose ֬ೝͯ͠ͳ͍͚Ͳଟ෼ಈ͘ 14೥3݄14೔༵ۚ೔

  25. from unittest import TestCase from webtest import TestApp from autodoc

    import autodoc from tests.app import create_app class TestUnittest(TestCase): def setUp(self): app = create_app self.client = TestApp(app) @classmethod @autodoc.generate('var/test_unittest.rst') def tearDownClass(cls): pass @autodoc.describe('POST /foo/bar') def test_foo_bar(self): """ POST /foo/bar """ param = {'id': 1, 'message': 'foo'} res = self.client.post_json('/foo/bar', params=param) self.assertEqual(res.status_code, 200) return res 14೥3݄14೔༵ۚ೔
  26. from unittest import TestCase from webtest import TestApp from autodoc

    import autodoc from tests.app import create_app class TestUnittest(TestCase): def setUp(self): app = create_app self.client = TestApp(app) @classmethod @autodoc.generate('var/test_unittest.rst') def tearDownClass(cls): pass @autodoc.describe('POST /foo/bar') def test_foo_bar(self): """ POST /foo/bar """ param = {'id': 1, 'message': 'foo'} res = self.client.post_json('/foo/bar', params=param) self.assertEqual(res.status_code, 200) return res 14೥3݄14೔༵ۚ೔
  27. from unittest import TestCase from webtest import TestApp from autodoc

    import autodoc from tests.app import create_app class TestUnittest(TestCase): def setUp(self): app = create_app self.client = TestApp(app) @classmethod @autodoc.generate('var/test_unittest.rst') def tearDownClass(cls): pass @autodoc.describe('POST /foo/bar') def test_foo_bar(self): """ POST /foo/bar """ param = {'id': 1, 'message': 'foo'} res = self.client.post_json('/foo/bar', params=param) self.assertEqual(res.status_code, 200) return res 14೥3݄14೔༵ۚ೔
  28. from unittest import TestCase from webtest import TestApp from autodoc

    import autodoc from tests.app import create_app class TestUnittest(TestCase): def setUp(self): app = create_app self.client = TestApp(app) @classmethod @autodoc.generate('var/test_unittest.rst') def tearDownClass(cls): pass @autodoc.describe('POST /foo/bar') def test_foo_bar(self): """ POST /foo/bar """ param = {'id': 1, 'message': 'foo'} res = self.client.post_json('/foo/bar', params=param) self.assertEqual(res.status_code, 200) return res 14೥3݄14೔༵ۚ೔
  29. 14೥3݄14೔༵ۚ೔

  30. import sys import pytest from webtest import TestApp from autodoc

    import autodoc @autodoc.generate('var/test_pytest.md', template='templates/markdown.md') def teardown_module(module): pass @autodoc.describe('GET /') def test_index(): app = TestApp(create_app) res = app.get('/') assert res.status_code == 200 return res 14೥3݄14೔༵ۚ೔
  31. import sys import pytest from webtest import TestApp from autodoc

    import autodoc @autodoc.generate('var/test_pytest.md', template='templates/markdown.md') def teardown_module(module): pass @autodoc.describe('GET /') def test_index(): app = TestApp(create_app) res = app.get('/') assert res.status_code == 200 return res 14೥3݄14೔༵ۚ೔
  32. import sys import pytest from webtest import TestApp from autodoc

    import autodoc @autodoc.generate('var/test_pytest.md', template='templates/markdown.md') def teardown_module(module): pass @autodoc.describe('GET /') def test_index(): app = TestApp(create_app) res = app.get('/') assert res.status_code == 200 return res 14೥3݄14೔༵ۚ೔
  33. import sys import pytest from webtest import TestApp from autodoc

    import autodoc @autodoc.generate('var/test_pytest.md', template='templates/markdown.md') def teardown_module(module): pass @autodoc.describe('GET /') def test_index(): app = TestApp(create_app) res = app.get('/') assert res.status_code == 200 return res 14೥3݄14೔༵ۚ೔
  34. 14೥3݄14೔༵ۚ೔

  35. ςετΫϥΠΞϯτʹ WebTest Λ࢖༻ͯ͠Δ @autodoc.describe ͰυΩϡϝϯτΛग़ྗ͢Δϝιο υ/ؔ਺Λఆٛ͢Δ @autodoc.generete ͰσίϨʔτͨ͠ϝιου/ؔ਺ ͕࣮ߦ͞ΕͨλΠϛϯάͰυΩϡϝϯτΛग़ྗ 14೥3݄14೔༵ۚ೔

  36. υΩϡϝϯτΛੜ੒͢ΔλΠϛϯά͸ςετϝιο υ/ؔ਺͝ͱʹ͢Ε͹ɺϝιου/ؔ਺୯ҐͰυΩϡϝ ϯτΛग़ྗͰ͖Δ tearDownClass Έ͍ͨͷ৔߹ɺ࣮ߦͨ͠શͯͷϝιο υΛ 1 ϑΝΠϧʹग़ྗ͢Δ ໪࿦ reStracturedText

    ʹରԠ͍ͯ͠Δ 14೥3݄14೔༵ۚ೔
  37. ςϯϓϨʔτ͸ࣗ෼Ͱ࡞੒Մೳ ͨͩ͠String.template Λ࢖ͬͯΔͨΊࣗ༝౓͕௿͍ Ruby ͸ඪ४Ͱ ERB Λ࣋ͬͯΔͷ͕ત·͍͠ Python ΋ϏϧτΠϯͰ΋͏গ͠ߴػೳͳςϯϓϨ ʔτΤϯδϯཉ͍͠

    14೥3݄14೔༵ۚ೔
  38. ࣮૷͸γϯϓϧ(ʹͨͭ͠΋Γ) @autodoc.describe Ͱ return ͨ͠ response ΦϒδΣ ΫτΛύʔεͯ͠Ϧετʹ֨ೲ @autodoc.generate ͕࣮ߦͨ͠ΒϦετͷதΛϑΝΠ

    ϧʹग़ྗ 14೥3݄14೔༵ۚ೔
  39. ੍໿ ඞͣςετϝιου/ؔ਺Ͱ WebTest ͷϨεϙϯεΛ Ԡ౴͢Δඞཁ͋Γ Ruby ͷ autodoc ͸ Rack-Test

    Λ࢖͏ͱ last_response ͔ΒϨεϙϯεΛऔಘͯ͠Δ͚ͲɺWebTest ʹͦΜͳ ͷ͸ແ͍ͷͰ return ͯ͠ड͚औΔ࢓༷ Flask(ͱ͍͏͔Werkzueg)ͷςετΫϥΠΞϯτ΋ର Ԡ͠Α͏͔ͱࢥ͚ͬͨͲɺResponse ʹ Request Φϒ δΣΫτ͕֨ೲ͞Εͯͳ͍ͷͰμϝͩͬͨ 14೥3݄14೔༵ۚ೔
  40. ·ͱΊ Autodoc ࡞ͬͨ ςετΛ࣮ߦ͢ΔͱυΩϡϝϯτΛੜ੒ͯ͘͠ΕΔͷ ͸ศར σίϨʔλͬͯศར Web API ΛԠ౴͢ΔϞοΫαʔόͱ૊Έ߹ΘͤΕ͹ υΩϡϝϯτΛઌʹ࡞Δࣄ΋Մೳ

    ͜Ε͸͍͔ͭ·ͨ࿩͍ͨ͠ 14೥3݄14೔༵ۚ೔
  41. Thank you! Any Questions? 14೥3݄14೔༵ۚ೔