我是诗歌新手 - 不是借口,而是为这个问题设定框架:)
我想在
poetry run
周围有一个小包装器,它首先检查关联的虚拟环境是否是最新的 poetry.lock
,然后(有条件地)根据需要运行 poetry install
。
例如,如果
Pipfile.lock
没有改变,pipenv sync
终止得足够快,足以让它在每次调用 pipenv run
之前运行,而 poetry sync
需要超过 6 秒的时间,我才意识到不需要做任何事情完全没有。
演示我想要实现的目标的一个简单方法是编写一个
Makefile
目标,定义从 poetry.lock
到 .venv/some_random_file
和 touch
这个文件的依赖关系,并在每次该文件不满足时运行 poetry install
与 poetry.lock
约会。但我不想因为这种情况而依赖于 make
来污染我的项目。
那么有没有一种方法可以让诗歌在不需要额外工具的情况下完成这项检查呢?
我试图实现相同的目标,但创建 Makefile 是我实现此目标的唯一方法:
.PHONY: all check-install
all: check-install
@echo do something after checking poetry
check-install:
@echo "Checking if poetry is up to date..."
@poetry check || (echo "Running poetry lock..." && poetry lock)
@poetry install --sync --dry-run > poetry_output.txt
@if ! grep -q "0 installs, 0 updates, 0 removals" poetry_output.txt; then \
echo "Running poetry install: there are changes to be made"; \
poetry install; \
fi
@rm poetry_output.txt