Poetryのインストールと初期セットアップ
概要
全てはこのツイートで語られてます。。。
昨日、書いたこの記事( https://t.co/kg1iCQqITC )まんまのプルリクを会社で出したら「pipとかrequirements.txtとかマジ古いからやめれwwww」とか言われちゃったので調べてるんだけど
— あとらす (@Lychee_jam) October 7, 2019
python周りはよくわからんな
~
くさるほど溢れてますが自身の備忘録を兼ねて。
インストールと初期セットアップのみです。入れてなにかやるとかはないです。
目次
参考サイト様
- sdispater/poetry: Python dependency management and packaging made easy.
- Poetry: Python の依存関係管理とパッケージングを支援するツール | org-技術
- Poetryを使ったPythonパッケージ開発からPyPI公開まで - PYTHONIC BOOM BOOM HEAD
前提
- MacBook Pro 2017 Mojave
$ sw_vers ProductName: Mac OS X ProductVersion: 10.14.6 BuildVersion: 18G95 $ python -V Python 3.7.4
Poetryのインストール
インストール
READMEに従ってインストールします。
$ curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python Retrieving Poetry metadata # Welcome to Poetry! This will download and install the latest version of Poetry, a dependency and package manager for Python. It will add the `poetry` command to Poetry's bin directory, located at: $HOME/.poetry/bin This path will then be added to your `PATH` environment variable by modifying the profile files located at: $HOME/.profile $HOME/.bash_profile You can uninstall at any time with `poetry self:uninstall`, or by executing this script with the --uninstall option, and these changes will be reverted. Installing version: 0.12.17 - Downloading poetry-0.12.17-darwin.tar.gz (7.38MB) Poetry (0.12.17) is installed now. Great! To get started you need Poetry's bin directory ($HOME/.poetry/bin) in your `PATH` environment variable. Next time you log in this will be done automatically. To configure your current shell run `source $HOME/.poetry/env`
このままコマンドを実行してもcommand not found
になります。
$ poetry
-bash: poetry: command not found
PATHを通す
コマンドを使えるようにするためにPATHを通します。
$ echo '$HOME/.poetry/bin:$PATH' >> ~/.bashrc $ source ~/.bashrc
これでコマンドが実行できます。
$ poetry Poetry 0.12.17 Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose[=VERBOSE] Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: about Short information about Poetry. add Add a new dependency to pyproject.toml. build Builds a package, as a tarball and a wheel by default. check Checks the validity of the pyproject.toml file. config Sets/Gets config options. develop Installs the current project in development mode. (Deprecated) help Displays help for a command init Creates a basic pyproject.toml file in the current directory. install Installs the project dependencies. list Lists commands lock Locks the project dependencies. new Creates a new Python project at <path> publish Publishes a package to a remote repository. remove Removes a package from the project dependencies. run Runs a command in the appropriate environment. script Executes a script defined in pyproject.toml. (Deprecated) search Searches for packages on remote repositories. shell Spawns a shell within the virtual environment. show Shows information about packages. update Update dependencies as according to the pyproject.toml file. version Bumps the version of the project. cache cache:clear Clears poetry's cache. debug debug:info Shows debug information. debug:resolve Debugs dependency resolution. self self:update Updates poetry to the latest version.
Poetryの初期セットアップ
virtualenvの生成パスをプロジェクトディレクトリに変更
Poetryの初期状態だと~/Library/Caches/pypoetry/virtualenvs
配下に書くプロジェクトの仮想環境が作成されるようなんですが
よくわからないところに作成されるのが気持ち悪いので、プロジェクトディレクトリに作成されるよう変更します。
$ poetry config --list settings.virtualenvs.create = true settings.virtualenvs.in-project = false settings.virtualenvs.path = "/Users/{user}/Library/Caches/pypoetry/virtualenvs" repositories = {}
設定を変更
$ poetry config settings.virtualenvs.in-project true
変更確認
$ poetry config --list settings.virtualenvs.create = true settings.virtualenvs.in-project = true settings.virtualenvs.path = "/Users/{user}/Library/Caches/pypoetry/virtualenvs" repositories = {}
以上
Poetryの入力補完設定
Poetryには入力補完機能があるようなので設定します。
READMEにも書いてあります。
が...有効化できませんでした。なんででしょうかね。
brewのシンボリックリンク周りな気がするんですけどよくわかりません。
$ poetry completions bash > $(brew --prefix)/etc/bash_completion.d/poetry.bash-completion
そのうちできたら追記します〜
雑感
まあ、pythonをまともに書いたことがないってのがでかい。
— あとらす (@Lychee_jam) October 7, 2019
python周りの技術動向が全然わからん