1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GitHubにある Poetry プロジェクトを参照するサンプル

Last updated at Posted at 2020-09-12

はじめに

PipenvとPoetryの一番の大きな違いはPipenvはライブラリプロジェクトでは使えないが、Poetryは使えるところではと思い、Poetryを勉強しました。

mainプロジェクトとlibraryプロジェクトの2つのプロジェクトをGithub経由でインストールしてlibraryプロジェクトの関数をmainプロジェクトから実行するサンプルです。

ソースは mainプロジェクトlibraryプロジェクト にあげてあります。

ディレクトリ構成

poetry-lib
├── pyproject.toml
└── poetry_lib
    └── aaa2.py
poetry-main
├── pyproject.toml
└── main.py

ファイル

poetry-lib

pyproject.toml
[tool.poetry]
name = "poetry-lib"
version = "0.1.0"
description = ""
authors = ["va034600"]
packages = [
    { include = "poetry_lib" },
]

[tool.poetry.dependencies]
python = "^3.6"
python-dateutil = "^2.8.1"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
aaa2.py
from dateutil.relativedelta import *
from datetime import *


def bbb2():
    today = datetime.now()
    return today + relativedelta(months=+6)

poetry-main

pyproject.toml
[tool.poetry]
name = "poetry-main"
version = "0.1.0"
description = ""
authors = ["va034600"]

[tool.poetry.dependencies]
python = "^3.6"
poetry-lib = { git = "ssh://git@github.com/va034600/poetry-lib.git" }

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
main.py
from poetry_lib import aaa2

print(aaa2.bbb2())

実行

setup
$ cd poetry-main
$ poetry install
$ python main.py
2021-03-13 08:00:14.266597

終わりに

Pytharmを使えば、mainプロジェクトにlibraryプロジェクトをアタッチすればデバッグもlibraryを修正した反映の確認もできます。
便利です
スクリーンショット 2020-09-13 8.09.38.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?