Upgrade to Pro — share decks privately, control downloads, hide ads and more …

這樣的開發環境沒問題嗎?

 這樣的開發環境沒問題嗎?

如果把軟體開發比喻成音樂,開發環境就是開發者的樂器。好的開發環境會讓開發過程更順利,減少使用者需要煩惱的外務;當你專注在需要研究的課題上,便能完成更好的作品。最好的開發環境,應該讓你成為更好的開發者。

由於 Python 的根基來自 Unix 文化,它周圍的工具鏈(toolchain)也深受其「do one thing, and do it well」哲學影響,著重於創建單一功能,可與其他工具互動的元件。搭配開源社群常見的「bring your own tools」理念,Python 傳統上並沒有一個「標準」的工具搭配,而是讓大家發揮創意自由組合。這同時是優點,也是詛咒——不論你的背景為何,都可以在 Python 找到習慣的配置,但是經驗較少的人就容易犯錯,用了不適合自己,甚至根本錯誤的開發環境。

講者在這個議程將根據自己參與 Python 工具鏈專案、以及觀察、建議 Python 開發者建構環境的意見,描述常見的開發狀況、常見的組合、容易混淆的工具用法,並根據這些問題提出建議,希望讓大家能夠找到有用的資訊,建構讓自己更得心應手的開發環境。

Tzu-ping Chung

June 01, 2018
Tweet

More Decks by Tzu-ping Chung

Other Decks in Programming

Transcript

  1. cffi==1.5.2 cryptography==1.2.2 enum34==1.1.2 Flask==0.10.1 gunicorn==19.4.5 idna==2.0 ipaddress==1.0.16 itsdangerous==0.24 Jinja2==2.8 MarkupSafe==0.23

    ndg-httpsclient==0.4.0 pyasn1==0.1.9 pycparser==2.14 pyOpenSSL==0.15.1 requests==2.9.1 six==1.10.0 Werkzeug==0.11.4 requests[security] flask gunicorn==19.4.5
  2. Pipenv • No more bin/activate • Subshell • Direct binary

    call • Declared dependencies • Locking into actual requirements
  3. $ mkdir -p ~/.local/bin ~/.local/venvs $ python3 -m venv ~/.local/venvs/pipenv

    $ ~/.local/venvs/pipenv/bin/pip install pipenv $ ln -s ~/.local/venvs/pipenv/bin/pipenv ~/.local/bin $ pipenv --version pipenv, version 11.10.3
  4. Rules of Thumb • Do not use sudo. Ever. •

    Always use virtual environments • Use --user when desperate
  5. Linux • Ubuntu: use “deadsnakes” PPA • Compile your own

    otherwise • Discussed later • Be careful with the package manager
  6. macOS • Do not use System Python • Do not

    use Homebrew Python • Must compile your own
  7. Compile Your Python • Install some build dependencies • pyenv

    install <version> • You can use shims, but I hate them
  8. $ python-build 3.6.5 ~/.local/pythons/3.6 $ python-build 3.5.4 ~/.local/pythons/3.5 $ ln

    -s ~/.local/pythons/3.6/python3.6 ~/.local/bin $ ln -s ~/.local/pythons/3.5/python3.5 ~/.local/bin $ ln -s ~/.local/bin/python3.6 ~/.local/bin/python3
  9. $ pythonup install 3.6 # Build 3.6. $ pythonup upgrade

    3.6 # Re-install if newer. $ pythonup use 3.6 # Link 3.6 scripts.
  10. python() { local PYTHON="$(which python)" if [[ "$PYTHON" == /usr/*

    ]]; then echo "nope" >&2 | echo >/dev/null else "$PYTHON" "$@" fi } Hide the Default Python
  11. Windows • No global Python to worry about • No

    support from pyenv • Building is drastically more difficult
  12. $ pythonup install 3.6 # Download and install 3.6. $

    pythonup upgrade 3.6 # Re-install if newer. $ pythonup use 3.6 # Link 3.6 scripts.
  13. Summary (1/3) • Don’t use Homebrew Python • Prefer self-compiling

    if possible • Don’t add things to PATH; link* them
  14. Summary (2/3) • Always use virtual environments • You can

    call scripts in venv directly • Link* them in PATH!
  15. Summary (3/3) • Always use virtual environments (reprise) • Avoid

    activate scripts • Pipfile and Pipenv abstracts away warts
  16. Future Work • A lot of unfinished stuff already •

    Differences when developing a package • pyproject.toml and build system declaration